Skip to content

Commit

Permalink
feat: Turns Syntax Highlighting on and off
Browse files Browse the repository at this point in the history
Closes #5.
  • Loading branch information
ironcev committed Sep 29, 2017
1 parent 2197f37 commit 007921f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 10 deletions.
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
### 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.
4 changes: 3 additions & 1 deletion src/AllGunControllers.ts
Original file line number Diff line number Diff line change
@@ -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 };
export { CodeLensGunController };
export { SyntaxHighlightingGunController };
93 changes: 93 additions & 0 deletions src/SyntaxHighlightingGunController.ts
Original file line number Diff line number Diff line change
@@ -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.
}
}
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 10 additions & 1 deletion test/smoke/Example.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit 007921f

Please sign in to comment.