dsh-gufa-code 1.3.91 → 1.3.93
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 +1 -0
- package/client.js +286 -2
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +8 -0
- package/host/fs.js +9 -1
- package/package.json +1 -1
- package/src/client/15-template-languages.js +267 -0
- package/src/client/20-editor.js +5 -0
- package/src/client/58b-drag-ref.js +10 -1
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ dsh plugin add dsh-gufa-code
|
|
|
39
39
|
### 编辑器
|
|
40
40
|
|
|
41
41
|
- Monaco 编辑器(离线随包分发,无需联网下载);
|
|
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.
|
|
19
|
+
G.BUILD = '1.3.93'
|
|
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
|
|
@@ -9793,7 +10068,16 @@ function activeSessionId() {
|
|
|
9793
10068
|
const text = model.getValueInRange(selection);
|
|
9794
10069
|
if (!text) return null;
|
|
9795
10070
|
const rawPath = model.uri && model.uri.path ? String(model.uri.path) : "";
|
|
9796
|
-
const
|
|
10071
|
+
const absolute = decodeURIComponent(rawPath.replace(/^\//, ""));
|
|
10072
|
+
if (absolute === "") return null;
|
|
10073
|
+
/* gufa 的 model URI 是项目绝对路径;引用 chip 需要项目相对路径 */
|
|
10074
|
+
let path = absolute;
|
|
10075
|
+
try {
|
|
10076
|
+
const root = typeof G.projectRoot === "string" ? String(G.projectRoot).replace(/\/+$/, "") : "";
|
|
10077
|
+
const rootNoSlash = root.replace(/^\//, "");
|
|
10078
|
+
if (root !== "" && absolute.startsWith(root + "/")) path = absolute.slice(root.length + 1);
|
|
10079
|
+
else if (rootNoSlash !== "" && absolute.startsWith(rootNoSlash + "/")) path = absolute.slice(rootNoSlash.length + 1);
|
|
10080
|
+
} catch (_) {}
|
|
9797
10081
|
if (path === "") return null;
|
|
9798
10082
|
const startLine = Math.min(selection.startLineNumber, selection.endLineNumber);
|
|
9799
10083
|
const endLine = Math.max(selection.startLineNumber, selection.endLineNumber);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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.
|
|
11
|
-
<key>CFBundleVersion</key><string>1.3.
|
|
10
|
+
<key>CFBundleShortVersionString</key><string>1.3.93</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.93</string>
|
|
12
12
|
<key>LSUIElement</key><true/>
|
|
13
13
|
<key>NSHighResolutionCapable</key><true/>
|
|
14
14
|
<key>NSPrincipalClass</key><string>NSApplication</string>
|
|
Binary file
|
package/docs/KNOWN-PITFALLS.md
CHANGED
|
@@ -37,6 +37,14 @@
|
|
|
37
37
|
- 成功复制/插入/拖动/跳转一律不弹 toast(用户明确讨厌成功提示),只有失败才提示;toast 复用 `G.refToast`。
|
|
38
38
|
- 古法 IDE 内点击引用 chip:优先 `G.bus.emit('editor:open-at')` 打开自己的 Monaco 标签,再 `selectRange` 选中行范围;不要依赖 DSH 侧边栏资源路由。
|
|
39
39
|
- 行范围引用格式 `@path Lx-Ly`;chip 标签里存路径+行号用于点击定位,`localStorage` key 使用 `gufa-code.refs.v1`。
|
|
40
|
+
- **model URI 是项目绝对路径,引用 chip 必须转成项目相对路径**(`G.projectRoot` 前缀剥离),否则点击 chip 会走 `fs.read` 绝对路径并报「路径不存在」;这个坑 1.3.92 已修。
|
|
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` 状态里 `/>` 要在 `>` 之前。
|
|
40
48
|
|
|
41
49
|
## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
|
|
42
50
|
|
package/host/fs.js
CHANGED
|
@@ -26,7 +26,14 @@ export const LANG_BY_EXT = {
|
|
|
26
26
|
json: 'json', jsonc: 'json', json5: 'json',
|
|
27
27
|
md: 'markdown', markdown: 'markdown', mdx: '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
|
+
ejs: 'ejs', eta: 'ejs',
|
|
31
|
+
hbs: 'handlebars', handlebars: 'handlebars', mustache: 'handlebars',
|
|
32
|
+
pug: 'pug', jade: 'pug',
|
|
33
|
+
njk: 'jinja', nunjucks: 'jinja', jinja: 'jinja', jinja2: 'jinja', j2: 'jinja',
|
|
34
|
+
liquid: 'liquid', twig: 'twig', ftl: 'freemarker2', razor: 'razor', cshtml: 'razor',
|
|
35
|
+
erb: 'erb', rhtml: 'erb',
|
|
36
|
+
haml: 'haml', slim: 'slim',
|
|
30
37
|
xml: 'xml', svg: 'xml', plist: 'xml', csproj: 'xml',
|
|
31
38
|
yaml: 'yaml', yml: 'yaml', toml: 'ini', ini: 'ini', cfg: 'ini', conf: 'ini', properties: 'ini', env: 'ini',
|
|
32
39
|
py: 'python', pyw: 'python',
|
|
@@ -43,6 +50,7 @@ export function languageOf(path) {
|
|
|
43
50
|
if (/^dockerfile$/i.test(base)) return 'dockerfile'
|
|
44
51
|
if (/^makefile$/i.test(base)) return 'makefile'
|
|
45
52
|
if (/^\.?gitignore$/i.test(base) || /^\.?env/i.test(base)) return 'plaintext'
|
|
53
|
+
if (/\.blade\.php$/i.test(base)) return 'blade'
|
|
46
54
|
const dot = base.lastIndexOf('.')
|
|
47
55
|
if (dot <= 0) return 'plaintext'
|
|
48
56
|
return LANG_BY_EXT[base.slice(dot + 1).toLowerCase()] ?? 'plaintext'
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/src/client/20-editor.js
CHANGED
|
@@ -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
|
|
@@ -215,7 +215,16 @@ function activeSessionId() {
|
|
|
215
215
|
const text = model.getValueInRange(selection);
|
|
216
216
|
if (!text) return null;
|
|
217
217
|
const rawPath = model.uri && model.uri.path ? String(model.uri.path) : "";
|
|
218
|
-
const
|
|
218
|
+
const absolute = decodeURIComponent(rawPath.replace(/^\//, ""));
|
|
219
|
+
if (absolute === "") return null;
|
|
220
|
+
/* gufa 的 model URI 是项目绝对路径;引用 chip 需要项目相对路径 */
|
|
221
|
+
let path = absolute;
|
|
222
|
+
try {
|
|
223
|
+
const root = typeof G.projectRoot === "string" ? String(G.projectRoot).replace(/\/+$/, "") : "";
|
|
224
|
+
const rootNoSlash = root.replace(/^\//, "");
|
|
225
|
+
if (root !== "" && absolute.startsWith(root + "/")) path = absolute.slice(root.length + 1);
|
|
226
|
+
else if (rootNoSlash !== "" && absolute.startsWith(rootNoSlash + "/")) path = absolute.slice(rootNoSlash.length + 1);
|
|
227
|
+
} catch (_) {}
|
|
219
228
|
if (path === "") return null;
|
|
220
229
|
const startLine = Math.min(selection.startLineNumber, selection.endLineNumber);
|
|
221
230
|
const endLine = Math.max(selection.startLineNumber, selection.endLineNumber);
|