✨ feat(vscode): 代码阅读预览单击名字高亮它在文件里的各处出现

This commit is contained in:
cruldra committed 2026-09-26 15:51:52 +08:00
1 parent 5872cf7958
commit 9c0f05362c
12 files changed
+558 -9

No files matched your search

@@ -11,6 +11,7 @@ import { blockReplacement } from '../editText'
import { definitionAction } from './definitionAction'
import { findDefinitions, hasDefinition, pickDefinition } from './definitions'
import { documentMessage } from './documentMessage'
import { occurrencesOf } from './occurrences'
export const PREVIEW_VIEW_TYPE = 'superpowers.codeReader.preview'
@@ -197,9 +198,22 @@ class Preview {
return
case 'goToDefinition':
await this.goToDefinition(msg.version, msg.offset)
return
case 'findOccurrences':
await this.findOccurrences(msg.id, msg.version, msg.offset)
}
}
/** 回答 webview 第 id 次询问:offset 处的名字在这份文档里出现在哪几处。下标属于别的文档版本时不答,webview 换了文档版本会清掉高亮 */
private async findOccurrences(id: number, version: number, offset: number): Promise<void> {
const { document } = this
if (version !== document.version)
return
const occurrences = await occurrencesOf(document, offset)
if (version === document.version && this.ready)
this.post({ type: 'occurrencesFound', id, occurrences })
}
/** 回答 webview 第 id 次询问:offset 处的名字有没有定义。下标属于别的文档版本时不答,webview 收到新文档后会重新问 */
private async probeDefinition(id: number, version: number, offset: number): Promise<void> {
const { document } = this