feat: allow control over displaying hidden/dotfiles and .gitignore matches (#179)
* feat: add chat setting to toggle hidden files (dotfiles) * feat: add toggle to show/hide gitignored files in file browser * refactor: don't reuse visibility setting for dotfiles toggle * fix: honor hidden/gitignored toggles across runtimes --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
6544b12e78
commit
2de0d9d3dd
@@ -11,13 +11,16 @@ import { sendBridgeMessage, sendBridgeMessageWithOptions } from './bridge';
|
||||
const normalizePath = (value: string): string => value.replace(/\\/g, '/');
|
||||
|
||||
export const createVSCodeFilesAPI = (): FilesAPI => ({
|
||||
async listDirectory(path: string): Promise<DirectoryListResult> {
|
||||
async listDirectory(path: string, options?: { respectGitignore?: boolean }): Promise<DirectoryListResult> {
|
||||
const target = normalizePath(path);
|
||||
const data = await sendBridgeMessage<{
|
||||
directory?: string;
|
||||
path?: string;
|
||||
entries: Array<{ name: string; path: string; isDirectory: boolean }>;
|
||||
}>('api:fs:list', { path: target });
|
||||
}>('api:fs:list', {
|
||||
path: target,
|
||||
respectGitignore: options?.respectGitignore,
|
||||
});
|
||||
|
||||
const directory = normalizePath(data?.directory || data?.path || target);
|
||||
const entries = Array.isArray(data?.entries) ? data.entries : [];
|
||||
@@ -36,6 +39,8 @@ export const createVSCodeFilesAPI = (): FilesAPI => ({
|
||||
directory: normalizePath(payload.directory),
|
||||
query: payload.query,
|
||||
limit: payload.maxResults,
|
||||
includeHidden: payload.includeHidden,
|
||||
respectGitignore: payload.respectGitignore,
|
||||
});
|
||||
|
||||
const files = Array.isArray(data?.files) ? data.files : [];
|
||||
|
||||
@@ -263,6 +263,14 @@ if (workspaceFolder) {
|
||||
try {
|
||||
window.localStorage.setItem('lastDirectory', normalizedWorkspaceFolder);
|
||||
window.localStorage.setItem('homeDirectory', normalizedWorkspaceFolder);
|
||||
|
||||
// VS Code defaults: show dotfiles, hide gitignored
|
||||
if (window.localStorage.getItem('directoryTreeShowHidden') === null) {
|
||||
window.localStorage.setItem('directoryTreeShowHidden', 'true');
|
||||
}
|
||||
if (window.localStorage.getItem('filesViewShowGitignored') === null) {
|
||||
window.localStorage.setItem('filesViewShowGitignored', 'false');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to persist workspace folder', error);
|
||||
}
|
||||
@@ -357,7 +365,8 @@ const handleLocalApiRequest = async (url: URL, init?: RequestInit) => {
|
||||
|
||||
if (pathname.startsWith('/api/fs/list')) {
|
||||
const targetPath = url.searchParams.get('path') || '';
|
||||
const data = await sendBridgeMessage('api:fs:list', { path: targetPath });
|
||||
const respectGitignore = url.searchParams.get('respectGitignore') === 'true';
|
||||
const data = await sendBridgeMessage('api:fs:list', { path: targetPath, respectGitignore });
|
||||
return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
|
||||
@@ -367,7 +376,15 @@ const handleLocalApiRequest = async (url: URL, init?: RequestInit) => {
|
||||
const limitParam = url.searchParams.get('limit');
|
||||
const limit = limitParam ? Number(limitParam) : undefined;
|
||||
const resolvedLimit = Number.isFinite(limit) ? limit : undefined;
|
||||
const data = await sendBridgeMessage('api:fs:search', { directory, query, limit: resolvedLimit });
|
||||
const includeHidden = url.searchParams.get('includeHidden') === 'true';
|
||||
const respectGitignore = url.searchParams.get('respectGitignore') !== 'false';
|
||||
const data = await sendBridgeMessage('api:fs:search', {
|
||||
directory,
|
||||
query,
|
||||
limit: resolvedLimit,
|
||||
includeHidden,
|
||||
respectGitignore,
|
||||
});
|
||||
return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user