Skip to content

Commit 007921f

Browse files
committed
feat: Turns Syntax Highlighting on and off
Closes #5.
1 parent 2197f37 commit 007921f

File tree

5 files changed

+119
-10
lines changed

5 files changed

+119
-10
lines changed

CHANGELOG.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Change Log
2-
[The change log is yet to come. The below text is the standard template created by the Yeoman extension generator.]
1+
# Changelog
2+
All notable changes to the "Without Guns" extension will be documented in this file.
3+
4+
The format of the file is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
35

4-
All notable changes to the "without-guns" extension will be documented in this file.
5-
6-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
7-
86
## [Unreleased]
9-
- Initial release
7+
### Added
8+
- Turns Syntax Highlighting on and off.
9+
- Turns Code Lens on and off.
10+
11+
## [0.1.0] - 2017-09-28
12+
### Added
13+
- Turns IntelliSense on and off.

src/AllGunControllers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import GunController from "./GunController";
22
import IntelliSenseGunController from "./IntelliSenseGunController";
33
import CodeLensGunController from "./CodeLensGunController";
4+
import SyntaxHighlightingGunController from "./SyntaxHighlightingGunController";
45

56
export { GunController };
67
export { IntelliSenseGunController };
7-
export { CodeLensGunController };
8+
export { CodeLensGunController };
9+
export { SyntaxHighlightingGunController };
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import * as vscode from 'vscode';
2+
import GunController from './GunController';
3+
4+
export default class SyntaxHighlightingGunController implements GunController {
5+
private readonly configuration: vscode.WorkspaceConfiguration;
6+
private readonly tokenColorCustomizations : any;
7+
8+
isGunTaken: boolean;
9+
10+
private initialSettings = (new class {
11+
private tokenColorCustomizations : any;
12+
13+
store(configuration : vscode.WorkspaceConfiguration) {
14+
this.tokenColorCustomizations = configuration.get("editor.tokenColorCustomizations");
15+
}
16+
17+
restore(configuration : vscode.WorkspaceConfiguration) {
18+
configuration.update("editor.tokenColorCustomizations", this.tokenColorCustomizations);
19+
}
20+
})
21+
22+
constructor(configuration : vscode.WorkspaceConfiguration) {
23+
this.configuration = configuration;
24+
this.isGunTaken = false;
25+
this.tokenColorCustomizations = SyntaxHighlightingGunController.createTokenColorCustomizations();
26+
}
27+
28+
takeTheGun() {
29+
if (this.isGunTaken) return;
30+
31+
this.initialSettings.store(this.configuration);
32+
33+
this.configuration.update("editor.tokenColorCustomizations", this.tokenColorCustomizations);
34+
35+
this.isGunTaken = true;
36+
}
37+
38+
giveTheGunBack() {
39+
if (!this.isGunTaken) return;
40+
41+
this.initialSettings.restore(this.configuration);
42+
43+
this.isGunTaken = false;
44+
}
45+
46+
private static createTokenColorCustomizations() {
47+
let editorForegroundColor = this.getEditorForegroundColor();
48+
49+
let textMateRules =
50+
SyntaxHighlightingGunController.getCSharpTokenColorCustomizations()
51+
.concat(SyntaxHighlightingGunController.getTypescriptTokenColorCustomizations())
52+
.map(scopeName => ({
53+
scope: scopeName,
54+
settings: {
55+
foreground: "#FFFFFF"
56+
}
57+
}));
58+
59+
return {
60+
comments : editorForegroundColor,
61+
functions : editorForegroundColor,
62+
keywords : editorForegroundColor,
63+
numbers : editorForegroundColor,
64+
strings: editorForegroundColor,
65+
types : editorForegroundColor,
66+
variables : editorForegroundColor,
67+
textMateRules : textMateRules
68+
};
69+
}
70+
71+
// TODO-IG: Make these token customizations configurable.
72+
// Or even better, is it possible to get them dynamically in the extension itself?
73+
private static getCSharpTokenColorCustomizations() {
74+
return [
75+
"storage.modifier", // E.g. public.
76+
"constant.language" // E.g. null.
77+
]
78+
}
79+
80+
private static getTypescriptTokenColorCustomizations() {
81+
return [
82+
"keyword.control", // E.g. import.
83+
"storage.type", // E.g. class.
84+
"support.type.primitive", // E.g. boolean.
85+
"meta.object-literal.key", // E.g. { literalKey : value }.
86+
"entity.other.inherited-class" // E.g. Class implements InheritedClass.
87+
]
88+
}
89+
90+
private static getEditorForegroundColor() {
91+
return "#FFFFFF"; // TODO-IG: Find a way to get it from the current theme.
92+
}
93+
}

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export function activate(context: vscode.ExtensionContext) {
88

99
const gunControllers : gcons.GunController[] = [
1010
new gcons.IntelliSenseGunController(configuration),
11-
new gcons.CodeLensGunController(configuration)
11+
new gcons.CodeLensGunController(configuration),
12+
new gcons.SyntaxHighlightingGunController(configuration)
1213
]
1314

1415
let gunsOff = vscode.commands.registerCommand('withoutGuns.gunsOff', () => {

test/smoke/Example.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import * as vscode from "vscode";
22

3-
class ExampleClass {
3+
interface ExampleInterface {
4+
boolProperty : boolean;
5+
numberProperty : number;
6+
}
7+
8+
abstract class BaseExampleClass {
9+
10+
}
11+
12+
class ExampleClass extends BaseExampleClass implements ExampleInterface {
413
boolProperty : boolean;
514
numberProperty : number;
615

0 commit comments

Comments
 (0)