From 2ee927dbaa5d02b7e192d8ee0cb37a3658db9740 Mon Sep 17 00:00:00 2001 From: "lon.hutt" Date: Mon, 7 Oct 2024 15:06:14 -0600 Subject: [PATCH] updated multi-root support with a more native impl --- package.json | 5 -- src/extension.ts | 5 -- src/projectViewManager.ts | 7 ++- src/provider/rootFileViewProvider.ts | 76 ---------------------------- 4 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 src/provider/rootFileViewProvider.ts diff --git a/package.json b/package.json index afc4800..0718231 100644 --- a/package.json +++ b/package.json @@ -232,11 +232,6 @@ { "id": "bazelTaskOutline", "name": "Bazel Run Targets" - }, - { - "id": "rootFileViewer", - "name": "Project Root (Files)", - "when": "isMultiRoot" } ] }, diff --git a/src/extension.ts b/src/extension.ts index 611d09f..d341f9d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,7 +21,6 @@ import { registerLSClient } from './loggingTCPServer'; import { ProjectViewManager } from './projectViewManager'; import { BazelRunTargetProvider } from './provider/bazelRunTargetProvider'; import { BazelTaskProvider } from './provider/bazelTaskProvider'; -import { RootFileViewProvider } from './provider/rootFileViewProvider'; import { getWorkspaceRoot, initBazelProjectFile, @@ -46,10 +45,6 @@ export async function activate(context: ExtensionContext) { BazelRunTargetProvider.instance ); tasks.registerTaskProvider('bazel', new BazelTaskProvider()); - window.registerTreeDataProvider( - 'rootFileViewer', - RootFileViewProvider.instance - ); BazelLanguageServerTerminal.trace('extension activated'); diff --git a/src/projectViewManager.ts b/src/projectViewManager.ts index d655131..5a59def 100644 --- a/src/projectViewManager.ts +++ b/src/projectViewManager.ts @@ -77,6 +77,9 @@ export namespace ProjectViewManager { async function getDisplayFolders(): Promise { let displayFolders = new Set(['.eclipse']); // TODO bubble this out to a setting + if (isMultiRoot()) { + displayFolders.add('.'); + } try { const bazelProjectFile = await getBazelProjectFile(); if (bazelProjectFile.directories.includes('.')) { @@ -164,11 +167,11 @@ export namespace ProjectViewManager { k.includes('.eclipse') ).length; - const viewAll = displayFolders.includes('.'); + const viewAll = displayFolders.includes('.') && !isMultiRoot(); const fileWatcherExcludePattern = viewAll ? '' - : `**/!(${Array.from(displayFolders.sort()).join('|')})/**`; + : `**/!(${Array.from(displayFolders.filter((s) => s !== '.').sort()).join('|')})/**`; if (viewAll) { // if viewAll and existing config doesn't contain .eclipse return diff --git a/src/provider/rootFileViewProvider.ts b/src/provider/rootFileViewProvider.ts deleted file mode 100644 index 7ae8d90..0000000 --- a/src/provider/rootFileViewProvider.ts +++ /dev/null @@ -1,76 +0,0 @@ -import path from 'path'; -import { - Event, - EventEmitter, - FileSystemWatcher, - ProviderResult, - RelativePattern, - ThemeIcon, - TreeDataProvider, - TreeItem, - TreeItemCollapsibleState, - Uri, - workspace, -} from 'vscode'; -import { getWorkspaceRoot } from '../util'; - -const WORKSPACE_ROOT = getWorkspaceRoot(); - -export class RootFileViewProvider implements TreeDataProvider { - private static _instance: RootFileViewProvider; - - private _filesWatcher: FileSystemWatcher; - private _onDidChangeTreeData: EventEmitter = - new EventEmitter(); - readonly onDidChangeTreeData: Event = - this._onDidChangeTreeData.event; - - private constructor() { - this._filesWatcher = workspace.createFileSystemWatcher( - new RelativePattern(WORKSPACE_ROOT, '*') - ); - this._filesWatcher.onDidChange((f) => this._onDidChangeTreeData.fire()); - this._filesWatcher.onDidCreate((f) => this._onDidChangeTreeData.fire()); - this._filesWatcher.onDidDelete((f) => this._onDidChangeTreeData.fire()); - } - - public static get instance(): RootFileViewProvider { - if (!this._instance) { - this._instance = new RootFileViewProvider(); - } - return this._instance; - } - - getTreeItem(element: string): TreeItem | Thenable { - return new FileItem(element); - } - getChildren(element?: string | undefined): ProviderResult { - if (!element) { - return workspace.fs - .readDirectory(Uri.file(WORKSPACE_ROOT)) - .then((val) => { - return val.filter((v) => v[1] === 1).map((v) => v[0]); - }); - } - return []; - } -} - -class FileItem extends TreeItem { - constructor(fileName: string, collapsibleState?: TreeItemCollapsibleState) { - super(fileName, collapsibleState); - this.command = { - title: fileName, - command: 'vscode.open', - arguments: [Uri.file(`${WORKSPACE_ROOT}${path.sep}${fileName}`)], - }; - switch (fileName.split('.').reverse()[0]) { - case 'json': - this.iconPath = new ThemeIcon('json'); - break; - default: - this.iconPath = new ThemeIcon('file'); - break; - } - } -}