| 5ffddc6 | | | 1 | /** |
| 5ffddc6 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 5ffddc6 | | | 3 | * |
| 5ffddc6 | | | 4 | * This source code is licensed under the MIT license found in the |
| 5ffddc6 | | | 5 | * LICENSE file in the root directory of this source tree. |
| 5ffddc6 | | | 6 | */ |
| 5ffddc6 | | | 7 | |
| 5ffddc6 | | | 8 | import type {Logger} from 'isl-server/src/logger'; |
| 5ffddc6 | | | 9 | import type {Disposable, Event} from 'vscode'; |
| 5ffddc6 | | | 10 | |
| 5ffddc6 | | | 11 | import {EventEmitter, ThemeColor, Uri, window, type FileDecoration, type FileDecorationProvider} from 'vscode'; |
| 5ffddc6 | | | 12 | import type {VSCodeRepo} from './VSCodeRepo'; |
| 5ffddc6 | | | 13 | |
| 5ffddc6 | | | 14 | export default class IgnoredFileDecorationProvider implements FileDecorationProvider { |
| 5ffddc6 | | | 15 | private readonly _onDidChangeDecorations = new EventEmitter<Uri[]>(); |
| 5ffddc6 | | | 16 | readonly onDidChangeFileDecorations: Event<Uri[]> = this._onDidChangeDecorations.event; |
| 5ffddc6 | | | 17 | |
| 5ffddc6 | | | 18 | private disposables: Disposable[] = []; |
| 5ffddc6 | | | 19 | // Cache: uri string → ignored boolean |
| 5ffddc6 | | | 20 | private cache = new Map<string, boolean>(); |
| 5ffddc6 | | | 21 | |
| 5ffddc6 | | | 22 | constructor( |
| 5ffddc6 | | | 23 | private repository: VSCodeRepo, |
| 5ffddc6 | | | 24 | private logger: Logger, |
| 5ffddc6 | | | 25 | ) { |
| 5ffddc6 | | | 26 | this.disposables.push(window?.registerFileDecorationProvider?.(this)); |
| 5ffddc6 | | | 27 | } |
| 5ffddc6 | | | 28 | |
| 5ffddc6 | | | 29 | provideFileDecoration(uri: Uri): FileDecoration | undefined | Thenable<FileDecoration | undefined> { |
| 5ffddc6 | | | 30 | const root = this.repository.rootPath; |
| 5ffddc6 | | | 31 | if (!uri.fsPath.startsWith(root)) { |
| 5ffddc6 | | | 32 | return undefined; |
| 5ffddc6 | | | 33 | } |
| 5ffddc6 | | | 34 | |
| 5ffddc6 | | | 35 | const key = uri.toString(); |
| 5ffddc6 | | | 36 | if (this.cache.has(key)) { |
| 5ffddc6 | | | 37 | return this.cache.get(key) |
| 5ffddc6 | | | 38 | ? {color: new ThemeColor('gitDecoration.ignoredResourceForeground')} |
| 5ffddc6 | | | 39 | : undefined; |
| 5ffddc6 | | | 40 | } |
| 5ffddc6 | | | 41 | |
| 5ffddc6 | | | 42 | const rel = uri.fsPath.slice(root.length + 1); |
| 5ffddc6 | | | 43 | if (!rel || rel === '.sl') { |
| 5ffddc6 | | | 44 | return undefined; |
| 5ffddc6 | | | 45 | } |
| 5ffddc6 | | | 46 | |
| 5ffddc6 | | | 47 | return this.repository.runSlCommand(['debugignore', rel]).then(result => { |
| 5ffddc6 | | | 48 | if (result.exitCode !== 0) { |
| 5ffddc6 | | | 49 | return undefined; |
| 5ffddc6 | | | 50 | } |
| 5ffddc6 | | | 51 | const ignored = result.stdout.includes(': ignored by'); |
| 5ffddc6 | | | 52 | this.cache.set(key, ignored); |
| 5ffddc6 | | | 53 | return ignored ? {color: new ThemeColor('gitDecoration.ignoredResourceForeground')} : undefined; |
| 5ffddc6 | | | 54 | }); |
| 5ffddc6 | | | 55 | } |
| 5ffddc6 | | | 56 | |
| 5ffddc6 | | | 57 | dispose(): void { |
| 5ffddc6 | | | 58 | this.disposables.forEach(d => d?.dispose()); |
| 5ffddc6 | | | 59 | } |
| 5ffddc6 | | | 60 | } |