✨ feat(vscode): 代码阅读的入口文件和入口块换成绿色播放图标,不再写「入口」二字
This commit is contained in:
1 parent
5827defd51
commit
f6bc217e91
10 files changed
+110
-53
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { escapeMarkdown, rowDecoration } from './rowDecoration'
|
||||
import { ENTRY_ICON, escapeMarkdown, rowDecoration } from './rowDecoration'
|
||||
|
||||
describe('树上的一行', () => {
|
||||
it('没有注释、不是入口的行保持原样', () => {
|
||||
@@ -15,21 +15,27 @@ describe('树上的一行', () => {
|
||||
expect(rowDecoration('folder', 'campaign', '营销活动', undefined)?.contextValue).toBe('folder noted')
|
||||
})
|
||||
|
||||
it('入口、没注释:灰字是「入口」,提示里写从哪个名字开始读,contextValue 不变', () => {
|
||||
it('入口、没注释:没有灰字,图标换成绿色播放,提示里写从哪个名字开始读,contextValue 不变', () => {
|
||||
expect(rowDecoration('file', 'src/agent_cli/main.py', undefined, ['app', 'dev'])).toEqual({
|
||||
description: '入口',
|
||||
tooltip: '**src\\/agent\\_cli\\/main\\.py** \n入口,从 `app`、`dev` 开始读',
|
||||
contextValue: 'file',
|
||||
icon: { id: 'play', color: 'testing.iconPassed' },
|
||||
})
|
||||
expect(rowDecoration('file', 'bin/cli.js', undefined, [])?.tooltip).toBe('**bin\\/cli\\.js** \n入口')
|
||||
})
|
||||
|
||||
it('入口、有注释:灰字是「注释 · 入口」,注释不被盖掉,提示里注释下面再写入口', () => {
|
||||
it('入口、有注释:灰字只是注释,图标换成绿色播放,提示里注释下面再写入口', () => {
|
||||
expect(rowDecoration('file', 'src/main.rs', '服务启动', ['main'])).toEqual({
|
||||
description: '服务启动 · 入口',
|
||||
description: '服务启动',
|
||||
tooltip: '**src\\/main\\.rs** \n服务启动 \n入口,从 `main` 开始读',
|
||||
contextValue: 'file noted',
|
||||
icon: ENTRY_ICON,
|
||||
})
|
||||
expect(ENTRY_ICON).toEqual({ id: 'play', color: 'testing.iconPassed' })
|
||||
})
|
||||
|
||||
it('不是入口的行不换图标', () => {
|
||||
expect(rowDecoration('file', 'src/lib.rs', '库', undefined)?.icon).toBeUndefined()
|
||||
})
|
||||
|
||||
it('注释里的 Markdown 符号原样显示', () => {
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
/** 侧栏一行名字后面的灰字和悬停提示:文件注释、项目入口。 */
|
||||
/** 侧栏一行换上的图标:VS Code 自带图标字体里的名字(ThemeIcon 的 id)和主题色的键(ThemeColor 的 id)。 */
|
||||
export interface RowIcon {
|
||||
id: string
|
||||
color: string
|
||||
}
|
||||
|
||||
/** 入口文件的图标:绿色播放,绿色是测试通过的那种(主题色 `testing.iconPassed`)。 */
|
||||
export const ENTRY_ICON: RowIcon = { id: 'play', color: 'testing.iconPassed' }
|
||||
|
||||
/** 侧栏一行名字后面的灰字、悬停提示和图标:文件注释、项目入口。 */
|
||||
export interface RowDecoration {
|
||||
/** 名字后面的灰字:注释,是入口时后面接「 · 入口」,没注释时就是「入口」;VS Code 放不下时自己截断 */
|
||||
description: string
|
||||
/** 名字后面的灰字:文件注释,没注释时没有;VS Code 放不下时自己截断 */
|
||||
description?: string
|
||||
/** 悬停提示(Markdown):第一行粗体的相对路径,下面是注释全文,是入口时再一行写明 */
|
||||
tooltip: string
|
||||
/** 有注释时末尾加上 ` noted`:菜单的 when 子句靠它在「添加注释」和「编辑注释」之间换;是不是入口不影响 */
|
||||
contextValue: string
|
||||
/** 是入口时文件图标换成 ENTRY_ICON;git 改动的颜色和字母照旧由 VS Code 按文件加 */
|
||||
icon?: RowIcon
|
||||
}
|
||||
|
||||
/** 每个 ASCII 标点前加反斜杠(CommonMark 允许任何 ASCII 标点这样转义),注释里的 `*`、`_`、`<`、`[` 等原样显示。 */
|
||||
@@ -29,8 +40,9 @@ export function rowDecoration(contextValue: string, key: string, note: string |
|
||||
if (entry !== undefined)
|
||||
lines.push(entry.length > 0 ? `入口,从 ${entry.map(name => `\`${name}\``).join('、')} 开始读` : '入口')
|
||||
return {
|
||||
description: note === undefined ? '入口' : entry === undefined ? note : `${note} · 入口`,
|
||||
...(note !== undefined && { description: note }),
|
||||
tooltip: lines.join(' \n'),
|
||||
contextValue: note === undefined ? contextValue : `${contextValue} noted`,
|
||||
...(entry !== undefined && { icon: ENTRY_ICON }),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Event, TreeItem, Uri } from 'vscode'
|
||||
import type { FileNode, FileTreeDecorator } from './fileTree'
|
||||
import { Disposable, MarkdownString } from 'vscode'
|
||||
import { Disposable, MarkdownString, ThemeColor, ThemeIcon } from 'vscode'
|
||||
import { locate } from '../folderStore'
|
||||
import { rowDecoration } from './rowDecoration'
|
||||
|
||||
@@ -16,7 +16,10 @@ export interface RowEntries {
|
||||
namesOf: (uri: Uri) => readonly string[] | undefined
|
||||
}
|
||||
|
||||
/** 侧栏一行名字后面的灰字和悬停提示:文件注释,后面接项目入口(见 rowDecoration);工作区外面的行(审查的工作副本)不加。 */
|
||||
/**
|
||||
* 侧栏一行名字后面的灰字(文件注释)、悬停提示,入口文件换成绿色播放图标(见 rowDecoration);工作区外面的行(审查的工作副本)不加。
|
||||
* 只改这棵树自己的行,资源管理器、标签页不受影响。
|
||||
*/
|
||||
export class RowDecorator implements FileTreeDecorator {
|
||||
constructor(private readonly notes: RowNotes, private readonly entries: RowEntries) {}
|
||||
|
||||
@@ -33,8 +36,11 @@ export class RowDecorator implements FileTreeDecorator {
|
||||
const decoration = at && rowDecoration(item.contextValue ?? '', at.key, this.notes.noteOf(node), entry)
|
||||
if (!decoration)
|
||||
return
|
||||
item.description = decoration.description
|
||||
if (decoration.description !== undefined)
|
||||
item.description = decoration.description
|
||||
item.tooltip = new MarkdownString(decoration.tooltip)
|
||||
item.contextValue = decoration.contextValue
|
||||
if (decoration.icon)
|
||||
item.iconPath = new ThemeIcon(decoration.icon.id, new ThemeColor(decoration.icon.color))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user