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() readonly onDidChangeFileDecorations: Event = this.changed.event private changes = new Map() 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() } }