From 3b4e91839da8820e9d17dad15e6416295330d7fb Mon Sep 17 00:00:00 2001 From: Karl Goffin Date: Mon, 22 Jan 2018 21:42:10 -0500 Subject: [PATCH] 1.2.0 - default editor config for befunge files, guides now default to on, bugfixes --- CHANGELOG.md | 14 +++++++++++++ README.md | 22 +++++++++++++------- package.json | 52 +++++++++++++++++++++++++++++++++++++++--------- src/extension.ts | 48 ++++++++++++++++++++++++++++++-------------- 4 files changed, 105 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9643b18..6744491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to the Befunge VS Code extension will be documented in this The format of this changelog is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 1.2.0 - 2018-01-22 + +### Added + +* default editor configurations for Befunge-93 and 98 files, including turning off indent guides, line highlight, trailing whitespace trimming, autoindent, and quick suggestions. See the "Contributions" tab in VS Code for details +* restriction on colors: previously accepted any string, now only accepts 6 digit hex colors. This prevents some bugs in rendering, especially in rendering horizontal guides +* extension now renders guides on a change in configuration + +### Changed + +* fixed bug where guide lines in the old color could still persist after a color change +* `"befunge.guides.enable"` renamed to `"befunge.guides.enabled"` +* `"befunge.guides.enabled"` now defaults to `true` + ## 1.1.0 - 2018-01-21 ### Added diff --git a/README.md b/README.md index 1e2c07b..274f601 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Version](https://vsmarketplacebadge.apphb.com/version/kagof.befunge.svg)](https://marketplace.visualstudio.com/items?itemName=kagof.befunge) [![Installs](https://vsmarketplacebadge.apphb.com/installs/kagof.befunge.svg)](https://marketplace.visualstudio.com/items?itemName=kagof.befunge) -[![Ratings](https://vsmarketplacebadge.apphb.com/rating/kagof.befunge.svg)](https://marketplace.visualstudio.com/items?itemName=kagof.befunge) [![Build Status](https://img.shields.io/travis/kagof/VSCode-Befunge.svg)](https://travis-ci.org/kagof/VSCode-Befunge) +[![Known Vulnerabilities](https://snyk.io/test/github/kagof/vscode-befunge/badge.svg?targetFile=package.json)](https://snyk.io/test/github/kagof/vscode-befunge?targetFile=package.json) ## Features @@ -34,9 +34,9 @@ Adds the following new configuration settings: | Name | Default (Type) | Description | |------|----------------|-------------| -|`"befunge.guides.enabled"`|`false` (boolean)|Enable the Befunge guides coming from arrow characters.| -|`"befunge.guides.color.dark"`|`"rgba(60, 60, 60, 0.75)"` (string)|The Befunge guide line color to use for a dark theme.| -|`"befunge.guides.color.light"`|`"rgba(220, 220, 220, 0.75)"` (string)|The Befunge guide line color to use for a light theme.| +|`"befunge.guides.enabled"`|`true` (boolean)|Enable the Befunge guides coming from arrow characters.| +|`"befunge.guides.color.dark"`|`"#3c3c3c"` (*#rrggbb* hex string)|The Befunge guide line color to use for a dark theme.| +|`"befunge.guides.color.light"`|`"#dcdcdc"` (*#rrggbb* hex string)|The Befunge guide line color to use for a light theme.| To get the colors shown in the [screenshots](#screenshots), some changes to your User Settings are necessary: @@ -170,10 +170,18 @@ Find an issue/bug? [Report it](https://github.com/kagof/VSCode-Befunge-syntax-hi See also the [changelog](CHANGELOG.md). -### 1.0.0 +### 1.2.0 -* Initial release with support for Befunge-93 and Befunge-98 +* Restrict colors to 6 digit hex colors as other formats can cause problems, especially with the horizontal lines +* Purge decorations of the old style when color configuration changes, as otherwise it would persist until editor is closed +* Renamed `"befunge.guides.enable"` configuration property to `"befunge.guides.enabled"` to match README and code +* Set some default editor configurations for Befunge-93 and 98 files, including turning off indent guides, line highlight, trailing whitespace trimming, autoindent, and quick suggestions +* Because indent guides are now disabled by default, `"befunge.guides.enabled"` now defaults to `true` ### 1.1.0 -* Support for alignment guides for the directional characters \ No newline at end of file +* Support for alignment guides for the directional characters + +### 1.0.0 + +* Initial release with support for Befunge-93 and Befunge-98 diff --git a/package.json b/package.json index ce01a94..ec760a6 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,13 @@ "author": { "name": "Karl Goffin" }, - "version": "1.1.0", + "version": "1.2.0", "publisher": "kagof", "icon": "assets/icon.png", + "galleryBanner": { + "color": "#1c232d", + "theme": "dark" + }, "license": "SEE LICENSE IN LICENSE.md", "repository": { "type": "git", @@ -78,22 +82,52 @@ ], "configuration": { "type": "object", - "title": "Befunge configuration", + "title": "Befunge Configuration", "properties": { - "befunge.guides.enable": { + "befunge.guides.enabled": { "type": "boolean", - "default": false, - "description": "Enable the Befunge guides coming from arrow characters. It is highly recommended that you set \"editor.renderIndentGuides\" to false if you enable this." + "default": true, + "description": "Enable the Befunge guides coming from arrow characters." }, "befunge.guides.color.dark": { "type": "string", - "default": "rgba(60, 60, 60, 0.75)", - "description": "The Befunge guide line color to use for a dark theme." + "format": "color-hex", + "pattern": "^#[0-9a-f]{6}$", + "default": "#3c3c3c", + "description": "The Befunge guide line color to use for a dark theme. Currently restricted to 6 digit hex as other values may cause issues." }, "befunge.guides.color.light": { "type": "string", - "default": "rgba(220, 220, 220, 0.75)", - "description": "The Befunge guide line color to use for a light theme." + "format": "color-hex", + "pattern": "^#[0-9a-f]{6}$", + "default": "#dcdcdc", + "description": "The Befunge guide line color to use for a light theme. Currently restricted to 6 digit hex as other values may cause issues." + } + } + }, + "configurationDefaults": { + "[befunge]": { + "editor.renderIndentGuides": false, + "editor.renderLineHighlight": "none", + "files.trimTrailingWhitespace": false, + "editor.autoIndent": false, + "editor.acceptSuggestionOnEnter": "off", + "editor.quickSuggestions": { + "other": false, + "comments": false, + "strings": false + } + }, + "[befunge98]": { + "editor.renderIndentGuides": false, + "editor.renderLineHighlight": "none", + "files.trimTrailingWhitespace": false, + "editor.autoIndent": false, + "editor.acceptSuggestionOnEnter": "off", + "editor.quickSuggestions": { + "other": false, + "comments": false, + "strings": false } } } diff --git a/src/extension.ts b/src/extension.ts index e690ea3..08f69db 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -25,6 +25,13 @@ export function activate(context: vscode.ExtensionContext) { } }, null, context.subscriptions); + vscode.workspace.onDidChangeConfiguration( + (event) => { + if (editor && isBefungeDoc(editor)) { + renderer.render(editor); + } + }, + null, context.subscriptions); } /** @@ -40,8 +47,6 @@ function isBefungeDoc(editor: vscode.TextEditor): boolean { */ export class Renderer { - private enabled: boolean; - private verticalConfig: vscode.DecorationRenderOptions; private horizontalConfig: vscode.DecorationRenderOptions; @@ -50,12 +55,11 @@ export class Renderer { private colorDark: string; private colorLight: string; - // regex to find arrows private regex = /[v<>^?]/g; constructor() { - this.refresh(); + this.loadDecorations(this.getConfig()); } /** @@ -63,8 +67,7 @@ export class Renderer { * @param editor the current text editor */ render(editor: vscode.TextEditor): void { - this.refresh(); - if (!this.enabled) { + if (!this.isEnabled()) { return; } let vRanges: vscode.Range[] = []; @@ -90,7 +93,7 @@ export class Renderer { hRanges = hRanges.concat(this.execLeft(startPos, editor)); } } - + this.refresh(); // refreshes the color configuration editor.setDecorations(this.verticalDecoration, vRanges); editor.setDecorations(this.horizontalDecoration, hRanges); } @@ -198,23 +201,38 @@ export class Renderer { } /** - * Rereads the configuration. - * This allows the colors to stay updated, as well as whether to enable/disable guides. + * retrieves the current workspace configuration + */ + getConfig(): vscode.WorkspaceConfiguration { + return vscode.workspace.getConfiguration('befunge.guides'); + } + + /** + * Returns whether or not alignment guides are enabled in the workspace configuration. + */ + isEnabled(): boolean { + return this.getConfig().enabled; + } + + /** + * Rereads the configuration, purging old decorations and reloading styles as needed. */ refresh(): void { - const cfg: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('befunge.guides'); - this.enabled = cfg.enable; + const cfg: vscode.WorkspaceConfiguration = this.getConfig(); if (this.colorDark !== cfg.color.dark || this.colorLight !== cfg.color.light) { - this.colorDark = cfg.color.dark; - this.colorLight = cfg.color.light; - this.refreshDecorations(); + this.verticalDecoration.dispose(); // erase all vertical decorations in old style + this.horizontalDecoration.dispose(); // erase all horizontal decorations in old style + this.loadDecorations(cfg); } } /** * Refreshes the decorations. To be called when a color configuration has been changed. + * @param config the configuration to load the decorations from */ - refreshDecorations() { + loadDecorations(config: vscode.WorkspaceConfiguration): void { + this.colorDark = config.color.dark; + this.colorLight = config.color.light; this.verticalConfig = { dark: { outlineWidth: '1px',