✨ feat(vscode): 代码阅读注释里不带路径的引用 [Name] 能点,本文件定义的优先、再找导入的
This commit is contained in:
1 parent
0958506681
commit
300d8a07b9
16 files changed
+600
-124
No files matched your search
@@ -1,12 +1,14 @@
|
||||
import type { Tree } from '@vscode/tree-sitter-wasm'
|
||||
import type { BlockAttributes, BlockConcept, BlockKind, CodeBlock, DisplayName, EmbeddedCode, EmbeddedReading, Inline, KindBadge, LanguageAdapter, LibraryRule, LocalSymbol, Markdown, Node, PreviewTable, PreviewText, PropertyRow, RuleCard, RuleContext, Segment, SourceDocument, SourceRange, SourceSpan, StepBlocks, TextBlock, TokenRole, Translator } from './contract'
|
||||
import type { TreeSitterRuntime } from './runtime'
|
||||
import type { ImportedName } from './symbolLinks'
|
||||
import { blockAttributes } from './attributes'
|
||||
import { KIND_ICONS } from './contract'
|
||||
import { commonIndent, splitLines } from './editText'
|
||||
import { commentSpan } from './languages/shared'
|
||||
import { activeRules, claimBlock, importsIn } from './libraryRules'
|
||||
import { BlockAnchors } from './qa/anchor'
|
||||
import { importedNames } from './symbolLinks'
|
||||
|
||||
interface BlockViewBase {
|
||||
/** 在树里的位置,例如 '6.1.0'。 */
|
||||
@@ -415,12 +417,14 @@ export function toBlockViews(
|
||||
|
||||
/**
|
||||
* 一份源码的视图数据,和它里面起了中文名的定义(预览找用到它们的各处要用,见 displayNames.ts)、
|
||||
* 语言插件自己认得出的名字(LanguageAdapter.symbols,语言扩展查不到定义、各处出现时用)。
|
||||
* 语言插件自己认得出的名字(LanguageAdapter.symbols,语言扩展查不到定义、各处出现时用)、
|
||||
* 各条导入引进来的名字(注释里不带路径的引用按它找导入的定义,见 symbolLinks.ts)。
|
||||
*/
|
||||
export interface DocumentViews {
|
||||
blocks: BlockView[]
|
||||
displayNames: DisplayName[]
|
||||
symbols: LocalSymbol[]
|
||||
imports: ImportedName[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,12 +491,13 @@ export async function readBlockViews(
|
||||
...(commandRule && { commandRule }),
|
||||
...(parts.size > 0 && { embedded }),
|
||||
}
|
||||
const blocks = toBlockViews(adapter.toBlocks(tree.rootNode, source, languageId), document, translator, extras.rules, parts)
|
||||
const codeBlocks = adapter.toBlocks(tree.rootNode, source, languageId)
|
||||
const blocks = toBlockViews(codeBlocks, document, translator, extras.rules, parts)
|
||||
const symbols = [
|
||||
...adapter.symbols?.(tree.rootNode, source, languageId) ?? [],
|
||||
...[...parts.values()].flatMap(part => part.document.language.symbols?.(part.root, source, part.code.languageId) ?? []),
|
||||
]
|
||||
return { blocks, displayNames: names, symbols }
|
||||
return { blocks, displayNames: names, symbols, imports: importedNames(importsIn(codeBlocks)) }
|
||||
}
|
||||
finally {
|
||||
for (const parsed of trees)
|
||||
|
||||
Reference in new issue
Block a user