From 007921ff7bf73325726d693b71ac9d7e5b41350e Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 29 Sep 2017 16:50:20 +0200 Subject: [PATCH] feat: Turns Syntax Highlighting on and off Closes #5. --- CHANGELOG.md | 18 +++-- src/AllGunControllers.ts | 4 +- src/SyntaxHighlightingGunController.ts | 93 ++++++++++++++++++++++++++ src/extension.ts | 3 +- test/smoke/Example.ts | 11 ++- 5 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 src/SyntaxHighlightingGunController.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ade82b4..09c23e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ -# Change Log -[The change log is yet to come. The below text is the standard template created by the Yeoman extension generator.] +# Changelog +All notable changes to the "Without Guns" extension will be documented in this file. + +The format of the file is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). -All notable changes to the "without-guns" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - ## [Unreleased] -- Initial release \ No newline at end of file +### Added +- Turns Syntax Highlighting on and off. +- Turns Code Lens on and off. + +## [0.1.0] - 2017-09-28 +### Added +- Turns IntelliSense on and off. \ No newline at end of file diff --git a/src/AllGunControllers.ts b/src/AllGunControllers.ts index d042863..fac3575 100644 --- a/src/AllGunControllers.ts +++ b/src/AllGunControllers.ts @@ -1,7 +1,9 @@ import GunController from "./GunController"; import IntelliSenseGunController from "./IntelliSenseGunController"; import CodeLensGunController from "./CodeLensGunController"; +import SyntaxHighlightingGunController from "./SyntaxHighlightingGunController"; export { GunController }; export { IntelliSenseGunController }; -export { CodeLensGunController }; \ No newline at end of file +export { CodeLensGunController }; +export { SyntaxHighlightingGunController }; \ No newline at end of file diff --git a/src/SyntaxHighlightingGunController.ts b/src/SyntaxHighlightingGunController.ts new file mode 100644 index 0000000..bd5d5fb --- /dev/null +++ b/src/SyntaxHighlightingGunController.ts @@ -0,0 +1,93 @@ +import * as vscode from 'vscode'; +import GunController from './GunController'; + +export default class SyntaxHighlightingGunController implements GunController { + private readonly configuration: vscode.WorkspaceConfiguration; + private readonly tokenColorCustomizations : any; + + isGunTaken: boolean; + + private initialSettings = (new class { + private tokenColorCustomizations : any; + + store(configuration : vscode.WorkspaceConfiguration) { + this.tokenColorCustomizations = configuration.get("editor.tokenColorCustomizations"); + } + + restore(configuration : vscode.WorkspaceConfiguration) { + configuration.update("editor.tokenColorCustomizations", this.tokenColorCustomizations); + } + }) + + constructor(configuration : vscode.WorkspaceConfiguration) { + this.configuration = configuration; + this.isGunTaken = false; + this.tokenColorCustomizations = SyntaxHighlightingGunController.createTokenColorCustomizations(); + } + + takeTheGun() { + if (this.isGunTaken) return; + + this.initialSettings.store(this.configuration); + + this.configuration.update("editor.tokenColorCustomizations", this.tokenColorCustomizations); + + this.isGunTaken = true; + } + + giveTheGunBack() { + if (!this.isGunTaken) return; + + this.initialSettings.restore(this.configuration); + + this.isGunTaken = false; + } + + private static createTokenColorCustomizations() { + let editorForegroundColor = this.getEditorForegroundColor(); + + let textMateRules = + SyntaxHighlightingGunController.getCSharpTokenColorCustomizations() + .concat(SyntaxHighlightingGunController.getTypescriptTokenColorCustomizations()) + .map(scopeName => ({ + scope: scopeName, + settings: { + foreground: "#FFFFFF" + } + })); + + return { + comments : editorForegroundColor, + functions : editorForegroundColor, + keywords : editorForegroundColor, + numbers : editorForegroundColor, + strings: editorForegroundColor, + types : editorForegroundColor, + variables : editorForegroundColor, + textMateRules : textMateRules + }; + } + + // TODO-IG: Make these token customizations configurable. + // Or even better, is it possible to get them dynamically in the extension itself? + private static getCSharpTokenColorCustomizations() { + return [ + "storage.modifier", // E.g. public. + "constant.language" // E.g. null. + ] + } + + private static getTypescriptTokenColorCustomizations() { + return [ + "keyword.control", // E.g. import. + "storage.type", // E.g. class. + "support.type.primitive", // E.g. boolean. + "meta.object-literal.key", // E.g. { literalKey : value }. + "entity.other.inherited-class" // E.g. Class implements InheritedClass. + ] + } + + private static getEditorForegroundColor() { + return "#FFFFFF"; // TODO-IG: Find a way to get it from the current theme. + } +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 96a2986..40e95e0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,7 +8,8 @@ export function activate(context: vscode.ExtensionContext) { const gunControllers : gcons.GunController[] = [ new gcons.IntelliSenseGunController(configuration), - new gcons.CodeLensGunController(configuration) + new gcons.CodeLensGunController(configuration), + new gcons.SyntaxHighlightingGunController(configuration) ] let gunsOff = vscode.commands.registerCommand('withoutGuns.gunsOff', () => { diff --git a/test/smoke/Example.ts b/test/smoke/Example.ts index 597a3b4..4b4455a 100644 --- a/test/smoke/Example.ts +++ b/test/smoke/Example.ts @@ -1,6 +1,15 @@ import * as vscode from "vscode"; -class ExampleClass { +interface ExampleInterface { + boolProperty : boolean; + numberProperty : number; +} + +abstract class BaseExampleClass { + +} + +class ExampleClass extends BaseExampleClass implements ExampleInterface { boolProperty : boolean; numberProperty : number;