✨ feat(vscode): 代码阅读的函数和类可以看调用树

This commit is contained in:
cruldra committed 2026-10-11 00:37:24 -04:00
1 parent 8dc572bf94
commit 645542eb5c
17 files changed
+1679 -5

No files matched your search

@@ -23,6 +23,8 @@ import { commands, EndOfLine, Position, Range, Uri, window, workspace, Workspace
import { logger } from '../../logging/logger'
import { webviewHtml, webviewUiRoot } from '../../webview/html'
import { DocumentCallees } from '../calleeKinds'
import { loadCallEdges } from '../callTree/query'
import { CallTreeSession } from '../callTree/session'
import { findBlock, rewriteBlockComment } from '../commentRewrite'
import { PreviewDiff } from '../diff/previewDiff'
import { blockReplacement } from '../editText'
@@ -187,6 +189,20 @@ class Preview {
private readonly rewriteStops = new Map<string, AbortController>()
/** 最近一次发出去的文档(版本、块树、源码):问 AI 时按块的记号在里面找那块代码,对比基准变了时拿它重新比 */
private sent: SentDocument | undefined
/** 函数、类落在几棵调用树里。文档发出去之后再数,不挡住第一次预览 */
private readonly callTrees = new CallTreeSession(
message => this.post(message),
() => {
if (!this.sent || this.sent.version !== this.document.version)
return undefined
return {
version: this.sent.version,
blocks: this.sent.blocks,
load: (offset, cancelled) => loadCallEdges(this.document, offset, cancelled),
}
},
)
/** 最近一次发出去的文档里语言插件自己认得出的名字(LanguageAdapter.symbols):语言扩展查不到定义、各处出现时用 */
private symbols: { version: number, list: LocalSymbol[] } | undefined
/** 最近一次发出去的文档里各条导入引进来的名字:注释里不带路径的引用按它找导入的定义 */
@@ -318,6 +334,7 @@ class Preview {
if (!this.ready)
return
const request = ++this.latest
this.callTrees.cancel()
if (pathPreviewOf(this.document.uri)) {
this.sent = undefined
const reveal = this.pendingReveal
@@ -359,6 +376,7 @@ class Preview {
this.names.resolve(version, report => resolveNames(displayNames, message.blocks, this.nameSources(), report))
this.lookups.resolve(version, session.requests(), this.lookupSources())
this.callees.resolve(version, callees.requests(), offset => this.calleeKind(offset))
this.callTrees.refresh()
}
}
@@ -455,6 +473,7 @@ class Preview {
}
dispose(): void {
this.callTrees.dispose()
this.rewriteAbort.abort()
clearTimeout(this.timer)
this.names.dispose()
@@ -608,6 +627,9 @@ class Preview {
case 'checkRepoImages':
await this.checkRepoImages(msg.id, msg.paths)
return
case 'openCallTree':
this.callTrees.open(msg.version, msg.anchor)
return
case 'occurrenceNavigation':
this.owner.navigation.update(this, msg.available)
}