- 标题栏新按钮「未提交的更改」:树里只剩工作区各 git 仓库里没提交的文件(暂存、没暂存、未跟踪、合并冲突),每个有改动的仓库一个根,跟着 git 状态自动重摆;上色和徽标交给 VS Code 自带的 git 装饰
- 两种筛选互斥,由 TreeFilters 统一管,上下文键合并成 superpowers.codeReader.filter(review / uncommitted)
- 改动文件树改成多根,buildChangedTree 挪到 explorer/changedTree 并改吃 {path, change}
- 内置 git 扩展 API 的类型和加载抽到 src/git/gitApi、gitExtension,提交按钮的监听也改用它
- 文件注释按文件所在的工作区文件夹记,不看树从哪个根摆下来
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import type { Disposable, Event, FileDecorationProvider, Uri } from 'vscode'
|
|
import type { FileChange } from '../explorer/changedTree'
|
|
import { EventEmitter, FileDecoration, ThemeColor } from 'vscode'
|
|
import { CHANGE_STYLES } from './changedFiles'
|
|
|
|
/**
|
|
* 审查工单时给 PR 改过的文件上色、挂 M / A / D 徽标,颜色和 VS Code 源代码管理一样;不审查时什么都不挂。
|
|
* 挂在文件 Uri 上:侧栏的行、编辑器标签页上打开的这些文件都带着。
|
|
*/
|
|
export class ChangeDecorations implements FileDecorationProvider, Disposable {
|
|
private readonly changed = new EventEmitter<Uri[]>()
|
|
readonly onDidChangeFileDecorations: Event<Uri[]> = this.changed.event
|
|
private changes = new Map<string, FileChange>()
|
|
private uris: Uri[] = []
|
|
|
|
/** 换成这些文件的改动(空数组清掉),原来挂着的和新挂的都重画。 */
|
|
show(files: readonly { uri: Uri, change: FileChange }[]): void {
|
|
const before = this.uris
|
|
this.changes = new Map(files.map(file => [file.uri.toString(), file.change]))
|
|
this.uris = files.map(file => file.uri)
|
|
this.changed.fire([...before, ...this.uris])
|
|
}
|
|
|
|
provideFileDecoration(uri: Uri): FileDecoration | undefined {
|
|
const change = this.changes.get(uri.toString())
|
|
if (!change)
|
|
return undefined
|
|
const style = CHANGE_STYLES[change]
|
|
return new FileDecoration(change, style.tooltip, new ThemeColor(style.color))
|
|
}
|
|
|
|
dispose(): void {
|
|
this.changed.dispose()
|
|
}
|
|
}
|