mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
feat(color-scheme): split predefined types and functions and separate literal keywords (#4978)
Language Defaults and each language page get Identifiers › Predefined type and Predefined function next to Predefined symbol, and Literal keyword next to Keyword. The new entries show their parent until set, so existing overrides keep applying. true / false / null in the clike modes (Kotlin, Scala, Dart, Groovy, C#) are bool / null tokens taking Literal keyword instead of Constant. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
co-authored by
wildcatDownstairs
parent
a3dc3c99a6
commit
9eaa44e004
@@ -40,19 +40,11 @@ export const openideaHighlightStyle = HighlightStyle.define([
|
||||
token(t.link, "link", { effect: "underline" }),
|
||||
token(t.quote, "string"),
|
||||
token(
|
||||
[
|
||||
t.keyword,
|
||||
t.controlKeyword,
|
||||
t.moduleKeyword,
|
||||
t.operatorKeyword,
|
||||
t.definitionKeyword,
|
||||
t.modifier,
|
||||
t.null,
|
||||
t.bool,
|
||||
t.unit,
|
||||
],
|
||||
[t.keyword, t.controlKeyword, t.moduleKeyword, t.operatorKeyword, t.definitionKeyword, t.modifier, t.unit],
|
||||
"keyword",
|
||||
),
|
||||
// JetBrains colours them as keywords; Literal keyword sets them apart.
|
||||
token([t.null, t.bool], "literal", { color: "keyword" }),
|
||||
token(t.self, "self"),
|
||||
token([t.string, t.special(t.string), t.character, t.attributeValue], "string"),
|
||||
token(t.docString, "docstring", { italic: "italic" }),
|
||||
@@ -60,7 +52,9 @@ export const openideaHighlightStyle = HighlightStyle.define([
|
||||
token(t.regexp, "regexp"),
|
||||
token([t.number, t.integer, t.float], "number"),
|
||||
token([t.typeName, t.className, t.namespace, t.definition(t.typeName)], "type"),
|
||||
token([t.standard(t.typeName), t.standard(t.variableName), t.standard(t.function(t.variableName))], "builtin"),
|
||||
token(t.standard(t.variableName), "builtin"),
|
||||
token(t.standard(t.typeName), "builtin-type", { color: "builtin" }),
|
||||
token(t.standard(t.function(t.variableName)), "builtin-function", { color: "builtin" }),
|
||||
token([t.function(t.variableName), t.function(t.propertyName)], "function-call"),
|
||||
token(shellCommand, "shell-command", { color: "function-call" }),
|
||||
token(
|
||||
|
||||
@@ -51,6 +51,20 @@ describe("Kotlin soft keywords", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("literal keywords (#4059)", () => {
|
||||
it.each(["Kotlin", "Scala", "Dart", "Groovy", "C#"])(
|
||||
"tags true, false and null in %s as literals, not as constants",
|
||||
async (mode) => {
|
||||
const out = await tokens(mode, "x = f(true, false, null)");
|
||||
const styleOf = (text: string) => out.find((t) => t.text === text)?.style ?? "";
|
||||
expect(styleOf("true")).toBe("tok-bool");
|
||||
expect(styleOf("false")).toBe("tok-bool");
|
||||
// `tags.null` derives from keyword, which classHighlighter prints; an atom prints tok-atom.
|
||||
expect(styleOf("null")).toBe("tok-keyword");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("frontend string interpolation", () => {
|
||||
it.each([
|
||||
["Kotlin", 'println("$i + 1 = ${i + 1}")'],
|
||||
|
||||
@@ -154,6 +154,12 @@ export function interpolationParser<S>(base: StreamParser<S>, dialect: Interpola
|
||||
}
|
||||
if (dialect === "Kotlin" && result === "keyword" && !kotlinKeywordAt(stream.string, from, stream.pos))
|
||||
return "variable";
|
||||
// The clike modes call these atoms, like enum-ish constants; JetBrains colours them as keywords.
|
||||
if (result === "atom") {
|
||||
const word = stream.string.slice(from, stream.pos);
|
||||
if (word === "true" || word === "false") return "bool";
|
||||
if (word === "null") return "null";
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -518,7 +518,8 @@ export const lspTheme = EditorView.theme({
|
||||
".cm-sem-function": semanticStyle("function-call", "function"),
|
||||
// Keep role selectors at one class so static/deprecated modifiers can override their styles.
|
||||
".cm-sem-function:where(.cm-sem-declaration)": semanticStyle("function", "function"),
|
||||
".cm-sem-function:where(.cm-sem-builtin)": semanticStyle("builtin", "function"),
|
||||
// Predefined function / type: unset, they keep the Predefined symbol style.
|
||||
".cm-sem-function:where(.cm-sem-builtin)": inheritedStyle("builtin-function", "builtin"),
|
||||
".cm-sem-function.cm-sem-python-method-call": semanticStyle("python-method-call", "function-call"),
|
||||
// WebStorm's Global function: a module-level function, its declaration and its calls.
|
||||
".cm-sem-global-function": inheritedStyle("global-function", "function"),
|
||||
@@ -535,6 +536,7 @@ export const lspTheme = EditorView.theme({
|
||||
// Before the builtin rule: library globals (`print`, `string`) keep the predefined colour.
|
||||
".cm-sem-global:where(:not(.cm-sem-function))": semanticStyle("global", "variable"),
|
||||
".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-static": { fontStyle: "var(--syn-static-italic, italic)" },
|
||||
".cm-sem-property.cm-sem-static, .cm-sem-property.cm-sem-static *": {
|
||||
|
||||
@@ -377,6 +377,17 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
["predefined", "predefined"],
|
||||
[", ", "operator"],
|
||||
["local", "identifier"],
|
||||
[", ", "operator"],
|
||||
["true", "literalKeyword"],
|
||||
[")", "operator"],
|
||||
],
|
||||
[
|
||||
[" ", "text"],
|
||||
["String", "predefinedType"],
|
||||
[".", "operator"],
|
||||
["format", "predefinedFunction"],
|
||||
["(", "operator"],
|
||||
["null", "literalKeyword"],
|
||||
[")", "operator"],
|
||||
],
|
||||
[
|
||||
@@ -966,7 +977,7 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
["val", "kotlin.keyword"],
|
||||
[" name", "kotlin.parameter"],
|
||||
[": ", "text"],
|
||||
["String", "kotlin.className"],
|
||||
["String", "kotlin.predefinedType"],
|
||||
[")", "kotlin.operator"],
|
||||
[" {", "kotlin.operator"],
|
||||
],
|
||||
@@ -997,9 +1008,11 @@ const SAMPLES: Record<string, CodeSample> = {
|
||||
],
|
||||
[
|
||||
[" ", "text"],
|
||||
["println", "kotlin.predefined"],
|
||||
["println", "kotlin.predefinedFunction"],
|
||||
["(", "kotlin.operator"],
|
||||
["name", "kotlin.identifier"],
|
||||
[" ?: ", "kotlin.operator"],
|
||||
["null", "kotlin.literalKeyword"],
|
||||
[")", "kotlin.operator"],
|
||||
],
|
||||
[["}", "kotlin.operator"]],
|
||||
|
||||
@@ -106,6 +106,31 @@ describe("color schemes", () => {
|
||||
expect(css).not.toMatch(/:root \{[^}]*--syn-decorator/);
|
||||
});
|
||||
|
||||
it("splits Predefined symbol into types and functions and keeps literals apart from Constant (#4059)", () => {
|
||||
for (const [child, parent] of [
|
||||
["predefinedType", "predefined"],
|
||||
["predefinedFunction", "predefined"],
|
||||
["literalKeyword", "keyword"],
|
||||
["kotlin.predefinedType", "kotlin.predefined"],
|
||||
["kotlin.literalKeyword", "kotlin.keyword"],
|
||||
] as const)
|
||||
expect(resolvedAttribute("dark", child)).toEqual(resolvedAttribute("dark", parent));
|
||||
expect(resolvedAttribute("dark", "kotlin.literalKeyword")).not.toEqual(
|
||||
resolvedAttribute("dark", "kotlin.constant"),
|
||||
);
|
||||
// A language's Predefined symbol still reaches unset types and functions: they are not set on :root.
|
||||
const css = schemeCss("dark", { dark: { "kotlin.predefined": { foreground: "#224466" } } });
|
||||
expect(css).not.toContain("--syn-builtin-type");
|
||||
const split = schemeCss("dark", {
|
||||
dark: {
|
||||
"kotlin.predefinedType": { foreground: "#bcbec4" },
|
||||
"kotlin.predefinedFunction": { foreground: "#56a8f5" },
|
||||
},
|
||||
});
|
||||
expect(split).toContain("--syn-builtin-type: #bcbec4 !important");
|
||||
expect(split).toContain("--syn-builtin-function: #56a8f5 !important");
|
||||
});
|
||||
|
||||
it("shows an unset Global function in the function declaration style, then its own (#4059)", () => {
|
||||
const fn = resolvedAttribute("dark", "functionDeclaration");
|
||||
expect(resolvedAttribute("dark", "javascript.globalFunction")).toEqual(fn);
|
||||
|
||||
@@ -300,6 +300,8 @@ const BASE_ATTRIBUTES: readonly AttributeDef[] = [
|
||||
},
|
||||
|
||||
syn("keyword", "Keyword", [LD], "keyword"),
|
||||
// `true`, `false`, `null`: keywords in JetBrains schemes, which have no key of their own for them.
|
||||
syn("literalKeyword", "Literal keyword", [LD], "literal", { inherit: "keyword" }),
|
||||
syn("identifier", "Identifiers › Local variable", [LD], "variable"),
|
||||
syn("parameter", "Identifiers › Parameter", [LD], "param"),
|
||||
syn("globalVariable", "Identifiers › Global variable", [LD], "global"),
|
||||
@@ -317,6 +319,9 @@ const BASE_ATTRIBUTES: readonly AttributeDef[] = [
|
||||
syn("functionDeclaration", "Identifiers › Function declaration", [LD], "function"),
|
||||
syn("functionCall", "Identifiers › Function call", [LD], "function-call"),
|
||||
syn("predefined", "Identifiers › Predefined symbol", [LD], "builtin"),
|
||||
// A standard library's types and functions (String, let), apart from its other symbols.
|
||||
syn("predefinedType", "Identifiers › Predefined type", [LD], "builtin-type", { inherit: "builtin" }),
|
||||
syn("predefinedFunction", "Identifiers › Predefined function", [LD], "builtin-function", { inherit: "builtin" }),
|
||||
syn("className", "Classes › Class name", [LD], "type"),
|
||||
syn("number", "Number", [LD], "number"),
|
||||
syn("string", "String › String text", [LD], "string"),
|
||||
|
||||
@@ -2961,5 +2961,8 @@
|
||||
"Cannot find the source of {0}": "Cannot find the source of {0}",
|
||||
"JavaScript and TypeScript": "JavaScript and TypeScript",
|
||||
"Global function": "Global function",
|
||||
"Decorator": "Decorator"
|
||||
"Decorator": "Decorator",
|
||||
"Literal keyword": "Literal keyword",
|
||||
"Predefined type": "Predefined type",
|
||||
"Predefined function": "Predefined function"
|
||||
}
|
||||
|
||||
@@ -9288,5 +9288,8 @@
|
||||
"This CLI discovers the folder itself: off hides the skill from OpenIDEA's / menu and applies only where the CLI supports disabling.": "该 CLI 会自己发现这个文件夹:关闭只会让 OpenIDEA 的 / 菜单不再提供该技能,并且只在 CLI 支持禁用时生效。",
|
||||
"Cannot find the source of {0}": "找不到 {0} 的源代码",
|
||||
"JavaScript and TypeScript": "JavaScript 和 TypeScript",
|
||||
"Global function": "全局函数"
|
||||
"Global function": "全局函数",
|
||||
"Literal keyword": "字面量关键字",
|
||||
"Predefined type": "预定义类型",
|
||||
"Predefined function": "预定义函数"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user