✨ feat(vscode): 代码阅读契约加命令规则(按命令名注册、读一条命令)、按位置的参数 / 输出 / 返回、解释器和选项块、分情况 / 命令 / 管道种类、常量色;模板引擎加节点读法;没有定义、高亮提供者的语言用语言插件认的同一文件里的名字跳转、高亮
This commit is contained in:
1 parent
cf09c24730
commit
ff2a44f080
17 files changed
+555
-60
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { LocalSymbol, SourceRange } from './contract'
|
||||
|
||||
/**
|
||||
* 语言插件自己认得出的名字(LanguageAdapter.symbols)怎么用:VS Code 里没有这种语言的定义、高亮提供者时(shell),
|
||||
* 宿主拿它跳到定义、高亮各处出现。这里不碰 VS Code。
|
||||
*/
|
||||
|
||||
/** 盖住 offset 的那个名字。 */
|
||||
export function symbolAt(symbols: readonly LocalSymbol[], offset: number): LocalSymbol | undefined {
|
||||
return symbols.find(symbol => symbol.occurrences.some(range => range.startIndex <= offset && offset < range.endIndex))
|
||||
}
|
||||
|
||||
/** offset 处用到的名字跳到哪个定义:它之前最近的一处(同名的变量前后赋过几次值),前面没有就是第一处。 */
|
||||
export function definitionFor(symbol: LocalSymbol, offset: number): SourceRange | undefined {
|
||||
return symbol.definitions.filter(range => range.startIndex <= offset).at(-1) ?? symbol.definitions[0]
|
||||
}
|
||||
|
||||
/** 名字的各处出现:定义处算写,别处算读。 */
|
||||
export function symbolOccurrences(symbol: LocalSymbol): { start: number, end: number, kind: 'read' | 'write' }[] {
|
||||
return symbol.occurrences.map(({ startIndex, endIndex }) => ({
|
||||
start: startIndex,
|
||||
end: endIndex,
|
||||
kind: symbol.definitions.some(range => range.startIndex === startIndex) ? 'write' : 'read',
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user