Skip to content

Commit

Permalink
File Explorer: add configuration option to hide dotfiles (#221)
Browse files Browse the repository at this point in the history
Fixes #199
  • Loading branch information
thisisparker authored Sep 19, 2023
1 parent ad50c7e commit a7acda2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/node-explorer-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +29,7 @@ export class NodeExplorerProvider
private _onDidChangeTreeData: vscode.EventEmitter<
(PeerBaseTreeItem | FileExplorer | undefined)[] | undefined
> = new vscode.EventEmitter<PeerBaseTreeItem[] | undefined>();

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<any> = this._onDidChangeTreeData.event;
Expand All @@ -39,6 +40,9 @@ export class NodeExplorerProvider
private fsProvider: FileSystemProvider,
private updateNodeExplorerDisplayName: (title: string) => void
) {
this.showDotFiles = vscode.workspace
.getConfiguration(EXTENSION_NS)
.get<boolean>('fileExplorer.showDotFiles');
this.registerCopyDNSNameCommand();
this.registerCopyIPv4Command();
this.registerCopyIPv6Command();
Expand Down Expand Up @@ -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<FileExplorer[]>((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
Expand Down

0 comments on commit a7acda2

Please sign in to comment.