Skip to content

Commit

Permalink
optimize semantic highlighting of ts and js
Browse files Browse the repository at this point in the history
  • Loading branch information
sainnhe committed May 1, 2020
1 parent e5ac79b commit 671033f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/semantic/colorful.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Palette } from "../interface";

export function getColorfulSemantic(palette: Palette) {
return {
// JavaScript {{{
"variable.defaultLibrary:javascript": `${palette.purple}`,
"property.defaultLibrary:javascript": `${palette.purple}`,
// }}}
// JavaScript React {{{
"variable.defaultLibrary:javascriptreact": `${palette.purple}`,
"property.defaultLibrary:javascriptreact": `${palette.purple}`,
// }}}
// TypeScript {{{
"namespace:typescript": `${palette.purple}`,
"enumMember:typescript": `${palette.yellow}`,
"variable.defaultLibrary:typescript": `${palette.purple}`,
"property.defaultLibrary:typescript": `${palette.purple}`,
// }}}
// TypeScript React {{{
"namespace:typescriptreact": `${palette.purple}`,
"enumMember:typescriptreact": `${palette.yellow}`,
"variable.defaultLibrary:typescriptreact": `${palette.purple}`,
"property.defaultLibrary:typescriptreact": `${palette.purple}`,
// }}}
};
}
32 changes: 32 additions & 0 deletions src/semantic/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Palette } from "../interface";

export function getDefaultSemantic(palette: Palette) {
return {
// JavaScript {{{
"variable.defaultLibrary:javascript": `${palette.purple}`,
"property.defaultLibrary:javascript": `${palette.purple}`,
// }}}
// JavaScript React {{{
"variable.defaultLibrary:javascriptreact": `${palette.purple}`,
"property.defaultLibrary:javascriptreact": `${palette.purple}`,
// }}}
// TypeScript {{{
"class:typescript": `${palette.aqua}`,
"interface:typescript": `${palette.aqua}`,
"enum:typescript": `${palette.purple}`,
"enumMember:typescript": `${palette.blue}`,
"namespace:typescript": `${palette.purple}`,
"variable.defaultLibrary:typescript": `${palette.purple}`,
"property.defaultLibrary:typescript": `${palette.purple}`,
// }}}
// TypeScript React {{{
"class:typescriptreact": `${palette.aqua}`,
"interface:typescriptreact": `${palette.aqua}`,
"enum:typescriptreact": `${palette.purple}`,
"enumMember:typescriptreact": `${palette.blue}`,
"namespace:typescriptreact": `${palette.purple}`,
"variable.defaultLibrary:typescriptreact": `${palette.purple}`,
"property.defaultLibrary:typescriptreact": `${palette.purple}`,
// }}}
};
}
15 changes: 15 additions & 0 deletions src/semantic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Configuration } from "../interface";
import { getPalette } from "../palette";
import { getDefaultSemantic } from "./default";
import { getColorfulSemantic } from "./colorful";

export function getSemantic(configuration: Configuration, variant: string) {
let palette = getPalette(configuration, variant);
let semantic: any;
if (configuration.colorfulSyntax === false) {
semantic = getDefaultSemantic(palette);
} else {
semantic = getColorfulSemantic(palette);
}
return semantic;
}
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ConfigurationChangeEvent, workspace, window, commands } from "vscode";
import { Configuration } from "./interface";
import { getWorkbench } from "./workbench";
import { getSyntax } from "./syntax";
import { getSemantic } from "./semantic";

export default class Utils {
detectConfigChanges(
Expand Down Expand Up @@ -44,13 +45,15 @@ export default class Utils {
name: "Gruvbox Material Dark",
type: "dark",
semanticHighlighting: configuration.semanticHighlighting,
semanticTokenColors: getSemantic(configuration, "dark"),
colors: getWorkbench(configuration, "dark"),
tokenColors: getSyntax(configuration, "dark"),
},
light: {
name: "Gruvbox Material Light",
type: "light",
semanticHighlighting: configuration.semanticHighlighting,
semanticTokenColors: getSemantic(configuration, "dark"),
colors: getWorkbench(configuration, "light"),
tokenColors: getSyntax(configuration, "light"),
},
Expand Down
20 changes: 20 additions & 0 deletions themes/gruvbox-material-dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
"name": "Gruvbox Material Dark",
"type": "dark",
"semanticHighlighting": true,
"semanticTokenColors": {
"variable.defaultLibrary:javascript": "#d3869b",
"property.defaultLibrary:javascript": "#d3869b",
"variable.defaultLibrary:javascriptreact": "#d3869b",
"property.defaultLibrary:javascriptreact": "#d3869b",
"class:typescript": "#89b482",
"interface:typescript": "#89b482",
"enum:typescript": "#d3869b",
"enumMember:typescript": "#7daea3",
"namespace:typescript": "#d3869b",
"variable.defaultLibrary:typescript": "#d3869b",
"property.defaultLibrary:typescript": "#d3869b",
"class:typescriptreact": "#89b482",
"interface:typescriptreact": "#89b482",
"enum:typescriptreact": "#d3869b",
"enumMember:typescriptreact": "#7daea3",
"namespace:typescriptreact": "#d3869b",
"variable.defaultLibrary:typescriptreact": "#d3869b",
"property.defaultLibrary:typescriptreact": "#d3869b"
},
"colors": {
"foreground": "#d4be98",
"focusBorder": "#45403d00",
Expand Down
20 changes: 20 additions & 0 deletions themes/gruvbox-material-light.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
"name": "Gruvbox Material Light",
"type": "light",
"semanticHighlighting": true,
"semanticTokenColors": {
"variable.defaultLibrary:javascript": "#d3869b",
"property.defaultLibrary:javascript": "#d3869b",
"variable.defaultLibrary:javascriptreact": "#d3869b",
"property.defaultLibrary:javascriptreact": "#d3869b",
"class:typescript": "#89b482",
"interface:typescript": "#89b482",
"enum:typescript": "#d3869b",
"enumMember:typescript": "#7daea3",
"namespace:typescript": "#d3869b",
"variable.defaultLibrary:typescript": "#d3869b",
"property.defaultLibrary:typescript": "#d3869b",
"class:typescriptreact": "#89b482",
"interface:typescriptreact": "#89b482",
"enum:typescriptreact": "#d3869b",
"enumMember:typescriptreact": "#7daea3",
"namespace:typescriptreact": "#d3869b",
"variable.defaultLibrary:typescriptreact": "#d3869b",
"property.defaultLibrary:typescriptreact": "#d3869b"
},
"colors": {
"foreground": "#654735",
"focusBorder": "#e0cfa900",
Expand Down

0 comments on commit 671033f

Please sign in to comment.