✨ feat(vscode): 代码阅读的 TypeScript interface 换成一张属性表卡片

契约加 InterfaceBlock / InterfaceFacts(种类「接口」,图标、颜色同类型块);属性签名和索引签名连同讲它的注释并进「属性 | 类型 | 说明」表,可省略带 ?、只读写在类型前、没标注写未标注,每行讲的定义是属性名;方法签名是函数子块,调用签名、构造签名照旧是子块;declare interface 也认;「了解一块代码」照旧按 接口名.属性名 找得到属性
This commit is contained in:
cruldra committed 2026-10-16 14:27:28 +11:00
1 parent f487b841ce
commit 6b1e6f3487
16 files changed
+334 -46

No files matched your search

+42 -4
View File
@@ -10,9 +10,10 @@ export type { Node }
* run 构建时执行的命令,copy 往镜像里复制文件,setting 一条设置(工作目录、运行身份、端口……),label 镜像的标签,
* health 健康检查,start 容器启动时执行的命令。
* comment 是讲整个文件的注释(文件开头的说明);别的注释不单独成块,挂在它讲的块上(见 BlockShape.comments)。
* interface 是 TypeScript 的接口(属性表),type 是别的类型声明(`type` 别名这类,一行译文)。
*/
export type BlockKind
= | 'import' | 'function' | 'class' | 'enum' | 'exception' | 'type' | 'field' | 'const' | 'variable'
= | 'import' | 'function' | 'class' | 'interface' | 'enum' | 'exception' | 'type' | 'field' | 'const' | 'variable'
| 'trait' | 'impl' | 'module' | 'attribute'
| 'if' | 'else' | 'loop' | 'try' | 'catch' | 'finally' | 'return' | 'statement' | 'comment'
| 'interpreter' | 'options' | 'case' | 'command' | 'pipeline'
@@ -275,6 +276,40 @@ export interface EnumFacts {
members: EnumMemberFacts[]
}
/** 接口的一个属性:属性签名 `名字?: 类型`,索引签名 `[key: string]: 类型` 也算一个;节点都指向源码。 */
export interface InterfacePropertyFacts {
/** 属性名;索引签名是方括号里的参数名(`[key: string]` 的 `key`)。 */
name: Node
/** 索引签名方括号里参数的类型(`[key: string]` 的 `string`);普通属性没有。 */
index?: Node
/** 属性的类型;没标注时没有。 */
type?: Node
/** 可省略的属性 `x?`。 */
optional: boolean
/** 只读属性 `readonly x`。 */
readonly: boolean
/** 属性的说明文字节点,同 [EnumMemberFacts.docs]:从上一个成员之后起单独成行的注释 / JSDoc、写在它这一行行尾的注释。 */
docs: Node[]
}
/**
* 接口:TypeScript 的 `interface`(含 `declare interface`)由语言插件报。属性(含索引签名)连同讲它的注释并进属性表,
* 方法签名、调用签名、构造签名这些别的成员照旧是子块。
*/
export interface InterfaceFacts {
name: Node
/** 接口自己的说明,同 [ClassFacts.doc]:紧贴在前面的 JSDoc。 */
doc?: Node
/** 同 [ClassFacts.access]。 */
access?: Access
/** 泛型参数,同 [ClassFacts.typeParameters]。 */
typeParameters: Node[]
/** 继承的接口(`extends A, B<T>`),每项一个节点,泛型实参连在里面。 */
extends: Node[]
/** 照源码顺序。 */
properties: InterfacePropertyFacts[]
}
/** 异常类的一个类属性:Python 类主体里给一个名字赋值的语句(带不带注解、有没有值),TypeScript 的类字段(含 static);节点都指向源码。 */
export interface FieldFacts {
name: Node
@@ -551,7 +586,7 @@ export interface VariableFacts {
* - kind:块的种类(BlockKind);
* - access:访问级别,'public' | 'private' | 'protected',语言可以加自己的值(Kotlin 的 'internal',见 BlockShape.attributes);
* - async、abstract、typeOnly:异步、抽象、仅类型,值是 'true' | 'false'。
* 宿主从块的 kind 和 facts 推出它们(FunctionFacts.access / async、ClassFacts.access / abstract、EnumFacts.access、ExceptionFacts.access、ImportFacts.typeOnly、VariableFacts.access),
* 宿主从块的 kind 和 facts 推出它们([FunctionFacts.access] / [FunctionFacts.async]、[ClassFacts.access] / [ClassFacts.abstract]、[InterfaceFacts.access]、[EnumFacts.access]、[ExceptionFacts.access]、[ImportFacts.typeOnly]、[VariableFacts.access]),
* 语言插件不用另报;facts 里没填的(语言没有这个概念、块没有这一项),块就没有这个属性,也不受这个属性的筛选影响。
*/
export const COMMON_ATTRIBUTES = ['kind', 'access', 'async', 'abstract', 'typeOnly'] as const
@@ -593,6 +628,8 @@ export interface ImplBlock extends BlockShape { kind: 'impl', facts: ClassFacts
export interface ModuleBlock extends BlockShape { kind: 'module', facts: ClassFacts }
/** Rust 的内部属性 `#![…]`:写给所在 crate 或模块的编译属性。 */
export interface AttributeBlock extends BlockShape { kind: 'attribute', facts: AttributeFacts }
/** 接口块的头部是整个接口(属性都在属性表里讲),方法签名等别的成员是子块。 */
export interface InterfaceBlock extends BlockShape { kind: 'interface', facts: InterfaceFacts }
/** 枚举块的头部是整个枚举(成员都在属性表里讲),没有子块;库规则认出来的枚举(Python)是整个类,留下的方法等是子块。 */
export interface EnumBlock extends BlockShape { kind: 'enum', facts: EnumFacts }
/** 异常块的头部是整个类(类属性都在属性表里讲),留下的方法(含构造函数)等是子块。 */
@@ -610,11 +647,11 @@ export interface StageBlock extends BlockShape { kind: 'stage', facts: StageFact
export interface HealthBlock extends BlockShape { kind: 'health', facts: HealthFacts }
export interface StartBlock extends BlockShape { kind: 'start', facts: StartFacts }
export type FactBlock
= | FunctionBlock | ClassBlock | TraitBlock | ImplBlock | ModuleBlock | AttributeBlock | EnumBlock | ExceptionBlock | ImportBlock | VariableBlock | InterpreterBlock | OptionsBlock
= | FunctionBlock | ClassBlock | TraitBlock | ImplBlock | ModuleBlock | AttributeBlock | InterfaceBlock | EnumBlock | ExceptionBlock | ImportBlock | VariableBlock | InterpreterBlock | OptionsBlock
| DirectiveBlock | StageBlock | HealthBlock | StartBlock
/** 带说明(facts.doc)的块。 */
export type DocumentedBlock = FunctionBlock | ClassBlock | TraitBlock | ImplBlock | ModuleBlock | EnumBlock | ExceptionBlock | VariableBlock
export type DocumentedBlock = FunctionBlock | ClassBlock | TraitBlock | ImplBlock | ModuleBlock | InterfaceBlock | EnumBlock | ExceptionBlock | VariableBlock
/** 属性表块的种类和 facts,不带块的形状(节点、头部、子块):库规则把一块认成现成的一种属性表块时给它(RuleFacts)。 */
export type BlockFacts = FactBlock extends infer B ? B extends FactBlock ? Pick<B, 'kind' | 'facts'> : never : never
@@ -1068,6 +1105,7 @@ export const KIND_ICONS: Record<BlockKind, KindIconName> = {
module: 'layers',
attribute: 'sliders-horizontal',
type: 'braces',
interface: 'braces',
enum: 'list-ordered',
exception: 'triangle-alert',
field: 'tag',