✨ feat(vscode): 代码阅读的入口文件和入口块换成绿色播放图标,不再写「入口」二字
This commit is contained in:
1 parent
5827defd51
commit
f6bc217e91
10 files changed
+110
-53
No files matched your search
@@ -1,31 +1,26 @@
|
||||
import type { BlockView } from '../blockView'
|
||||
import type { Segment } from '../contract'
|
||||
import type { BlockConcept } from '../contract'
|
||||
|
||||
/** 名称那一行、名字后面的浅色说明词。 */
|
||||
const ENTRY_HINT: Segment = { text: ' 入口', role: 'hint' }
|
||||
/** 入口这个概念:绿色播放图标,绿色就是侧栏入口文件图标的主题色 `testing.iconPassed`(webview 里是同名的 CSS 变量,跟着主题变)。 */
|
||||
export const ENTRY_CONCEPT: BlockConcept = {
|
||||
id: 'entry',
|
||||
label: '入口',
|
||||
icon: 'play',
|
||||
color: { dark: 'var(--vscode-testing-iconPassed)', light: 'var(--vscode-testing-iconPassed)' },
|
||||
}
|
||||
|
||||
/**
|
||||
* 入口文件的预览:文件最外层、名字是入口名字之一的那一块(函数、常量、变量、库规则的卡片,谁对上就是谁),
|
||||
* 属性表里写着这个名字的那一行、名字后面加一个浅色的「入口」。和语言、翻译插件无关:
|
||||
* 块的名字按它定义处(defines)在源码里的那一段认,属性表里按词的源码下标(offset)找写名字的那个词;对不上就什么都不加。
|
||||
* 概念列表的第一个(种类)换成入口(ENTRY_CONCEPT),后面别的概念照旧;种类、筛选、卡片边框都不变。和语言、翻译插件无关:
|
||||
* 块的名字按它定义处(defines)在源码里的那一段认;对不上就什么都不改。
|
||||
*/
|
||||
export function markEntryNames(blocks: BlockView[], source: string, names: readonly string[]): BlockView[] {
|
||||
export function markEntryBlocks(blocks: BlockView[], source: string, names: readonly string[]): BlockView[] {
|
||||
if (names.length === 0)
|
||||
return blocks
|
||||
return blocks.map((block) => {
|
||||
const at = block.defines
|
||||
if (!at || !('properties' in block) || !names.includes(source.slice(at.startIndex, at.endIndex)))
|
||||
if (!at || !names.includes(source.slice(at.startIndex, at.endIndex)))
|
||||
return block
|
||||
let marked = false
|
||||
const properties = block.properties.map((row) => {
|
||||
if (marked || 'markdown' in row.value)
|
||||
return row
|
||||
const index = row.value.findIndex(piece => 'role' in piece && piece.offset === at.startIndex)
|
||||
if (index < 0)
|
||||
return row
|
||||
marked = true
|
||||
return { ...row, value: [...row.value.slice(0, index + 1), ENTRY_HINT, ...row.value.slice(index + 1)] }
|
||||
})
|
||||
return marked ? { ...block, properties } : block
|
||||
return { ...block, concepts: [ENTRY_CONCEPT, ...block.concepts.slice(1)] }
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user