Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Explorer: add configuration option to hide dotfiles #221

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,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