addons/vscode/extension/IgnoredFileDecorationProvider.tsblame
View source
5ffddc61/**
5ffddc62 * Copyright (c) Meta Platforms, Inc. and affiliates.
5ffddc63 *
5ffddc64 * This source code is licensed under the MIT license found in the
5ffddc65 * LICENSE file in the root directory of this source tree.
5ffddc66 */
5ffddc67
5ffddc68import type {Logger} from 'isl-server/src/logger';
5ffddc69import type {Disposable, Event} from 'vscode';
5ffddc610
5ffddc611import {EventEmitter, ThemeColor, Uri, window, type FileDecoration, type FileDecorationProvider} from 'vscode';
5ffddc612import type {VSCodeRepo} from './VSCodeRepo';
5ffddc613
5ffddc614export default class IgnoredFileDecorationProvider implements FileDecorationProvider {
5ffddc615 private readonly _onDidChangeDecorations = new EventEmitter<Uri[]>();
5ffddc616 readonly onDidChangeFileDecorations: Event<Uri[]> = this._onDidChangeDecorations.event;
5ffddc617
5ffddc618 private disposables: Disposable[] = [];
5ffddc619 // Cache: uri string → ignored boolean
5ffddc620 private cache = new Map<string, boolean>();
5ffddc621
5ffddc622 constructor(
5ffddc623 private repository: VSCodeRepo,
5ffddc624 private logger: Logger,
5ffddc625 ) {
5ffddc626 this.disposables.push(window?.registerFileDecorationProvider?.(this));
5ffddc627 }
5ffddc628
5ffddc629 provideFileDecoration(uri: Uri): FileDecoration | undefined | Thenable<FileDecoration | undefined> {
5ffddc630 const root = this.repository.rootPath;
5ffddc631 if (!uri.fsPath.startsWith(root)) {
5ffddc632 return undefined;
5ffddc633 }
5ffddc634
5ffddc635 const key = uri.toString();
5ffddc636 if (this.cache.has(key)) {
5ffddc637 return this.cache.get(key)
5ffddc638 ? {color: new ThemeColor('gitDecoration.ignoredResourceForeground')}
5ffddc639 : undefined;
5ffddc640 }
5ffddc641
5ffddc642 const rel = uri.fsPath.slice(root.length + 1);
5ffddc643 if (!rel || rel === '.sl') {
5ffddc644 return undefined;
5ffddc645 }
5ffddc646
5ffddc647 return this.repository.runSlCommand(['debugignore', rel]).then(result => {
5ffddc648 if (result.exitCode !== 0) {
5ffddc649 return undefined;
5ffddc650 }
5ffddc651 const ignored = result.stdout.includes(': ignored by');
5ffddc652 this.cache.set(key, ignored);
5ffddc653 return ignored ? {color: new ThemeColor('gitDecoration.ignoredResourceForeground')} : undefined;
5ffddc654 });
5ffddc655 }
5ffddc656
5ffddc657 dispose(): void {
5ffddc658 this.disposables.forEach(d => d?.dispose());
5ffddc659 }
5ffddc660}