✨ feat(vscode): 代码阅读加 Celery 库规则,定时任务表里的任务名能跳到任务函数

This commit is contained in:
cruldra committed 2026-09-26 19:41:07 +08:00
1 parent 905d7845b5
commit 68104e2cba
22 files changed
+2228 -139

No files matched your search

+15 -4
View File
@@ -1,15 +1,17 @@
import type { CustomTextEditorProvider, Disposable, TextDocument, TextDocumentShowOptions, Uri, WebviewPanel } from 'vscode'
import type { RuleLocation, RuleReference } from '../contract'
import type { CodeReaderRegistry } from '../registry'
import type { TreeSitterRuntime } from '../runtime'
import type { BlockFilter } from './blockFilter'
import type { Definition } from './definitions'
import type { Definition, FoundLocation } from './definitions'
import type { ExtensionToWebview, Reveal, WebviewToExtension } from './messages'
import { commands, Range, window, workspace, WorkspaceEdit } from 'vscode'
import { logger } from '../../logging/logger'
import { webviewHtml, webviewUiRoot } from '../../webview/html'
import { blockReplacement } from '../editText'
import { definitionAction } from './definitionAction'
import { findDefinitions, hasDefinition, pickDefinition } from './definitions'
import { findDefinitions, languageDefinitions, pickDefinition, ruleDefinitions } from './definitions'
import { DefinitionSources } from './definitionSources'
import { documentMessage } from './documentMessage'
import { occurrencesOf } from './occurrences'
@@ -32,6 +34,8 @@ export class PreviewEditorProvider implements CustomTextEditorProvider {
private readonly registry: CodeReaderRegistry,
private readonly runtime: TreeSitterRuntime,
private readonly filter: BlockFilter,
/** 库规则标的引用去哪儿查定义(交给标它的规则) */
readonly resolveReference: (reference: RuleReference) => Promise<RuleLocation[]>,
) {}
resolveCustomTextEditor(document: TextDocument, panel: WebviewPanel): void {
@@ -90,6 +94,8 @@ class Preview {
private latest = 0
private timer: NodeJS.Timeout | undefined
private readonly disposables: Disposable[]
/** 名字的定义去哪儿查:库规则标了引用的问规则,其余问语言扩展 */
private readonly definitions: DefinitionSources<FoundLocation>
/** webview 报来的视口顶部那块的起始行 */
visibleLine: number | undefined
@@ -106,6 +112,10 @@ class Preview {
*/
private pendingReveal: Reveal | undefined,
) {
this.definitions = new DefinitionSources({
rule: async reference => ruleDefinitions(await owner.resolveReference(reference)),
language: offset => languageDefinitions(document.uri, document.positionAt(offset)),
})
this.disposables = [
panel.webview.onDidReceiveMessage((msg: WebviewToExtension) => this.handleMessage(msg)),
panel.onDidChangeViewState(() => {
@@ -146,6 +156,7 @@ class Preview {
})
if (request !== this.latest || !this.ready)
return
this.definitions.remember(message.version, message.blocks)
const reveal = this.pendingReveal
this.pendingReveal = undefined
this.post(reveal === undefined ? message : { ...message, reveal })
@@ -221,7 +232,7 @@ class Preview {
const { document } = this
if (version !== document.version)
return
const found = await hasDefinition(document.uri, document.positionAt(offset))
const found = (await this.definitions.locate(version, offset)).length > 0
if (version === document.version && this.ready)
this.post({ type: 'definitionProbed', id, found })
}
@@ -233,7 +244,7 @@ class Preview {
return
const current = document.uri.toString()
const supports = (languageId: string): boolean => this.registry.languageFor(languageId) !== undefined
let action = definitionAction(await findDefinitions(document.uri, document.positionAt(offset), supports), current)
let action = definitionAction(await findDefinitions(await this.definitions.locate(version, offset), supports), current)
if (action.kind === 'pick') {
const picked = await pickDefinition(action.targets)
action = definitionAction(picked ? [picked] : [], current)