дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 03:05:40 +02:00
Kotlin files showed declarations, parameters, fields, annotations, KDoc and escapes in generic lexer colours, because the CodeMirror mode alone drove their highlighting. Kotlin now gets supplemental backend marks from its tree-sitter grammar, which take precedence over lexer marks while LSP semantic marks stay innermost. The semantic provider also maps the mutable and operator-declaration tokens. Siblings covered: other grammars keep their parameter colours, and constructor default values are highlighted as values. Co-authored-by: shohruh-genius <[email protected]>
53 рядки
2.0 KiB
TypeScript
53 рядки
2.0 KiB
TypeScript
import { EditorView } from "@codemirror/view";
|
|
import { syntaxHighlighting } from "@codemirror/language";
|
|
import { schemeCss } from "../src/platform/colorScheme";
|
|
import { openideaHighlightStyle } from "../src/editor/core/cm/highlight";
|
|
import { findLanguageDescription, loadSupport } from "../src/editor/core/cm/languages";
|
|
import { syntaxHighlightField, setSyntaxHighlights } from "../src/editor/core/cm/syntaxHighlight";
|
|
import { commands } from "../src/platform/ipc";
|
|
import { setInvokeRoute } from "../src/platform/tauriCore";
|
|
import { lspDoc } from "../src/editor/lsp/lsp";
|
|
import { semanticExtension } from "../src/editor/lsp/semantic";
|
|
import { lspTheme } from "../src/editor/lsp/theme";
|
|
|
|
const semantic = new URLSearchParams(location.search).has("semantic");
|
|
setInvokeRoute(() => null);
|
|
commands.lspSemanticTokens = async () => ({
|
|
status: "ok",
|
|
data: {
|
|
tokenTypes: ["operator", "parameter"],
|
|
tokenModifiers: ["declaration", "modification"],
|
|
data: [0, 4, 5, 0, 1, 0, 10, 6, 1, 2],
|
|
},
|
|
});
|
|
|
|
const style = document.createElement("style");
|
|
style.textContent = schemeCss("dark", {
|
|
dark: {
|
|
"kotlin.functionDeclaration": { foreground: "#557799", background: "#ddeeff", bold: true },
|
|
"kotlin.parameter": { foreground: "#6688aa" },
|
|
},
|
|
});
|
|
document.head.append(style);
|
|
const host = document.createElement("section");
|
|
host.dataset.language = "Kotlin";
|
|
document.body.append(host);
|
|
const support = await loadSupport(findLanguageDescription("Kotlin", "Demo.kt")!);
|
|
const view = new EditorView({
|
|
parent: host,
|
|
doc: "fun greet(prefix: String) {}",
|
|
extensions: [
|
|
support!,
|
|
syntaxHighlightField,
|
|
syntaxHighlighting(openideaHighlightStyle),
|
|
...(semantic
|
|
? [
|
|
lspTheme,
|
|
lspDoc.of({ doc: 1, path: "Demo.kt", language: "kotlin", uiMode: "Kotlin", readOnly: false }),
|
|
semanticExtension(),
|
|
]
|
|
: []),
|
|
],
|
|
});
|
|
view.dispatch({ effects: setSyntaxHighlights.of({ kinds: ["function", "parameter"], data: [4, 9, 0, 10, 16, 1] }) });
|