✨ feat(vscode): 代码阅读契约加命令规则(按命令名注册、读一条命令)、按位置的参数 / 输出 / 返回、解释器和选项块、分情况 / 命令 / 管道种类、常量色;模板引擎加节点读法;没有定义、高亮提供者的语言用语言插件认的同一文件里的名字跳转、高亮

This commit is contained in:
cruldra committed 2026-09-28 00:44:46 +08:00
1 parent cf09c24730
commit ff2a44f080
17 files changed
+555 -60

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import type { CommandRule } from './contract'
/** 规则读命令时出错:记下,当它没读(命令照抄)。 */
function guarded(rule: CommandRule, report: (message: string) => void): CommandRule {
return {
...rule,
read: (command, context) => {
try {
return rule.read(command, context)
}
catch (err) {
report(`命令规则 ${rule.id} 读「${command.name.node.text}」时出错,照抄命令:${err instanceof Error ? err.message : String(err)}`)
return undefined
}
},
}
}
/** 命令名 → 命令规则(SourceDocument.commandRule):几条规则都管同一个名字时先注册的算。 */
export function commandRuleLookup(rules: readonly CommandRule[], report: (message: string) => void): (name: string) => CommandRule | undefined {
const byName = new Map<string, CommandRule>()
for (const rule of rules) {
const safe = guarded(rule, report)
for (const name of rule.commands) {
if (!byName.has(name))
byName.set(name, safe)
}
}
return name => byName.get(name)
}