diff --git a/plugins/official/harbor-night/themes/harbor-night.scheme.json b/plugins/official/harbor-night/themes/harbor-night.scheme.json index 789115cce..3de347810 100644 --- a/plugins/official/harbor-night/themes/harbor-night.scheme.json +++ b/plugins/official/harbor-night/themes/harbor-night.scheme.json @@ -26,6 +26,9 @@ "--syn-variable": "#d9dfe8", "--syn-global": "#d9dfe8", "--syn-namespace": "var(--fg-editor)", + "--syn-go-package": "#9ccc7a", + "--syn-go-type": "#8fd4c9", + "--syn-go-call": "#e5be91", "--syn-param": "#d9dfe8", "--syn-property": "#b9a3f0", "--syn-constant": "#e58fa3", diff --git a/plugins/themes.md b/plugins/themes.md index 746d656fc..b93bac0fa 100644 --- a/plugins/themes.md +++ b/plugins/themes.md @@ -333,7 +333,7 @@ a token. -275 themeable tokens: 128 in the UI theme file, 147 in the editor colour scheme file. +278 themeable tokens: 128 in the UI theme file, 150 in the editor colour scheme file. ### Surfaces (UI theme) @@ -448,6 +448,9 @@ a token. | `--syn-variable` | `#bcbec4` | `#080808` | | `--syn-global` | `var(--syn-variable)` | `var(--syn-variable)` | | `--syn-namespace` | `var(--fg-editor)` | `var(--fg-editor)` | +| `--syn-go-package` | `#a9bb75` | `#526a25` | +| `--syn-go-type` | `#6bb7c8` | `#007083` | +| `--syn-go-call` | `#bda77a` | `#7d5d26` | | `--syn-param` | `#bcbec4` | `#080808` | | `--syn-property` | `#c77dbb` | `#871094` | | `--syn-constant` | `#c77dbb` | `#871094` | diff --git a/src/editor/lsp/semantic/go/index.test.ts b/src/editor/lsp/semantic/go/index.test.ts index eec56a47a..79a22f878 100644 --- a/src/editor/lsp/semantic/go/index.test.ts +++ b/src/editor/lsp/semantic/go/index.test.ts @@ -41,19 +41,20 @@ describe("Go semantic tokens", () => { ); }); - it("retains package, field and function roles from the common decoder", () => { - for (const [type, expected] of [ - ["namespace", "cm-sem-namespace"], - ["property", "cm-sem-property"], - ["function", "cm-sem-function"], - ["type", "cm-sem-type"], - ["typeParameter", "cm-sem-typeParameter"], - ]) { - expect( - semanticRanges(doc, { tokenTypes: [type!], tokenModifiers: [], data: [0, 0, 4, 0, 0] }, false, "go")[0] - ?.className, - ).toBe(expected); - } + it.each([ + ["namespace", ["defaultLibrary"], "cm-sem-namespace cm-sem-builtin cm-sem-go-package"], + ["property", [], "cm-sem-property"], + ["function", [], "cm-sem-function cm-sem-go-call"], + ["method", [], "cm-sem-function cm-sem-go-call"], + ["function", ["definition"], "cm-sem-function cm-sem-declaration"], + ["type", [], "cm-sem-type cm-sem-go-type"], + ["struct", [], "cm-sem-type cm-sem-go-type"], + ["typeParameter", [], "cm-sem-typeParameter cm-sem-go-type"], + ["type", ["defaultLibrary"], "cm-sem-type cm-sem-builtin"], + ["variable", [], "cm-sem-variable"], + ])("colors %s with modifiers %j", (type, modifiers, expected) => { + const tokens = { tokenTypes: [type], tokenModifiers: modifiers, data: [0, 0, 4, 0, modifiers.length ? 1 : 0] }; + expect(semanticRanges(doc, tokens, false, "go")[0]?.className).toBe(expected); }); it("leaves branch labels and missing server tokens to syntax highlighting", () => { diff --git a/src/editor/lsp/semantic/go/index.ts b/src/editor/lsp/semantic/go/index.ts index 39a8d05c9..f3e5df1e0 100644 --- a/src/editor/lsp/semantic/go/index.ts +++ b/src/editor/lsp/semantic/go/index.ts @@ -2,9 +2,16 @@ import { registerLanguageSemantics, type LanguageSemantics } from "../languages" const goSemantics: LanguageSemantics = { tokenClasses({ type, modifiers, classes }) { + const builtin = modifiers.includes("defaultLibrary"); + if (type === "namespace") classes.push("cm-sem-go-package"); + if (!builtin && (classes.includes("cm-sem-type") || type === "typeParameter")) classes.push("cm-sem-go-type"); + if (!builtin && classes.includes("cm-sem-function") && !classes.includes("cm-sem-declaration")) + classes.push("cm-sem-go-call"); if (type === "variable") { if (modifiers.includes("readonly") && !classes.includes("cm-sem-constant")) classes.push("cm-sem-constant"); else if (modifiers.includes("static") && !classes.includes("cm-sem-constant")) classes.push("cm-sem-global"); + else if (!builtin && !classes.includes("cm-sem-constant") && !classes.includes("cm-sem-global")) + classes.push("cm-sem-variable"); } }, isLocal: ({ type, modifiers }) => type === "parameter" || (type === "variable" && !modifiers.includes("readonly")), diff --git a/src/editor/lsp/theme.ts b/src/editor/lsp/theme.ts index 8a6cd2fad..ca2d7b83f 100644 --- a/src/editor/lsp/theme.ts +++ b/src/editor/lsp/theme.ts @@ -669,6 +669,9 @@ export const lspTheme = EditorView.theme({ ".cm-sem-builtin:where(:not(.cm-sem-function))": semanticStyle("builtin", "variable"), ".cm-sem-builtin:where(.cm-sem-type)": inheritedStyle("builtin-type", "builtin"), ".cm-sem-builtin.cm-sem-python-builtin": semanticStyle("python-builtin", "builtin"), + ".cm-sem-go-package": semanticStyle("go-package", "namespace"), + ".cm-sem-go-type": semanticStyle("go-type", "type"), + ".cm-sem-go-call": semanticStyle("go-call", "function-call"), ".cm-sem-static": { fontStyle: "var(--syn-static-italic, italic)" }, ".cm-sem-property.cm-sem-static, .cm-sem-property.cm-sem-static *": { color: "var(--syn-static-property, var(--syn-property))", diff --git a/src/platform/colorScheme.ts b/src/platform/colorScheme.ts index 24ea4100d..76961aba2 100644 --- a/src/platform/colorScheme.ts +++ b/src/platform/colorScheme.ts @@ -460,18 +460,28 @@ const SCHEME_EDITORS: Record = { "C/C++": ["C", "C++"], }; +const GO_SCHEME_TOKENS = new Map([ + ["packageReference", "go-package"], + ["className", "go-type"], + ["functionCall", "go-call"], +]); + export const ATTRIBUTES: readonly AttributeDef[] = [ ...BASE_ATTRIBUTES, ...Object.entries(SCHEME_LANGUAGES).flatMap(([id, language]) => BASE_ATTRIBUTES.filter( // WebStorm's page has a Decorator instead of Metadata. (a) => a.path[0] === LD && !/^(semantic|bracket)\d$/.test(a.id) && !(language === JS && a.id === "metadata"), - ).map((a) => ({ - ...a, - id: `${id}.${a.id}`, - path: [language, ...a.path.slice(1)], - language, - })), + ).map((a) => { + const token = id === "go" ? GO_SCHEME_TOKENS.get(a.id) : undefined; + return { + ...a, + ...(token && { token, fg: `--syn-${token}` }), + id: `${id}.${a.id}`, + path: [language, ...a.path.slice(1)], + language, + }; + }), ), // WebStorm's JavaScript / TypeScript page: the whole `@Name` of a decorator, and module-level functions. { ...syn("javascript.decorator", "Decorator", [JS], "decorator"), language: JS }, diff --git a/src/styles/tokens.css b/src/styles/tokens.css index 6241f4b7c..604f8a2d1 100644 --- a/src/styles/tokens.css +++ b/src/styles/tokens.css @@ -167,6 +167,9 @@ html[data-os="windows"] { --syn-variable: #bcbec4; --syn-global: var(--syn-variable); --syn-namespace: var(--fg-editor); + --syn-go-package: #a9bb75; + --syn-go-type: #6bb7c8; + --syn-go-call: #bda77a; --syn-param: #bcbec4; --syn-property: #c77dbb; --syn-constant: #c77dbb; @@ -659,6 +662,9 @@ html[data-os="windows"] { --syn-variable: #080808; --syn-global: var(--syn-variable); --syn-namespace: var(--fg-editor); + --syn-go-package: #526a25; + --syn-go-type: #007083; + --syn-go-call: #7d5d26; --syn-param: #080808; --syn-property: #871094; --syn-constant: #871094; @@ -965,6 +971,9 @@ html[data-os="windows"] { --syn-variable: #e3e4e8; --syn-global: var(--syn-variable); --syn-namespace: var(--fg-editor); + --syn-go-package: #c7db96; + --syn-go-type: #6ddef3; + --syn-go-call: #ebbe83; --syn-param: #e3e4e8; --syn-property: #e0a0d6; --syn-constant: #e0a0d6; @@ -1362,6 +1371,9 @@ html[data-os="windows"] { --syn-variable: var(--palette-variable); --syn-global: var(--syn-variable); --syn-namespace: var(--fg-editor); + --syn-go-package: #859900; + --syn-go-type: #2aa198; + --syn-go-call: #b58900; --syn-param: var(--palette-fg); --syn-property: var(--palette-property); --syn-constant: var(--palette-number); @@ -1455,6 +1467,9 @@ html[data-os="windows"] { } :root[data-color-theme="solarized-light"] { + --syn-go-package: #586600; + --syn-go-type: #006d66; + --syn-go-call: #805f00; --palette-yellow: #b58900; --palette-orange: #cb4b16; --palette-red: #dc322f;