✨ feat(vscode): 代码阅读预览顶部加块筛选栏
语言插件按和语言无关的 id 报块属性(通用的由宿主从 facts 推),翻译插件起名,webview 只按 id 筛; 筛选整个工作区共用、记在 workspaceState;JavaScript 不再显示「抽象:否」「仅类型:否」
This commit is contained in:
1 parent
4eaf2ae11d
commit
1c7e31c51a
29 files changed
+1364
-319
No files matched your search
@@ -36,7 +36,8 @@ export interface FunctionFacts {
|
||||
doc?: Node
|
||||
/** 嵌套在函数体、条件等语句块里的函数没有。 */
|
||||
access?: Access
|
||||
async: boolean
|
||||
/** 异步函数;没有这个概念的语言不填。 */
|
||||
async?: boolean
|
||||
decorators: Node[]
|
||||
parameters: ParameterFacts[]
|
||||
returnType?: Node
|
||||
@@ -107,6 +108,21 @@ export interface VariableFacts {
|
||||
declarators: DeclaratorFacts[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选属性的通用词表,筛选栏按这个顺序排,语言自己的属性排在后面:
|
||||
* - kind:块的种类(BlockKind);
|
||||
* - access:访问级别,'public' | 'private' | 'protected',语言可以加自己的值(Kotlin 的 'internal',见 BlockShape.attributes);
|
||||
* - async、abstract、typeOnly:异步、抽象、仅类型,值是 'true' | 'false'。
|
||||
* 宿主从块的 kind 和 facts 推出它们(FunctionFacts.access / async、ClassFacts.access / abstract、ImportFacts.typeOnly、VariableFacts.access),
|
||||
* 语言插件不用另报;facts 里没填的(语言没有这个概念、块没有这一项),块就没有这个属性,也不受这个属性的筛选影响。
|
||||
*/
|
||||
export const COMMON_ATTRIBUTES = ['kind', 'access', 'async', 'abstract', 'typeOnly'] as const
|
||||
|
||||
export type CommonAttribute = (typeof COMMON_ATTRIBUTES)[number]
|
||||
|
||||
/** 块的筛选属性:属性 id → 值 id,都是稳定的英文 id,不放显示文字(显示名由翻译插件给,见 AttributeNames)。 */
|
||||
export type BlockAttributes = Record<string, string>
|
||||
|
||||
export interface BlockShape {
|
||||
/** 这一块对应的语法树节点(整条语句)。 */
|
||||
node: Node
|
||||
@@ -116,6 +132,11 @@ export interface BlockShape {
|
||||
*/
|
||||
header: SourceSpan
|
||||
children: CodeBlock[]
|
||||
/**
|
||||
* 语言自己报的筛选属性,和宿主推出的通用属性(见 COMMON_ATTRIBUTES)合在一起:通用词表以外的属性(Rust 的 unsafe: 'true'),
|
||||
* 或 facts 表达不了的通用属性值(Kotlin 的 access: 'internal',盖过从 facts 推出的)。kind 总是块的种类,这里填了不算。
|
||||
*/
|
||||
attributes?: BlockAttributes
|
||||
}
|
||||
|
||||
/** 预览成属性表的块:语言插件从语法树读出结构化信息(facts),翻译插件把它排成属性表。 */
|
||||
@@ -185,11 +206,20 @@ export interface LanguageAdapter {
|
||||
languageIds: string[]
|
||||
/** 该 languageId 用的语法包 .wasm 的绝对路径(宿主负责加载,保证和解析器运行时是同一份)。 */
|
||||
grammarPath: (languageId: string) => string
|
||||
toBlocks: (root: Node, source: string) => CodeBlock[]
|
||||
/** languageId 是这份源码的 languageId:一个插件覆盖几种方言时按它区分(JavaScript 没有 TypeScript 的抽象类、仅类型导入)。 */
|
||||
toBlocks: (root: Node, source: string, languageId: string) => CodeBlock[]
|
||||
/** 源码着色:给语法树叶子节点定词性。 */
|
||||
tokenRole: (leaf: Node) => TokenRole
|
||||
}
|
||||
|
||||
/** 筛选属性和值的显示名,筛选栏、种类标签用它;没给名字的显示 id。 */
|
||||
export interface AttributeNames {
|
||||
/** 属性 id → 属性名,例如 access → 访问级别。 */
|
||||
attributes: Record<string, string>
|
||||
/** 属性 id → 值 id → 值名,例如 access → public → 公共、async → true → 是、kind → function → 函数。 */
|
||||
values: Record<string, Record<string, string>>
|
||||
}
|
||||
|
||||
/** 翻译插件:代码块 → 一行译文或属性表。 */
|
||||
export interface Translator {
|
||||
id: string // 'typescript.zh-template'
|
||||
@@ -199,6 +229,8 @@ export interface Translator {
|
||||
translate: (block: TextBlock, source: string) => PreviewText
|
||||
/** 函数、类、导入、常量、变量块 → 属性表。 */
|
||||
describe: (block: FactBlock, source: string) => PropertyRow[]
|
||||
/** 筛选属性和值叫什么,和属性表里的属性名、值用同一套叫法;不给就都显示 id。 */
|
||||
attributeNames?: AttributeNames
|
||||
}
|
||||
|
||||
export interface CodeReaderApi {
|
||||
|
||||
Reference in new issue
Block a user