dsh-gufa-code 1.3.92 → 1.3.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,8 @@ dsh plugin add dsh-gufa-code
38
38
 
39
39
  ### 编辑器
40
40
 
41
- - Monaco 编辑器(离线随包分发,无需联网下载);
41
+ - Monaco 编辑器(离线随包分发,无需联网下载);Monaco 自带 81 种语言全部映射(ABAP、Apex、Clojure、Elixir、F#、GraphQL、HCL/Terraform、Julia、Objective-C、Pascal、Perl、Protobuf、R、RST、Scheme、Solidity、SystemVerilog/Verilog、Tcl、TypeSpec、VB、WGSL、Bicep、Batch、CoffeeScript、Cypher、DAX、Logstash/ECL、MIPS、Power Query、Q#、Redis、SPARQL、Structured Text、Modula-3、ATS、Pony 系列等);
42
+ - **HTML 模板语法高亮**:EJS / Eta、ERB、Nunjucks / Jinja2(`.njk/.nunjucks/.jinja/.jinja2/.j2`)、Blade(`.blade.php`)、Haml、Slim,以及 Monaco 内置的 Handlebars / Mustache / Pug / Twig / Liquid / Razor / FreeMarker;扩展名自动识别;
42
43
  - 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
43
44
  - **Copilot 风格 Tab 行内补全**:光标停/打字后,基于 Harness 自己的 DeepSeek 模型(默认 `deepseek-flash`,不需要额外 Copilot 订阅)流式生成灰色 ghost text,Tab 接受、Esc 忽略;支持 JS/TS/Python/Java/Go/Rust/C++/C#/JSON/YAML/Shell 等常见语言;
44
45
  - 保存走磁盘版本冲突检测 + 原子写;未保存标记;
package/client.js CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.92'
19
+ G.BUILD = '1.3.94'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -2347,6 +2347,276 @@ G.FooterAction = function FooterAction(props) {
2347
2347
  }
2348
2348
 
2349
2349
 
2350
+ /* ─────────────────────── 15-template-languages.js ─────────────────────── */
2351
+ /**
2352
+ * 15-template-languages:补 Monaco 自带的 HTML 模板语法。
2353
+ *
2354
+ * Monaco 已内置 handlebars / twig / liquid / pug / razor / freemarker2;这里补上
2355
+ * 市面上常用但 Monaco 没带的:EJS、Eta、ERB、Nunjucks/Jinja2(共用一套)、
2356
+ * Blade、Haml、Slim。均为「HTML + 模板分隔符里的代码」的简化 Monarch 高亮,
2357
+ * 不追求语法服务,只保证打开文件时有正常的颜色、注释和括号行为。
2358
+ */
2359
+ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
2360
+ if (monaco === null || monaco === undefined || !monaco.languages || G.__templateLanguagesRegistered === true) return
2361
+ G.__templateLanguagesRegistered = true
2362
+
2363
+ const existing = (() => {
2364
+ try {
2365
+ const list = monaco.languages.getLanguages()
2366
+ return new Set(Array.isArray(list) ? list.map((item) => item.id) : [])
2367
+ } catch {
2368
+ return new Set()
2369
+ }
2370
+ })()
2371
+
2372
+ const define = (id, extensions, aliases, tokenizer, configuration) => {
2373
+ if (existing.has(id)) return
2374
+ try {
2375
+ monaco.languages.register({ id, extensions, aliases })
2376
+ if (tokenizer !== null && tokenizer !== undefined) monaco.languages.setMonarchTokensProvider(id, tokenizer)
2377
+ if (configuration !== null && configuration !== undefined) monaco.languages.setLanguageConfiguration(id, configuration)
2378
+ existing.add(id)
2379
+ } catch (error) {
2380
+ /* 某个语言注册失败不影响其它语言 */
2381
+ }
2382
+ }
2383
+
2384
+ const htmlBase = () => ({
2385
+ root: [
2386
+ [/<!--/, 'comment', '@htmlComment'],
2387
+ [/<[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
2388
+ [/<\/[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
2389
+ [/&[a-zA-Z#0-9]+;/, 'string.escape'],
2390
+ [/[^<&]+/, ''],
2391
+ ],
2392
+ htmlComment: [
2393
+ [/-->/, { token: 'comment', next: '@pop' }],
2394
+ [/./, 'comment'],
2395
+ ],
2396
+ htmlTag: [
2397
+ [/\s+/, ''],
2398
+ [/[a-zA-Z_:][\w:.-]*/, 'attribute.name'],
2399
+ [/=/, 'delimiter'],
2400
+ [/"[^"]*"/, 'attribute.value'],
2401
+ /* ' 不参与转义(Monarch 不需要) */
2402
+ [/'[^']*'/, 'attribute.value'],
2403
+ [/\/>/, { token: 'tag', next: '@pop' }],
2404
+ [/>/, { token: 'tag', next: '@pop' }],
2405
+ [/</, { token: 'tag', next: '@pop' }],
2406
+ ],
2407
+ })
2408
+
2409
+ const jsKeywords = 'if|else|for|while|do|switch|case|break|continue|function|return|var|let|const|new|typeof|instanceof|in|of|try|catch|finally|throw|class|extends|super|import|export|from|as|await|async|yield|this|true|false|null|undefined|delete|void|with|debugger'
2410
+ const jinjaKeywords = 'if|else|elif|endif|for|endfor|block|endblock|extends|include|import|from|as|set|endset|macro|endmacro|filter|endfilter|with|endwith|raw|endraw|call|endcall|is|not|and|or|in|recursive|without|context|autoescape|endautoescape|trans|endtrans|do|loop|else'
2411
+ const rubyKeywords = 'def|end|if|elsif|else|unless|case|when|while|until|for|do|begin|rescue|ensure|class|module|return|yield|break|next|redo|retry|super|self|nil|true|false|and|or|not|require|include|extend|attr_accessor|attr_reader|attr_writer|lambda|proc|puts|print|raise|new'
2412
+ const bladeKeywords = 'if|elseif|else|endif|unless|endunless|foreach|endforeach|forelse|endforelse|for|endfor|while|endwhile|switch|endswitch|case|break|continue|extends|section|endsection|yield|include|each|push|stack|component|slot|php|endphp|auth|guest|env|production|error|csrf|method|json|checked|selected|disabled|readonly|required'
2413
+
2414
+ const codeTokens = (keywords, closePatterns) => {
2415
+ const rules = []
2416
+ for (const close of closePatterns) rules.push(close)
2417
+ rules.push(
2418
+ [/\/\/.*$/, 'comment'],
2419
+ [/\/\*/, 'comment', '@blockComment'],
2420
+ [/"[^"]*"/, 'string'],
2421
+ [/'[^']*'/, 'string'],
2422
+ [/`[^`]*`/, 'string'],
2423
+ [new RegExp(`\\b(?:${keywords})\\b`), 'keyword'],
2424
+ [/\b\d+(?:\.\d+)?\b/, 'number'],
2425
+ [/[A-Za-z_$][\w$]*/, 'identifier'],
2426
+ [/[{}()\[\]]/, '@brackets'],
2427
+ [/[<>=!+\-*/%&|^~?:;,.]+/, 'operator'],
2428
+ [/\s+/, ''],
2429
+ )
2430
+ return rules
2431
+ }
2432
+
2433
+ const blockCommentState = [
2434
+ [/\*\//, { token: 'comment', next: '@pop' }],
2435
+ [/./, 'comment'],
2436
+ ]
2437
+
2438
+ /* ── EJS / Eta:HTML + <% ... %> ───────────────────────────────────── */
2439
+ define('ejs', ['.ejs', '.eta'], ['EJS', 'Eta'], (() => {
2440
+ const base = htmlBase()
2441
+ return {
2442
+ defaultToken: '',
2443
+ tokenizer: {
2444
+ root: [
2445
+ [/<!--/, 'comment', '@htmlComment'],
2446
+ [/<%#/, 'comment', '@ejsComment'],
2447
+ [/<%[-=]?/, { token: 'delimiter.template', next: '@ejsCode' }],
2448
+ ...base.root.slice(1),
2449
+ ],
2450
+ htmlComment: base.htmlComment,
2451
+ htmlTag: base.htmlTag,
2452
+ ejsComment: [
2453
+ [/%>/, { token: 'comment', next: '@pop' }],
2454
+ [/./, 'comment'],
2455
+ ],
2456
+ ejsCode: codeTokens(jsKeywords, [[/%>/, { token: 'delimiter.template', next: '@pop' }]]),
2457
+ blockComment: blockCommentState,
2458
+ },
2459
+ }
2460
+ })(), {
2461
+ comments: { blockComment: ['<!--', '-->'] },
2462
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2463
+ autoClosingPairs: [
2464
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
2465
+ { open: '<%', close: '%>' }, { open: '<%=', close: '%>' },
2466
+ { open: '"', close: '"' }, { open: "'", close: "'" },
2467
+ ],
2468
+ surroundingPairs: [{ open: '<%', close: '%>' }, { open: '"', close: '"' }, { open: "'", close: "'" }],
2469
+ })
2470
+
2471
+ /* ── ERB:HTML + <% ... %>(Ruby 代码) ────────────────────────────── */
2472
+ define('erb', ['.erb', '.rhtml', '.html.erb'], ['ERB'], (() => {
2473
+ const base = htmlBase()
2474
+ return {
2475
+ defaultToken: '',
2476
+ tokenizer: {
2477
+ root: [
2478
+ [/<!--/, 'comment', '@htmlComment'],
2479
+ [/<%#/, 'comment', '@erbComment'],
2480
+ [/<%[-=]?/, { token: 'delimiter.template', next: '@erbCode' }],
2481
+ ...base.root.slice(1),
2482
+ ],
2483
+ htmlComment: base.htmlComment,
2484
+ htmlTag: base.htmlTag,
2485
+ erbComment: [
2486
+ [/%>/, { token: 'comment', next: '@pop' }],
2487
+ [/./, 'comment'],
2488
+ ],
2489
+ erbCode: codeTokens(rubyKeywords, [[/%>/, { token: 'delimiter.template', next: '@pop' }]]),
2490
+ blockComment: blockCommentState,
2491
+ },
2492
+ }
2493
+ })(), {
2494
+ comments: { blockComment: ['<!--', '-->'] },
2495
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2496
+ autoClosingPairs: [
2497
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
2498
+ { open: '<%', close: '%>' }, { open: '"', close: '"' }, { open: "'", close: "'" },
2499
+ ],
2500
+ })
2501
+
2502
+ /* ── Nunjucks / Jinja2:HTML + {{ }} / {% %} / {# #} ─────────────── */
2503
+ define('jinja', ['.njk', '.nunjucks', '.jinja', '.jinja2', '.j2', '.j2.html'], ['Nunjucks', 'Jinja2'], {
2504
+ defaultToken: '',
2505
+ tokenizer: {
2506
+ root: [
2507
+ [/<!--/, 'comment', '@htmlComment'],
2508
+ [/\{#/, 'comment', '@jinjaComment'],
2509
+ [/\{\{/, { token: 'delimiter.template', next: '@jinjaExpr' }],
2510
+ [/\{%/, { token: 'delimiter.template', next: '@jinjaStmt' }],
2511
+ [/<[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
2512
+ [/<\/[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
2513
+ [/&[a-zA-Z#0-9]+;/, 'string.escape'],
2514
+ [/[^<{&]+/, ''],
2515
+ ],
2516
+ htmlComment: [[/-->/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
2517
+ htmlTag: htmlBase().htmlTag,
2518
+ jinjaComment: [[/#\}/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
2519
+ jinjaExpr: codeTokens(jinjaKeywords, [
2520
+ [/\}\}/, { token: 'delimiter.template', next: '@pop' }],
2521
+ [/\|/, 'operator'],
2522
+ ]),
2523
+ jinjaStmt: codeTokens(jinjaKeywords, [
2524
+ [/%\}/, { token: 'delimiter.template', next: '@pop' }],
2525
+ [/\|/, 'operator'],
2526
+ ]),
2527
+ blockComment: blockCommentState,
2528
+ },
2529
+ }, {
2530
+ comments: { blockComment: ['<!--', '-->'] },
2531
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2532
+ autoClosingPairs: [
2533
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
2534
+ { open: '{{', close: '}}' }, { open: '{%', close: '%}' }, { open: '{#', close: '#}' },
2535
+ { open: '"', close: '"' }, { open: "'", close: "'" },
2536
+ ],
2537
+ })
2538
+
2539
+ /* ── Blade:HTML + {{ }} / {!! !!} / {{-- --}} / @directive ─────── */
2540
+ define('blade', ['.blade.php'], ['Blade'], (() => {
2541
+ const base = htmlBase()
2542
+ return {
2543
+ defaultToken: '',
2544
+ tokenizer: {
2545
+ root: [
2546
+ [/\{\{--/, 'comment', '@bladeComment'],
2547
+ [/\{!!/, { token: 'delimiter.template', next: '@bladeExpr' }],
2548
+ [/\{\{/, { token: 'delimiter.template', next: '@bladeExpr' }],
2549
+ [/@[a-zA-Z_][\w-]*/, 'keyword.directive'],
2550
+ ...base.root,
2551
+ ],
2552
+ htmlComment: base.htmlComment,
2553
+ htmlTag: base.htmlTag,
2554
+ bladeComment: [[/--\}\}/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
2555
+ bladeExpr: codeTokens(bladeKeywords, [
2556
+ [/\}\}/, { token: 'delimiter.template', next: '@pop' }],
2557
+ [/!!\}/, { token: 'delimiter.template', next: '@pop' }],
2558
+ ]),
2559
+ blockComment: blockCommentState,
2560
+ },
2561
+ }
2562
+ })(), {
2563
+ comments: { blockComment: ['{{--', '--}}'] },
2564
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2565
+ autoClosingPairs: [
2566
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
2567
+ { open: '{{', close: '}}' }, { open: '{{--', close: '--}}' },
2568
+ { open: '"', close: '"' }, { open: "'", close: "'" },
2569
+ ],
2570
+ })
2571
+
2572
+ /* ── Haml:缩进 + %tag / .class / #id / = / - ──────────────────── */
2573
+ define('haml', ['.haml'], ['Haml'], {
2574
+ defaultToken: '',
2575
+ tokenizer: {
2576
+ root: [
2577
+ [/^\s*!!!.*$/, 'meta'],
2578
+ [/^\s*\/.*$/, 'comment'],
2579
+ [/^\s*%[a-zA-Z][\w:-]*/, 'tag'],
2580
+ [/[.#][\w-]+/, 'attribute.name'],
2581
+ [/^\s*[-=]/, 'operator'],
2582
+ [/\{.*?\}/, 'string.interpolated'],
2583
+ [/"[^"]*"/, 'string'],
2584
+ [/'[^']*'/, 'string'],
2585
+ [/[A-Za-z_][\w-]*:/, 'attribute.name'],
2586
+ [/[^\n]+/, ''],
2587
+ [/\n/, ''],
2588
+ ],
2589
+ },
2590
+ }, {
2591
+ comments: { lineComment: '/' },
2592
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2593
+ })
2594
+
2595
+ /* ── Slim:缩进 + tag / = / - / | ──────────────────────────────── */
2596
+ define('slim', ['.slim'], ['Slim'], {
2597
+ defaultToken: '',
2598
+ tokenizer: {
2599
+ root: [
2600
+ [/^\s*(doctype)\b/, 'keyword'],
2601
+ [/^\s*\/.*$/, 'comment'],
2602
+ [/^\s*[-=]/, 'operator'],
2603
+ [/^\s*\|/, 'string'],
2604
+ [/^[\s]*[a-zA-Z][\w-]*/, 'tag'],
2605
+ [/[.#][\w-]+/, 'attribute.name'],
2606
+ [/[a-zA-Z_][\w-]*=/, 'attribute.name'],
2607
+ [/"[^"]*"/, 'string'],
2608
+ [/'[^']*'/, 'string'],
2609
+ [/[^\n]+/, ''],
2610
+ [/\n/, ''],
2611
+ ],
2612
+ },
2613
+ }, {
2614
+ comments: { lineComment: '/' },
2615
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
2616
+ })
2617
+ }
2618
+
2619
+
2350
2620
  /* ─────────────────────── 20-editor.js ─────────────────────── */
2351
2621
  /**
2352
2622
  * 20-editor:「古法编程」Monaco 多标签编辑器(Cursor / VS Code 风格)。
@@ -3073,6 +3343,11 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
3073
3343
  gufaLoadMonaco()
3074
3344
  .then((monaco) => {
3075
3345
  if (cancelled) return
3346
+ try {
3347
+ if (typeof G.registerTemplateLanguages === 'function') G.registerTemplateLanguages(monaco)
3348
+ } catch (error) {
3349
+ /* 模板语言注册失败不影响编辑器 */
3350
+ }
3076
3351
  try {
3077
3352
  const instance = monaco.editor.create(host, gufaEditorOptions(propsRef.current.theme))
3078
3353
  editor = instance
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.92</string>
11
- <key>CFBundleVersion</key><string>1.3.92</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.94</string>
11
+ <key>CFBundleVersion</key><string>1.3.94</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -39,6 +39,20 @@
39
39
  - 行范围引用格式 `@path Lx-Ly`;chip 标签里存路径+行号用于点击定位,`localStorage` key 使用 `gufa-code.refs.v1`。
40
40
  - **model URI 是项目绝对路径,引用 chip 必须转成项目相对路径**(`G.projectRoot` 前缀剥离),否则点击 chip 会走 `fs.read` 绝对路径并报「路径不存在」;这个坑 1.3.92 已修。
41
41
 
42
+ ## 0.9 HTML 模板语法(1.3.93)
43
+
44
+ - Monaco 的 `editor.main` 自带 handlebars / twig / liquid / pug / razor / freemarker2 等 basic-languages;**EJS/ERB/Nunjucks/Jinja2/Blade/Haml/Slim 需要自己注册**(`src/client/15-template-languages.js`,`monaco.languages.register` + `setMonarchTokensProvider` + `setLanguageConfiguration`)。
45
+ - 注册时机必须在 `gufaLoadMonaco()` 之后、创建 model 之前;`gufaResolveLanguage` 只接受 `getLanguages()` 里存在的 id,所以注册失败会静默回落 plaintext。
46
+ - `host/fs.js` 的 `LANG_BY_EXT` 决定 `.ejs/.njk/...` 返回哪个 language id;`.blade.php` 双扩展名要在 `languageOf` 里先特判,否则会命中 `php`。
47
+ - 自定义 tokenizer 是「HTML + 模板分隔符里的代码」简化版,不提供语义服务;Monarch 里 `@brackets`、`blockComment` 状态要各自定义,且 `htmlTag` 状态里 `/>` 要在 `>` 之前。
48
+
49
+ ## 0.10 Monaco 语言映射审计(1.3.94)
50
+
51
+ - Monaco basic-languages 里注册的 81 种语言,扩展名表在 `vendor/monaco/vs/editor/editor.main.js` 里;`host/fs.js` 的 `LANG_BY_EXT` 必须全部覆盖,否则打开文件会落到 plaintext。
52
+ - 审计脚本思路:从 `editor.main.js` 抓 `id:"x" ... extensions:[...]`(注意 `aliases` 可能夹在 `id` 与 `extensions` 之间,正则要允许中间内容),再对比 `LANG_BY_EXT` 的值集合。
53
+ - 有多个语言共享扩展名(`.p` Pascal、`.m` Objective-C、`.v` Verilog、`.cls` Apex、`.pp` Ruby/Pascal、`.s` MIPS、`.config` XML 等)时,按 Monaco 默认取一个;用户项目里如果扩展名含义不同,改 `LANG_BY_EXT` 一行即可。
54
+ - 点开头文件(`.babelrc/.eslintrc/.jshintrc/.jscsrc/.bowerrc` → json、`.gitconfig` → ini、`.rprofile` → r)要在 `languageOf` 的 `lastIndexOf('.')` 之前特判,否则会被当成 plaintext。
55
+
42
56
  ## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
43
57
 
44
58
  **现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
package/host/fs.js CHANGED
@@ -21,19 +21,48 @@ const LIST_LIMIT = 4000
21
21
 
22
22
  /** 扩展名 → Monaco language id(与 VS Code 常用映射一致)。 */
23
23
  export const LANG_BY_EXT = {
24
- js: 'javascript', jsx: 'javascript', mjs: 'javascript', cjs: 'javascript',
24
+ js: 'javascript', jsx: 'javascript', mjs: 'javascript', cjs: 'javascript', es6: 'javascript',
25
25
  ts: 'typescript', tsx: 'typescript', mts: 'typescript', cts: 'typescript',
26
- json: 'json', jsonc: 'json', json5: 'json',
27
- md: 'markdown', markdown: 'markdown', mdx: 'markdown',
26
+ json: 'json', jsonc: 'json', json5: 'json', bowerrc: 'json', jshintrc: 'json', jscsrc: 'json', eslintrc: 'json', babelrc: 'json', har: 'json',
27
+ md: 'markdown', markdown: 'markdown', mdown: 'markdown', mkdn: 'markdown', mkd: 'markdown', mdwn: 'markdown', mdtxt: 'markdown', mdtext: 'markdown',
28
28
  css: 'css', scss: 'scss', less: 'less',
29
- html: 'html', htm: 'html', vue: 'html', svelte: 'html',
29
+ html: 'html', htm: 'html', vue: 'html', svelte: 'html', astro: 'html',
30
+ shtml: 'html', xhtml: 'html', mdoc: 'html', jsp: 'html', asp: 'html', aspx: 'html', jshtm: 'html',
31
+ mdx: 'mdx',
32
+ ejs: 'ejs', eta: 'ejs',
33
+ hbs: 'handlebars', handlebars: 'handlebars', mustache: 'handlebars',
34
+ pug: 'pug', jade: 'pug',
35
+ njk: 'jinja', nunjucks: 'jinja', jinja: 'jinja', jinja2: 'jinja', j2: 'jinja',
36
+ liquid: 'liquid', twig: 'twig', ftl: 'freemarker2', razor: 'razor', cshtml: 'razor',
37
+ erb: 'erb', rhtml: 'erb',
38
+ haml: 'haml', slim: 'slim',
30
39
  xml: 'xml', svg: 'xml', plist: 'xml', csproj: 'xml',
31
- yaml: 'yaml', yml: 'yaml', toml: 'ini', ini: 'ini', cfg: 'ini', conf: 'ini', properties: 'ini', env: 'ini',
32
- py: 'python', pyw: 'python',
33
- sh: 'shell', bash: 'shell', zsh: 'shell', fish: 'shell', ps1: 'powershell',
34
- lua: 'lua', java: 'java', c: 'c', h: 'c', cpp: 'cpp', cc: 'cpp', cxx: 'cpp', hpp: 'cpp', hxx: 'cpp',
35
- cs: 'csharp', go: 'go', rs: 'rust', rb: 'ruby', php: 'php', sql: 'sql',
36
- swift: 'swift', kt: 'kotlin', kts: 'kotlin', dart: 'dart', scala: 'scala',
40
+ xsd: 'xml', dtd: 'xml', ascx: 'xml', config: 'xml', props: 'xml', targets: 'xml',
41
+ wxi: 'xml', wxl: 'xml', wxs: 'xml', xaml: 'xml', svgz: 'xml', opf: 'xml', xslt: 'xml', xsl: 'xml',
42
+ yaml: 'yaml', yml: 'yaml', toml: 'ini', ini: 'ini', cfg: 'ini', conf: 'ini', properties: 'ini', env: 'ini', gitconfig: 'ini',
43
+ py: 'python', pyw: 'python', rpy: 'python', cpy: 'python', gyp: 'python', gypi: 'python',
44
+ sh: 'shell', bash: 'shell', zsh: 'shell', fish: 'shell', ps1: 'powershell', psm1: 'powershell', psd1: 'powershell',
45
+ bat: 'bat', cmd: 'bat', azcli: 'azcli', bicep: 'bicep', abap: 'abap', apex: 'apex', cls: 'apex',
46
+ clj: 'clojure', cljs: 'clojure', cljc: 'clojure', edn: 'clojure',
47
+ coffee: 'coffeescript', csp: 'csp', cypher: 'cypher', cyp: 'cypher', ecl: 'ecl',
48
+ ex: 'elixir', exs: 'elixir', flow: 'flow9', fs: 'fsharp', fsi: 'fsharp', ml: 'fsharp', mli: 'fsharp', fsx: 'fsharp', fsscript: 'fsharp',
49
+ graphql: 'graphql', gql: 'graphql', tf: 'hcl', tfvars: 'hcl', hcl: 'hcl', jl: 'julia',
50
+ lex: 'lexon', m3: 'm3', i3: 'm3', mg: 'm3', ig: 'm3', s: 'mips',
51
+ dax: 'msdax', msdax: 'msdax', m: 'objective-c', pas: 'pascal', p: 'pascal',
52
+ ligo: 'pascaligo', pl: 'perl', pm: 'perl', pla: 'pla', dats: 'postiats', sats: 'postiats', hats: 'postiats',
53
+ pq: 'powerquery', pqm: 'powerquery', proto: 'proto', qs: 'qsharp',
54
+ r: 'r', rhistory: 'r', rmd: 'r', rt: 'r', redis: 'redis', rst: 'restructuredtext',
55
+ sb: 'sb', scm: 'scheme', ss: 'scheme', sch: 'scheme', rkt: 'scheme',
56
+ sol: 'sol', rq: 'sparql', st: 'st', iecst: 'st', iecplc: 'st', lc3lib: 'st',
57
+ sv: 'systemverilog', svh: 'systemverilog', v: 'verilog', vh: 'verilog',
58
+ tcl: 'tcl', tsp: 'typespec', vb: 'vb', wgsl: 'wgsl',
59
+ verilog: 'verilog', systemverilog: 'systemverilog',
60
+ lua: 'lua', java: 'java', jav: 'java', c: 'c', h: 'c', cpp: 'cpp', cc: 'cpp', cxx: 'cpp', hpp: 'cpp', hxx: 'cpp', hh: 'cpp',
61
+ cs: 'csharp', csx: 'csharp', cake: 'csharp', go: 'go', rs: 'rust', rlib: 'rust',
62
+ rb: 'ruby', rbx: 'ruby', rjs: 'ruby', gemspec: 'ruby',
63
+ php: 'php', php4: 'php', php5: 'php', phtml: 'php', ctp: 'php', sql: 'sql',
64
+ swift: 'swift', kt: 'kotlin', kts: 'kotlin', dart: 'dart', scala: 'scala', sc: 'scala', sbt: 'scala',
65
+ ftlh: 'freemarker2', ftlx: 'freemarker2',
37
66
  dockerfile: 'dockerfile', makefile: 'makefile', cmake: 'cmake',
38
67
  txt: 'plaintext', log: 'plaintext', gitignore: 'plaintext', lock: 'plaintext',
39
68
  }
@@ -43,6 +72,11 @@ export function languageOf(path) {
43
72
  if (/^dockerfile$/i.test(base)) return 'dockerfile'
44
73
  if (/^makefile$/i.test(base)) return 'makefile'
45
74
  if (/^\.?gitignore$/i.test(base) || /^\.?env/i.test(base)) return 'plaintext'
75
+ if (/\.blade\.php$/i.test(base)) return 'blade'
76
+ /* 以点开头的 JSON/INI/R 配置文件名(Monaco/json 默认支持这些) */
77
+ if (/^\.(?:babelrc|eslintrc|jshintrc|jscsrc|bowerrc)$/i.test(base)) return 'json'
78
+ if (/^\.gitconfig$/i.test(base)) return 'ini'
79
+ if (/^\.rprofile$/i.test(base)) return 'r'
46
80
  const dot = base.lastIndexOf('.')
47
81
  if (dot <= 0) return 'plaintext'
48
82
  return LANG_BY_EXT[base.slice(dot + 1).toLowerCase()] ?? 'plaintext'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.92",
3
+ "version": "1.3.94",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -112,6 +112,20 @@ try {
112
112
  const afterDelete = await call(router, 'fs.list', { root, path: 'src' })
113
113
  check('delete applied', !afterDelete.entries.some((entry) => entry.name === 'helper.ts'))
114
114
 
115
+ console.log('fs.languageOf (Monaco 语言映射)')
116
+ const languageCases = [
117
+ ['a.ejs', 'ejs'], ['a.eta', 'ejs'], ['a.erb', 'erb'], ['a.html.erb', 'erb'],
118
+ ['a.njk', 'jinja'], ['a.jinja2', 'jinja'], ['a.hbs', 'handlebars'], ['a.mustache', 'handlebars'],
119
+ ['a.pug', 'pug'], ['a.twig', 'twig'], ['a.liquid', 'liquid'], ['a.blade.php', 'blade'],
120
+ ['a.haml', 'haml'], ['a.slim', 'slim'], ['a.mdx', 'mdx'],
121
+ ['a.abap', 'abap'], ['a.cls', 'apex'], ['a.bat', 'bat'], ['a.clj', 'clojure'],
122
+ ['a.coffee', 'coffeescript'], ['a.graphql', 'graphql'], ['a.tf', 'hcl'], ['a.jl', 'julia'],
123
+ ['a.m', 'objective-c'], ['a.pas', 'pascal'], ['a.pl', 'perl'], ['a.proto', 'proto'],
124
+ ['a.r', 'r'], ['a.rst', 'restructuredtext'], ['a.sol', 'sol'], ['a.sv', 'systemverilog'],
125
+ ['a.tcl', 'tcl'], ['a.tsp', 'typespec'], ['a.vb', 'vb'], ['a.wgsl', 'wgsl'],
126
+ ['.babelrc', 'json'], ['.gitconfig', 'ini'],
127
+ ]
128
+ for (const [file, expected] of languageCases) check(`languageOf ${file} -> ${expected}`, fs.languageOf(file) === expected, fs.languageOf(file))
115
129
  console.log('fs.search')
116
130
  await call(router, 'fs.create', { root, path: 'search.txt', kind: 'file' })
117
131
  await call(router, 'fs.write', { root, path: 'search.txt', content: 'Alpha beta\nBETA gamma\nbeta BETA\n' })
@@ -0,0 +1,267 @@
1
+ /**
2
+ * 15-template-languages:补 Monaco 自带的 HTML 模板语法。
3
+ *
4
+ * Monaco 已内置 handlebars / twig / liquid / pug / razor / freemarker2;这里补上
5
+ * 市面上常用但 Monaco 没带的:EJS、Eta、ERB、Nunjucks/Jinja2(共用一套)、
6
+ * Blade、Haml、Slim。均为「HTML + 模板分隔符里的代码」的简化 Monarch 高亮,
7
+ * 不追求语法服务,只保证打开文件时有正常的颜色、注释和括号行为。
8
+ */
9
+ G.registerTemplateLanguages = function registerTemplateLanguages(monaco) {
10
+ if (monaco === null || monaco === undefined || !monaco.languages || G.__templateLanguagesRegistered === true) return
11
+ G.__templateLanguagesRegistered = true
12
+
13
+ const existing = (() => {
14
+ try {
15
+ const list = monaco.languages.getLanguages()
16
+ return new Set(Array.isArray(list) ? list.map((item) => item.id) : [])
17
+ } catch {
18
+ return new Set()
19
+ }
20
+ })()
21
+
22
+ const define = (id, extensions, aliases, tokenizer, configuration) => {
23
+ if (existing.has(id)) return
24
+ try {
25
+ monaco.languages.register({ id, extensions, aliases })
26
+ if (tokenizer !== null && tokenizer !== undefined) monaco.languages.setMonarchTokensProvider(id, tokenizer)
27
+ if (configuration !== null && configuration !== undefined) monaco.languages.setLanguageConfiguration(id, configuration)
28
+ existing.add(id)
29
+ } catch (error) {
30
+ /* 某个语言注册失败不影响其它语言 */
31
+ }
32
+ }
33
+
34
+ const htmlBase = () => ({
35
+ root: [
36
+ [/<!--/, 'comment', '@htmlComment'],
37
+ [/<[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
38
+ [/<\/[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
39
+ [/&[a-zA-Z#0-9]+;/, 'string.escape'],
40
+ [/[^<&]+/, ''],
41
+ ],
42
+ htmlComment: [
43
+ [/-->/, { token: 'comment', next: '@pop' }],
44
+ [/./, 'comment'],
45
+ ],
46
+ htmlTag: [
47
+ [/\s+/, ''],
48
+ [/[a-zA-Z_:][\w:.-]*/, 'attribute.name'],
49
+ [/=/, 'delimiter'],
50
+ [/"[^"]*"/, 'attribute.value'],
51
+ /* ' 不参与转义(Monarch 不需要) */
52
+ [/'[^']*'/, 'attribute.value'],
53
+ [/\/>/, { token: 'tag', next: '@pop' }],
54
+ [/>/, { token: 'tag', next: '@pop' }],
55
+ [/</, { token: 'tag', next: '@pop' }],
56
+ ],
57
+ })
58
+
59
+ const jsKeywords = 'if|else|for|while|do|switch|case|break|continue|function|return|var|let|const|new|typeof|instanceof|in|of|try|catch|finally|throw|class|extends|super|import|export|from|as|await|async|yield|this|true|false|null|undefined|delete|void|with|debugger'
60
+ const jinjaKeywords = 'if|else|elif|endif|for|endfor|block|endblock|extends|include|import|from|as|set|endset|macro|endmacro|filter|endfilter|with|endwith|raw|endraw|call|endcall|is|not|and|or|in|recursive|without|context|autoescape|endautoescape|trans|endtrans|do|loop|else'
61
+ const rubyKeywords = 'def|end|if|elsif|else|unless|case|when|while|until|for|do|begin|rescue|ensure|class|module|return|yield|break|next|redo|retry|super|self|nil|true|false|and|or|not|require|include|extend|attr_accessor|attr_reader|attr_writer|lambda|proc|puts|print|raise|new'
62
+ const bladeKeywords = 'if|elseif|else|endif|unless|endunless|foreach|endforeach|forelse|endforelse|for|endfor|while|endwhile|switch|endswitch|case|break|continue|extends|section|endsection|yield|include|each|push|stack|component|slot|php|endphp|auth|guest|env|production|error|csrf|method|json|checked|selected|disabled|readonly|required'
63
+
64
+ const codeTokens = (keywords, closePatterns) => {
65
+ const rules = []
66
+ for (const close of closePatterns) rules.push(close)
67
+ rules.push(
68
+ [/\/\/.*$/, 'comment'],
69
+ [/\/\*/, 'comment', '@blockComment'],
70
+ [/"[^"]*"/, 'string'],
71
+ [/'[^']*'/, 'string'],
72
+ [/`[^`]*`/, 'string'],
73
+ [new RegExp(`\\b(?:${keywords})\\b`), 'keyword'],
74
+ [/\b\d+(?:\.\d+)?\b/, 'number'],
75
+ [/[A-Za-z_$][\w$]*/, 'identifier'],
76
+ [/[{}()\[\]]/, '@brackets'],
77
+ [/[<>=!+\-*/%&|^~?:;,.]+/, 'operator'],
78
+ [/\s+/, ''],
79
+ )
80
+ return rules
81
+ }
82
+
83
+ const blockCommentState = [
84
+ [/\*\//, { token: 'comment', next: '@pop' }],
85
+ [/./, 'comment'],
86
+ ]
87
+
88
+ /* ── EJS / Eta:HTML + <% ... %> ───────────────────────────────────── */
89
+ define('ejs', ['.ejs', '.eta'], ['EJS', 'Eta'], (() => {
90
+ const base = htmlBase()
91
+ return {
92
+ defaultToken: '',
93
+ tokenizer: {
94
+ root: [
95
+ [/<!--/, 'comment', '@htmlComment'],
96
+ [/<%#/, 'comment', '@ejsComment'],
97
+ [/<%[-=]?/, { token: 'delimiter.template', next: '@ejsCode' }],
98
+ ...base.root.slice(1),
99
+ ],
100
+ htmlComment: base.htmlComment,
101
+ htmlTag: base.htmlTag,
102
+ ejsComment: [
103
+ [/%>/, { token: 'comment', next: '@pop' }],
104
+ [/./, 'comment'],
105
+ ],
106
+ ejsCode: codeTokens(jsKeywords, [[/%>/, { token: 'delimiter.template', next: '@pop' }]]),
107
+ blockComment: blockCommentState,
108
+ },
109
+ }
110
+ })(), {
111
+ comments: { blockComment: ['<!--', '-->'] },
112
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
113
+ autoClosingPairs: [
114
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
115
+ { open: '<%', close: '%>' }, { open: '<%=', close: '%>' },
116
+ { open: '"', close: '"' }, { open: "'", close: "'" },
117
+ ],
118
+ surroundingPairs: [{ open: '<%', close: '%>' }, { open: '"', close: '"' }, { open: "'", close: "'" }],
119
+ })
120
+
121
+ /* ── ERB:HTML + <% ... %>(Ruby 代码) ────────────────────────────── */
122
+ define('erb', ['.erb', '.rhtml', '.html.erb'], ['ERB'], (() => {
123
+ const base = htmlBase()
124
+ return {
125
+ defaultToken: '',
126
+ tokenizer: {
127
+ root: [
128
+ [/<!--/, 'comment', '@htmlComment'],
129
+ [/<%#/, 'comment', '@erbComment'],
130
+ [/<%[-=]?/, { token: 'delimiter.template', next: '@erbCode' }],
131
+ ...base.root.slice(1),
132
+ ],
133
+ htmlComment: base.htmlComment,
134
+ htmlTag: base.htmlTag,
135
+ erbComment: [
136
+ [/%>/, { token: 'comment', next: '@pop' }],
137
+ [/./, 'comment'],
138
+ ],
139
+ erbCode: codeTokens(rubyKeywords, [[/%>/, { token: 'delimiter.template', next: '@pop' }]]),
140
+ blockComment: blockCommentState,
141
+ },
142
+ }
143
+ })(), {
144
+ comments: { blockComment: ['<!--', '-->'] },
145
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
146
+ autoClosingPairs: [
147
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
148
+ { open: '<%', close: '%>' }, { open: '"', close: '"' }, { open: "'", close: "'" },
149
+ ],
150
+ })
151
+
152
+ /* ── Nunjucks / Jinja2:HTML + {{ }} / {% %} / {# #} ─────────────── */
153
+ define('jinja', ['.njk', '.nunjucks', '.jinja', '.jinja2', '.j2', '.j2.html'], ['Nunjucks', 'Jinja2'], {
154
+ defaultToken: '',
155
+ tokenizer: {
156
+ root: [
157
+ [/<!--/, 'comment', '@htmlComment'],
158
+ [/\{#/, 'comment', '@jinjaComment'],
159
+ [/\{\{/, { token: 'delimiter.template', next: '@jinjaExpr' }],
160
+ [/\{%/, { token: 'delimiter.template', next: '@jinjaStmt' }],
161
+ [/<[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
162
+ [/<\/[a-zA-Z][\w:-]*/, { token: 'tag', next: '@htmlTag' }],
163
+ [/&[a-zA-Z#0-9]+;/, 'string.escape'],
164
+ [/[^<{&]+/, ''],
165
+ ],
166
+ htmlComment: [[/-->/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
167
+ htmlTag: htmlBase().htmlTag,
168
+ jinjaComment: [[/#\}/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
169
+ jinjaExpr: codeTokens(jinjaKeywords, [
170
+ [/\}\}/, { token: 'delimiter.template', next: '@pop' }],
171
+ [/\|/, 'operator'],
172
+ ]),
173
+ jinjaStmt: codeTokens(jinjaKeywords, [
174
+ [/%\}/, { token: 'delimiter.template', next: '@pop' }],
175
+ [/\|/, 'operator'],
176
+ ]),
177
+ blockComment: blockCommentState,
178
+ },
179
+ }, {
180
+ comments: { blockComment: ['<!--', '-->'] },
181
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
182
+ autoClosingPairs: [
183
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
184
+ { open: '{{', close: '}}' }, { open: '{%', close: '%}' }, { open: '{#', close: '#}' },
185
+ { open: '"', close: '"' }, { open: "'", close: "'" },
186
+ ],
187
+ })
188
+
189
+ /* ── Blade:HTML + {{ }} / {!! !!} / {{-- --}} / @directive ─────── */
190
+ define('blade', ['.blade.php'], ['Blade'], (() => {
191
+ const base = htmlBase()
192
+ return {
193
+ defaultToken: '',
194
+ tokenizer: {
195
+ root: [
196
+ [/\{\{--/, 'comment', '@bladeComment'],
197
+ [/\{!!/, { token: 'delimiter.template', next: '@bladeExpr' }],
198
+ [/\{\{/, { token: 'delimiter.template', next: '@bladeExpr' }],
199
+ [/@[a-zA-Z_][\w-]*/, 'keyword.directive'],
200
+ ...base.root,
201
+ ],
202
+ htmlComment: base.htmlComment,
203
+ htmlTag: base.htmlTag,
204
+ bladeComment: [[/--\}\}/, { token: 'comment', next: '@pop' }], [/./, 'comment']],
205
+ bladeExpr: codeTokens(bladeKeywords, [
206
+ [/\}\}/, { token: 'delimiter.template', next: '@pop' }],
207
+ [/!!\}/, { token: 'delimiter.template', next: '@pop' }],
208
+ ]),
209
+ blockComment: blockCommentState,
210
+ },
211
+ }
212
+ })(), {
213
+ comments: { blockComment: ['{{--', '--}}'] },
214
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
215
+ autoClosingPairs: [
216
+ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' },
217
+ { open: '{{', close: '}}' }, { open: '{{--', close: '--}}' },
218
+ { open: '"', close: '"' }, { open: "'", close: "'" },
219
+ ],
220
+ })
221
+
222
+ /* ── Haml:缩进 + %tag / .class / #id / = / - ──────────────────── */
223
+ define('haml', ['.haml'], ['Haml'], {
224
+ defaultToken: '',
225
+ tokenizer: {
226
+ root: [
227
+ [/^\s*!!!.*$/, 'meta'],
228
+ [/^\s*\/.*$/, 'comment'],
229
+ [/^\s*%[a-zA-Z][\w:-]*/, 'tag'],
230
+ [/[.#][\w-]+/, 'attribute.name'],
231
+ [/^\s*[-=]/, 'operator'],
232
+ [/\{.*?\}/, 'string.interpolated'],
233
+ [/"[^"]*"/, 'string'],
234
+ [/'[^']*'/, 'string'],
235
+ [/[A-Za-z_][\w-]*:/, 'attribute.name'],
236
+ [/[^\n]+/, ''],
237
+ [/\n/, ''],
238
+ ],
239
+ },
240
+ }, {
241
+ comments: { lineComment: '/' },
242
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
243
+ })
244
+
245
+ /* ── Slim:缩进 + tag / = / - / | ──────────────────────────────── */
246
+ define('slim', ['.slim'], ['Slim'], {
247
+ defaultToken: '',
248
+ tokenizer: {
249
+ root: [
250
+ [/^\s*(doctype)\b/, 'keyword'],
251
+ [/^\s*\/.*$/, 'comment'],
252
+ [/^\s*[-=]/, 'operator'],
253
+ [/^\s*\|/, 'string'],
254
+ [/^[\s]*[a-zA-Z][\w-]*/, 'tag'],
255
+ [/[.#][\w-]+/, 'attribute.name'],
256
+ [/[a-zA-Z_][\w-]*=/, 'attribute.name'],
257
+ [/"[^"]*"/, 'string'],
258
+ [/'[^']*'/, 'string'],
259
+ [/[^\n]+/, ''],
260
+ [/\n/, ''],
261
+ ],
262
+ },
263
+ }, {
264
+ comments: { lineComment: '/' },
265
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
266
+ })
267
+ }
@@ -723,6 +723,11 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
723
723
  gufaLoadMonaco()
724
724
  .then((monaco) => {
725
725
  if (cancelled) return
726
+ try {
727
+ if (typeof G.registerTemplateLanguages === 'function') G.registerTemplateLanguages(monaco)
728
+ } catch (error) {
729
+ /* 模板语言注册失败不影响编辑器 */
730
+ }
726
731
  try {
727
732
  const instance = monaco.editor.create(host, gufaEditorOptions(propsRef.current.theme))
728
733
  editor = instance