✨ feat(vscode): 代码阅读的调用与构造:跨多行写的调用排成「新建 / 调用 名字 · N 个参数」一行,实参摊成参数 / 值表;Python 查被调用名字的定义分新建和调用,查到后刷新

This commit is contained in:
cruldra committed 2026-09-27 22:08:16 +08:00
1 parent ebf228cdc7
commit ecc415d763
30 files changed
+1033 -157

No files matched your search

+20 -1
View File
@@ -1,8 +1,10 @@
import type { Location, LocationLink, Position } from 'vscode'
import type { RuleLocation } from '../contract'
import type { BlockKind, LanguageAdapter, RuleLocation } from '../contract'
import type { TreeSitterRuntime } from '../runtime'
import type { DefinitionTarget } from './definitionAction'
import { commands, Range, Uri, window, workspace } from 'vscode'
import { logger } from '../../logging/logger'
import { readDefinitionKind } from '../blockView'
/** 查到的一处定义:文件和定义处那个名字的范围。 */
export interface FoundLocation { uri: Uri, range: Range }
@@ -36,6 +38,23 @@ export function ruleDefinitions(locations: readonly RuleLocation[]): FoundLocati
return locations.map(({ uri, start, end }) => ({ uri: Uri.parse(uri), range: new Range(start.line, start.character, end.line, end.character) }))
}
/** 定义处那个名字定义的是哪种块:打开目标文件,用它那种语言的语言插件分块认;目标打不开、语言不支持、不在哪块的名字上时没有。 */
export async function definitionKind(
location: FoundLocation,
languageFor: (languageId: string) => LanguageAdapter | undefined,
runtime: Pick<TreeSitterRuntime, 'parse'>,
): Promise<BlockKind | undefined> {
try {
const document = await workspace.openTextDocument(location.uri)
const adapter = languageFor(document.languageId)
return adapter && await readDefinitionKind(runtime, adapter, document.languageId, document.getText(), document.offsetAt(location.range.start))
}
catch (err) {
logger.add({ level: 'warn', source: 'codeReader', message: `认不出 ${location.uri.toString()} 里定义的是哪种块:${err instanceof Error ? err.message : String(err)}` })
return undefined
}
}
/** 查到的各处定义打开目标文件补上行文字、下标;目标打不开成文本的(例如 Python 命名空间包指向的目录)略过。 */
export async function findDefinitions(locations: readonly FoundLocation[], supports: (languageId: string) => boolean): Promise<Definition[]> {
const found = await Promise.all(locations.map(async (location): Promise<Definition[]> => {