Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

feat(editor): colour global variables (the semantic global modifier) (#1393)

l0ng-aid5c406674889
diff --git a/src/editor/lsp/features.test.ts b/src/editor/lsp/features.test.ts
index 357d35ec3..0d23cf9bc 100644
--- a/src/editor/lsp/features.test.ts
+++ b/src/editor/lsp/features.test.ts
@@ -44,6 +44,18 @@ describe("semanticRanges", () => {
expect(semanticRanges(doc, input)).toEqual([{ from: 0, to: 3, className: "cm-sem-function" }]);
});
+ it("marks globals (lua-language-server's `global` modifier)", () => {
+ const input = {
+ tokenTypes: ["variable", "function"],
+ tokenModifiers: ["global"],
+ data: [0, 0, 3, 0, 1, 0, 4, 3, 1, 1],
+ };
+ expect(semanticRanges(doc, input)).toEqual([
+ { from: 0, to: 3, className: "cm-sem-global" },
+ { from: 4, to: 7, className: "cm-sem-function cm-sem-global" },
+ ]);
+ });
+
it("colours a constructor (jdtls: class + `constructor`) as a function", () => {
const input = { tokenTypes: ["class"], tokenModifiers: ["constructor", "declaration"], data: [0, 0, 3, 0, 0b11] };
expect(semanticRanges(doc, input)[0]?.className).toBe("cm-sem-function cm-sem-declaration");
diff --git a/src/editor/lsp/semantic.ts b/src/editor/lsp/semantic.ts
index a1e497b87..9b3d3e956 100644
--- a/src/editor/lsp/semantic.ts
+++ b/src/editor/lsp/semantic.ts
@@ -56,6 +56,7 @@ const MODIFIER_CLASS: Record<string, string> = {
declaration: "declaration",
definition: "declaration",
defaultLibrary: "builtin",
+ global: "global",
};
/** Number of `--syn-rainbow-<n>` colours (IDEA's five semantic highlighting colours). */
diff --git a/src/editor/lsp/theme.ts b/src/editor/lsp/theme.ts
index 51b019d5c..aff186e7a 100644
--- a/src/editor/lsp/theme.ts
+++ b/src/editor/lsp/theme.ts
@@ -361,6 +361,8 @@ export const lspTheme = EditorView.theme({
".cm-sem-parameter": { color: "var(--syn-param, var(--syn-variable))" },
".cm-sem-self": { color: "var(--syn-self, var(--syn-keyword))" },
".cm-sem-keyword": { color: "var(--syn-keyword)", fontWeight: "var(--syn-keyword-bold, inherit)" },
+ // Before the builtin rule: library globals (`print`, `string`) keep the predefined colour.
+ ".cm-sem-global:not(.cm-sem-function)": { color: "var(--syn-global, inherit)" },
".cm-sem-builtin:not(.cm-sem-function)": { color: "var(--syn-builtin, inherit)" },
".cm-sem-static": { fontStyle: "var(--syn-static-italic, italic)" },
".cm-sem-python-static": { fontStyle: "var(--syn-python-static-italic, normal)" },
diff --git a/src/features/plugins/intellijTheme.ts b/src/features/plugins/intellijTheme.ts
index b1e81364d..0d345f3fe 100644
--- a/src/features/plugins/intellijTheme.ts
+++ b/src/features/plugins/intellijTheme.ts
@@ -130,6 +130,7 @@ export const ICLS_ATTRIBUTES: Record<string, Array<[Part, string]>> = {
DEFAULT_IDENTIFIER: [["FOREGROUND", "--syn-variable"]],
DEFAULT_LOCAL_VARIABLE: [["FOREGROUND", "--syn-variable"]],
DEFAULT_PARAMETER: [["FOREGROUND", "--syn-param"]],
+ DEFAULT_GLOBAL_VARIABLE: [["FOREGROUND", "--syn-global"]],
DEFAULT_PREDEFINED_SYMBOL: [["FOREGROUND", "--syn-builtin"]],
DEFAULT_METADATA: [
["FOREGROUND", "--syn-annotation"],
diff --git a/src/platform/colorScheme.ts b/src/platform/colorScheme.ts
index b9349d3b9..93564613b 100644
--- a/src/platform/colorScheme.ts
+++ b/src/platform/colorScheme.ts
@@ -113,6 +113,7 @@ export const ATTRIBUTES: readonly AttributeDef[] = [
syn("keyword", "Keyword", [LD], "keyword"),
syn("identifier", "Identifiers › Local variable", [LD], "variable"),
syn("parameter", "Identifiers › Parameter", [LD], "param"),
+ syn("globalVariable", "Identifiers › Global variable", [LD], "global"),
syn("constant", "Identifiers › Constant", [LD], "constant"),
syn("field", "Identifiers › Instance field", [LD], "property"),
{ id: "staticSymbol", name: "Identifiers › Static symbol", path: [LD], token: "static", italicOnly: true },
diff --git a/src/platform/icls.test.ts b/src/platform/icls.test.ts
index 675a23f24..9e914a56b 100644
--- a/src/platform/icls.test.ts
+++ b/src/platform/icls.test.ts
@@ -41,6 +41,17 @@ describe(".icls schemes", () => {
expect(customs).toEqual(before);
});
+ it("imports the global variable colour", () => {
+ const xml =
+ '<scheme name="G" parent_scheme="Darcula"><attributes><option name="DEFAULT_GLOBAL_VARIABLE"><value>' +
+ '<option name="FOREGROUND" value="9876aa"/><option name="FONT_TYPE" value="2"/></value></option></attributes></scheme>';
+ expect(parseIcls(xml).scheme.attributes.globalVariable).toEqual({
+ foreground: "#9876aa",
+ bold: false,
+ italic: true,
+ });
+ });
+
it.each([
["Darcula", "ffffff", "dark"],
["Default", "000000", "light"],
diff --git a/src/platform/icls.ts b/src/platform/icls.ts
index 3e6269f56..7062162ee 100644
--- a/src/platform/icls.ts
+++ b/src/platform/icls.ts
@@ -11,6 +11,7 @@ const ATTRIBUTE_NAMES: Record<string, string> = {
DEFAULT_IDENTIFIER: "identifier",
DEFAULT_LOCAL_VARIABLE: "identifier",
DEFAULT_PARAMETER: "parameter",
+ DEFAULT_GLOBAL_VARIABLE: "globalVariable",
DEFAULT_CONSTANT: "constant",
DEFAULT_INSTANCE_FIELD: "field",
DEFAULT_STATIC_FIELD: "constant",
diff --git a/src/styles/tokens.css b/src/styles/tokens.css
index d9eb0eb9f..251c115cc 100644
--- a/src/styles/tokens.css
+++ b/src/styles/tokens.css
@@ -116,6 +116,7 @@ html {
--syn-number: #2aacb8;
--syn-punct: #bcbec4;
--syn-variable: #bcbec4;
+ --syn-global: var(--syn-variable);
--syn-param: #bcbec4;
--syn-property: #c77dbb;
--syn-constant: #c77dbb;
@@ -494,6 +495,7 @@ html {
--syn-number: #1750eb;
--syn-punct: #080808;
--syn-variable: #080808;
+ --syn-global: var(--syn-variable);
--syn-param: #080808;
--syn-property: #871094;
--syn-constant: #871094;
@@ -748,6 +750,7 @@ html {
--syn-number: #4fd0dc;
--syn-punct: #e3e4e8;
--syn-variable: #e3e4e8;
+ --syn-global: var(--syn-variable);
--syn-param: #e3e4e8;
--syn-property: #e0a0d6;
--syn-constant: #e0a0d6;
@@ -1087,6 +1090,7 @@ html {
--syn-number: var(--palette-number);
--syn-punct: var(--palette-fg);
--syn-variable: var(--palette-variable);
+ --syn-global: var(--syn-variable);
--syn-param: var(--palette-fg);
--syn-property: var(--palette-property);
--syn-constant: var(--palette-number);