Files
paseo/packages/highlight/src/syntax-roles.ts
T
Mohamed BoudraandGitHub 4bda2dfea9 Edit workspace files directly on web (#2270)
* feat(files): edit workspace files on web

Keep source buffers synchronized with host file changes and require an explicit overwrite or reload when revisions diverge.

* feat(panels): surface and protect modified tabs

Expose tooltip and modification state through the generic panel boundary so tabs can show stable metadata and guard every close route consistently.

* fix(tests): use portable fake timeout handle

* fix(files): harden editor conflict handling

Preserve modified panel state across tab eviction, use precise revisions for optimistic writes, coalesce concurrent file watchers, and localize the editor interface.

* fix(files): close editor concurrency gaps

Coalesce clean reloads, preserve subscriber identities and file permissions, suspend pending saves during close confirmation, and carry precise revisions through file reads.

* test(files): expect read revision metadata
2026-07-21 04:41:19 +08:00

58 lines
2.5 KiB
TypeScript

import { HighlightStyle as CodeMirrorHighlightStyle } from "@codemirror/language";
import { tagHighlighter, tags, type Tag } from "@lezer/highlight";
import type { HighlightStyle } from "./types.js";
export const syntaxRoleTags: ReadonlyArray<{ tag: Tag; role: HighlightStyle }> = [
{ tag: tags.keyword, role: "keyword" },
{ tag: tags.controlKeyword, role: "keyword" },
{ tag: tags.operatorKeyword, role: "keyword" },
{ tag: tags.definitionKeyword, role: "keyword" },
{ tag: tags.moduleKeyword, role: "keyword" },
{ tag: tags.comment, role: "comment" },
{ tag: tags.lineComment, role: "comment" },
{ tag: tags.blockComment, role: "comment" },
{ tag: tags.docComment, role: "comment" },
{ tag: tags.string, role: "string" },
{ tag: tags.special(tags.string), role: "string" },
{ tag: tags.number, role: "number" },
{ tag: tags.integer, role: "number" },
{ tag: tags.float, role: "number" },
{ tag: tags.bool, role: "literal" },
{ tag: tags.null, role: "literal" },
{ tag: tags.function(tags.variableName), role: "function" },
{ tag: tags.function(tags.propertyName), role: "function" },
{ tag: tags.definition(tags.variableName), role: "definition" },
{ tag: tags.definition(tags.propertyName), role: "definition" },
{ tag: tags.definition(tags.function(tags.variableName)), role: "definition" },
{ tag: tags.className, role: "class" },
{ tag: tags.definition(tags.className), role: "class" },
{ tag: tags.typeName, role: "type" },
{ tag: tags.tagName, role: "tag" },
{ tag: tags.attributeName, role: "attribute" },
{ tag: tags.attributeValue, role: "string" },
{ tag: tags.propertyName, role: "property" },
{ tag: tags.variableName, role: "variable" },
{ tag: tags.local(tags.variableName), role: "variable" },
{ tag: tags.special(tags.variableName), role: "variable" },
{ tag: tags.operator, role: "operator" },
{ tag: tags.punctuation, role: "punctuation" },
{ tag: tags.bracket, role: "punctuation" },
{ tag: tags.separator, role: "punctuation" },
{ tag: tags.regexp, role: "regexp" },
{ tag: tags.escape, role: "escape" },
{ tag: tags.meta, role: "meta" },
{ tag: tags.heading, role: "heading" },
{ tag: tags.link, role: "link" },
{ tag: tags.url, role: "link" },
];
export const staticSyntaxHighlighter = tagHighlighter(
syntaxRoleTags.map(({ tag, role }) => ({ tag, class: role })),
);
export function createCodeMirrorHighlightStyle(colors: Record<HighlightStyle, string>) {
return CodeMirrorHighlightStyle.define(
syntaxRoleTags.map(({ tag, role }) => ({ tag, color: colors[role] })),
);
}