-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Turns Syntax Highlighting on and off
Closes #5.
- Loading branch information
Showing
5 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters