Skip to content

Commit c875f9c

Browse files
committed
Code editor language support
1 parent 43ed176 commit c875f9c

File tree

6 files changed

+91
-33
lines changed

6 files changed

+91
-33
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
"@gradio/theme": "workspace:*",
6666
"@gradio/upload": "workspace:*",
6767
"@gradio/utils": "workspace:*",
68+
"@lezer/generator": "^1.2.3",
69+
"@lezer/highlight": "^1.1.3",
70+
"@lezer/lr": "^1.3.6",
6871
"@litegraph-ts/core": "workspace:*",
6972
"@litegraph-ts/nodes-basic": "workspace:*",
7073
"@litegraph-ts/nodes-events": "workspace:*",

pnpm-lock.yaml

Lines changed: 26 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/widgets/ComfyUI.grammar

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@top Program { expression* }
2+
3+
@skip {} {
4+
BlockComment { "/*" (blockCommentContent | blockCommentNewline)* blockCommentEnd }
5+
}
6+
7+
@skip { space | LineComment | BlockComment }
8+
9+
@local tokens {
10+
blockCommentEnd { "*/" }
11+
blockCommentNewline { "\n" }
12+
@else blockCommentContent
13+
}
14+
15+
expression {
16+
Identifier |
17+
String |
18+
Boolean |
19+
Application { "(" expression* ")" }
20+
}
21+
22+
@tokens {
23+
Identifier { $[a-zA-Z_\-0-9]+ }
24+
25+
String { '"' (!["\\] | "\\" _)* '"' }
26+
27+
Boolean { "#t" | "#f" }
28+
29+
LineComment { "//" ![\n]* }
30+
31+
space { $[ \t\n\r]+ }
32+
33+
"(" ")"
34+
}
35+
36+
@detectDelim

src/lib/widgets/ComfyUI.grammar.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { LRParser } from "@lezer/lr"
2+
3+
export declare const parser: LRParser

src/lib/widgets/TextWidgetCodeVariant.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
indentOnInput,
1515
syntaxHighlighting,
1616
defaultHighlightStyle,
17-
foldKeymap
17+
foldKeymap,
18+
LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent
1819
} from "@codemirror/language";
1920
import { history, defaultKeymap, historyKeymap } from "@codemirror/commands";
2021
import {
@@ -27,8 +28,26 @@ import {
2728
type CompletionSource, autocompletion, CompletionContext, startCompletion,
2829
currentCompletions, completionStatus, completeFromList, acceptCompletion
2930
} from "@codemirror/autocomplete"
31+
import { styleTags, tags as t } from "@lezer/highlight"
3032
import DanbooruTags from "$lib/DanbooruTags";
3133

34+
import { parser } from "./ComfyUI.grammar"
35+
36+
export const comfyUILanguage = LRLanguage.define({
37+
name: "ComfyUI",
38+
parser: parser.configure({
39+
props: [
40+
styleTags({
41+
LineComment: t.lineComment,
42+
BlockComment: t.blockComment,
43+
})
44+
]
45+
}),
46+
languageData: {
47+
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
48+
}
49+
})
50+
3251
export const basicSetup: Extension = /*@__PURE__*/ (() => [
3352
lineNumbers(),
3453
highlightSpecialChars(),
@@ -43,6 +62,7 @@ export const basicSetup: Extension = /*@__PURE__*/ (() => [
4362
crosshairCursor(),
4463
EditorView.lineWrapping,
4564
DanbooruTags.getCompletionExt(),
65+
new LanguageSupport(comfyUILanguage),
4666

4767
keymap.of([
4868
...closeBracketsKeymap,

vite.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import removeConsole from 'vite-plugin-svelte-console-remover';
88
import glsl from 'vite-plugin-glsl';
99
import { execSync } from "child_process"
1010
import { visualizer } from "rollup-plugin-visualizer";
11+
import { lezer } from "@lezer/generator/rollup"
1112

1213
const isProduction = process.env.NODE_ENV === "production";
1314
console.log("Production build: " + isProduction)
@@ -31,6 +32,7 @@ export default defineConfig({
3132
isProduction && removeConsole(),
3233
glsl(),
3334
svelte(),
35+
lezer(),
3436
visualizer(),
3537
viteStaticCopy({
3638
targets: [

0 commit comments

Comments
 (0)