From a7acda25826bd040e7ea4394346364ce854d4b90 Mon Sep 17 00:00:00 2001 From: Parker Higgins Date: Tue, 19 Sep 2023 19:12:09 -0400 Subject: [PATCH] File Explorer: add configuration option to hide dotfiles (#221) Fixes #199 --- package.json | 9 +++++++++ src/node-explorer-provider.ts | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4a89255..d1ebdc5 100644 --- a/package.json +++ b/package.json @@ -410,6 +410,15 @@ "default": 30000, "markdownDescription": "The connection timeout for SSH connections in milliseconds.", "scope": "window" + }, + "tailscale.fileExplorer.showDotFiles": { + "type": "boolean", + "default": true, + "markdownDescription": "Show files and directories with names that start with a period.", + "scope": "window", + "examples": [ + false + ] } } } diff --git a/src/node-explorer-provider.ts b/src/node-explorer-provider.ts index 98972b2..00f452a 100644 --- a/src/node-explorer-provider.ts +++ b/src/node-explorer-provider.ts @@ -10,6 +10,7 @@ import { createTsUri, parseTsUri } from './utils/uri'; import { getUsername } from './utils/host'; import { FileSystemProvider } from './filesystem-provider'; import { trimSuffix } from './utils'; +import { EXTENSION_NS } from './constants'; /** * Anatomy of the TreeView @@ -28,7 +29,7 @@ export class NodeExplorerProvider private _onDidChangeTreeData: vscode.EventEmitter< (PeerBaseTreeItem | FileExplorer | undefined)[] | undefined > = new vscode.EventEmitter(); - + private showDotFiles: boolean | undefined; // We want to use an array as the event type, but the API for this is currently being finalized. Until it's finalized, use any. // eslint-disable-next-line @typescript-eslint/no-explicit-any public onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; @@ -39,6 +40,9 @@ export class NodeExplorerProvider private fsProvider: FileSystemProvider, private updateNodeExplorerDisplayName: (title: string) => void ) { + this.showDotFiles = vscode.workspace + .getConfiguration(EXTENSION_NS) + .get('fileExplorer.showDotFiles'); this.registerCopyDNSNameCommand(); this.registerCopyIPv4Command(); this.registerCopyIPv6Command(); @@ -72,10 +76,15 @@ export class NodeExplorerProvider // File Explorer if (element instanceof FileExplorer) { const dirents = await vscode.workspace.fs.readDirectory(element.uri); - return dirents.map(([name, type]) => { + const filtered = dirents.reduce((acc, [name, type]) => { + if (this.showDotFiles == false && name.startsWith('.')) { + return acc; + } const childUri = element.uri.with({ path: `${element.uri.path}/${name}` }); - return new FileExplorer(name, childUri, type); - }); + acc.push(new FileExplorer(name, childUri, type)); + return acc; + }, []); + return filtered; } // Node root