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

lua-language-server marks globals with the `global` token modifier, but
the editor dropped it, so a global variable looked like a local unless
rainbow highlighting was on. The modifier now sets `cm-sem-global`, drawn
in a new Language Defaults › Identifiers › Global variable colour
(`--syn-global`): library globals keep the predefined colour and calls the
function-call colour. Imported IntelliJ themes and .icls schemes take it
from DEFAULT_GLOBAL_VARIABLE. Built-in schemes default it to the local
variable colour (IntelliJ's fallback for the key), so they look as before
until a scheme sets it.

Fixes #1370
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-05 07:59:45 +08:00
1 джерело 8d784ac164
коміт d5c4066748
8 files changed
+33

No files matched your search

+12
Переглянути файл
@@ -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");
+1
Переглянути файл
@@ -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). */
+2
Переглянути файл
@@ -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)" },