✨ feat(vscode): 代码阅读预览 Rust 的语言卡片

This commit is contained in:
cruldra committed 2026-10-04 14:24:55 +08:00
1 parent 4480f936f3
commit 6d58b681cf
15 files changed
+1016 -6

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
import type { ImplBlock, KindBadge, LibraryRule, RuleCard, ThemeColor } from '../contract'
import { implRows, plainSay } from '../rustRows'
/** 和函数卡同一个黄,实现块看起来仍是函数那一挂。 */
const COLOR: ThemeColor = { dark: '#dcdcaa', light: '#795e26' }
const BADGE: KindBadge = { label: '实现', color: COLOR, icon: 'square-function' }
/**
* impl 的方法表:点方法名展开那张函数卡。
* 子块放进属性表某一行,和 React 事件处理同一条路。不看导入,Rust 文件都启用。
*/
export const rustImplRule: LibraryRule = {
id: 'rust',
label: 'Rust 实现',
languageIds: ['rust'],
libraries: [],
claim: block => block.kind === 'impl' ? implCard(block) : undefined,
attributeNames: () => ({
attributes: {},
values: { kind: { 'rust.impl': '实现' } },
}),
}
function implCard(block: ImplBlock): RuleCard {
const rows = implRows(block, plainSay())
const row = rows.findIndex(item => item.label === '方法')
const methods = block.children.filter(child => child.kind === 'function')
return {
kind: 'rust.impl',
badge: BADGE,
rows,
...(block.facts.name && { defines: { startIndex: block.facts.name.startIndex, endIndex: block.facts.name.endIndex } }),
absorbs: [],
...(row >= 0 && { slots: methods.map((child, item) => ({ block: child, row, item })) }),
}
}