|
|
|
@@ -77,10 +77,12 @@ import {
|
|
|
|
|
buildRootGroups,
|
|
|
|
|
buildThreadActionItems,
|
|
|
|
|
type CommandPaletteActionItem,
|
|
|
|
|
type CommandPaletteGroup,
|
|
|
|
|
type CommandPaletteSubmenuItem,
|
|
|
|
|
type CommandPaletteView,
|
|
|
|
|
filterBrowseEntries,
|
|
|
|
|
filterCommandPaletteGroups,
|
|
|
|
|
getBrowsePrefetchPaths,
|
|
|
|
|
getCommandPaletteInputPlaceholder,
|
|
|
|
|
getCommandPaletteMode,
|
|
|
|
|
ITEM_ICON_CLASS,
|
|
|
|
@@ -332,6 +334,11 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
browseEnvironmentId && currentProjectEnvironmentId === browseEnvironmentId
|
|
|
|
|
? currentProjectCwd
|
|
|
|
|
: null;
|
|
|
|
|
const getBrowseCwdForEnvironment = useCallback(
|
|
|
|
|
(environmentId: EnvironmentId | null): string | null =>
|
|
|
|
|
environmentId && currentProjectEnvironmentId === environmentId ? currentProjectCwd : null,
|
|
|
|
|
[currentProjectCwd, currentProjectEnvironmentId],
|
|
|
|
|
);
|
|
|
|
|
const relativePathNeedsActiveProject =
|
|
|
|
|
isExplicitRelativeProjectPath(query.trim()) && currentProjectCwdForBrowse === null;
|
|
|
|
|
const browseDirectoryPath = isBrowsing ? getBrowseDirectoryPath(query) : "";
|
|
|
|
@@ -339,16 +346,20 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
isBrowsing && !hasTrailingPathSeparator(query) ? getBrowseLeafPathSegment(query) : "";
|
|
|
|
|
|
|
|
|
|
const fetchBrowseResult = useCallback(
|
|
|
|
|
async (partialPath: string): Promise<FilesystemBrowseResult | null> => {
|
|
|
|
|
if (!browseEnvironmentId) return null;
|
|
|
|
|
const api = readEnvironmentApi(browseEnvironmentId);
|
|
|
|
|
async (input: {
|
|
|
|
|
environmentId: EnvironmentId | null;
|
|
|
|
|
partialPath: string;
|
|
|
|
|
cwd: string | null;
|
|
|
|
|
}): Promise<FilesystemBrowseResult | null> => {
|
|
|
|
|
if (!input.environmentId) return null;
|
|
|
|
|
const api = readEnvironmentApi(input.environmentId);
|
|
|
|
|
if (!api) return null;
|
|
|
|
|
return api.filesystem.browse({
|
|
|
|
|
partialPath,
|
|
|
|
|
...(currentProjectCwdForBrowse ? { cwd: currentProjectCwdForBrowse } : {}),
|
|
|
|
|
partialPath: input.partialPath,
|
|
|
|
|
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[browseEnvironmentId, currentProjectCwdForBrowse],
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { data: browseResult, isPending: isBrowsePending } = useQuery({
|
|
|
|
@@ -358,7 +369,13 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
browseDirectoryPath,
|
|
|
|
|
currentProjectCwdForBrowse,
|
|
|
|
|
],
|
|
|
|
|
queryFn: () => fetchBrowseResult(browseDirectoryPath),
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
fetchBrowseResult({
|
|
|
|
|
environmentId: browseEnvironmentId,
|
|
|
|
|
partialPath: browseDirectoryPath,
|
|
|
|
|
cwd: currentProjectCwdForBrowse,
|
|
|
|
|
}),
|
|
|
|
|
placeholderData: (previousData) => previousData,
|
|
|
|
|
staleTime: BROWSE_STALE_TIME_MS,
|
|
|
|
|
enabled:
|
|
|
|
|
isBrowsing &&
|
|
|
|
@@ -367,52 +384,54 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
!relativePathNeedsActiveProject,
|
|
|
|
|
});
|
|
|
|
|
const browseEntries = browseResult?.entries ?? EMPTY_BROWSE_ENTRIES;
|
|
|
|
|
const {
|
|
|
|
|
filteredEntries: filteredBrowseEntries,
|
|
|
|
|
highlightedEntry: highlightedBrowseEntry,
|
|
|
|
|
exactEntry: exactBrowseEntry,
|
|
|
|
|
} = useMemo(
|
|
|
|
|
const { filteredEntries: filteredBrowseEntries, exactEntry: exactBrowseEntry } = useMemo(
|
|
|
|
|
() => filterBrowseEntries({ browseEntries, browseFilterQuery, highlightedItemValue }),
|
|
|
|
|
[browseEntries, browseFilterQuery, highlightedItemValue],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const prefetchBrowsePath = useCallback(
|
|
|
|
|
(partialPath: string) => {
|
|
|
|
|
void queryClient.prefetchQuery({
|
|
|
|
|
queryKey: [
|
|
|
|
|
"filesystemBrowse",
|
|
|
|
|
browseEnvironmentId,
|
|
|
|
|
partialPath,
|
|
|
|
|
currentProjectCwdForBrowse,
|
|
|
|
|
],
|
|
|
|
|
queryFn: () => fetchBrowseResult(partialPath),
|
|
|
|
|
async (
|
|
|
|
|
partialPath: string,
|
|
|
|
|
environmentId: EnvironmentId | null = browseEnvironmentId,
|
|
|
|
|
cwd: string | null = currentProjectCwdForBrowse,
|
|
|
|
|
) => {
|
|
|
|
|
if (!environmentId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await queryClient.prefetchQuery({
|
|
|
|
|
queryKey: ["filesystemBrowse", environmentId, partialPath, cwd],
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
fetchBrowseResult({
|
|
|
|
|
environmentId,
|
|
|
|
|
partialPath,
|
|
|
|
|
cwd,
|
|
|
|
|
}),
|
|
|
|
|
staleTime: BROWSE_STALE_TIME_MS,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[browseEnvironmentId, currentProjectCwdForBrowse, fetchBrowseResult, queryClient],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Prefetch the parent and the most likely next child so browse navigation
|
|
|
|
|
// stays warm without scanning every child directory in large trees.
|
|
|
|
|
const browsePrefetchPaths = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
getBrowsePrefetchPaths({
|
|
|
|
|
browseQuery: query,
|
|
|
|
|
canBrowseUp: canNavigateUp(query),
|
|
|
|
|
exactEntry: exactBrowseEntry,
|
|
|
|
|
}),
|
|
|
|
|
[exactBrowseEntry, query],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Prefetch the parent and only an exact typed child so browse navigation
|
|
|
|
|
// stays warm without turning pointer hover into a directory read.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isBrowsing || filteredBrowseEntries.length === 0) return;
|
|
|
|
|
|
|
|
|
|
if (canNavigateUp(query)) {
|
|
|
|
|
prefetchBrowsePath(getBrowseParentPath(query)!);
|
|
|
|
|
for (const partialPath of browsePrefetchPaths) {
|
|
|
|
|
prefetchBrowsePath(partialPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nextChild = highlightedBrowseEntry ?? exactBrowseEntry;
|
|
|
|
|
if (nextChild) {
|
|
|
|
|
prefetchBrowsePath(appendBrowsePathSegment(query, nextChild.name));
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
exactBrowseEntry,
|
|
|
|
|
filteredBrowseEntries.length,
|
|
|
|
|
highlightedBrowseEntry,
|
|
|
|
|
isBrowsing,
|
|
|
|
|
prefetchBrowsePath,
|
|
|
|
|
query,
|
|
|
|
|
]);
|
|
|
|
|
}, [filteredBrowseEntries.length, browsePrefetchPaths, isBrowsing, prefetchBrowsePath]);
|
|
|
|
|
|
|
|
|
|
const openProjectFromSearch = useMemo(
|
|
|
|
|
() => async (project: (typeof projects)[number]) => {
|
|
|
|
@@ -554,15 +573,23 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startAddProjectBrowse = useCallback(
|
|
|
|
|
(environmentId: EnvironmentId): void => {
|
|
|
|
|
async (environmentId: EnvironmentId): Promise<void> => {
|
|
|
|
|
const initialQuery = getAddProjectInitialQueryForEnvironment(environmentId);
|
|
|
|
|
const initialBrowsePath = getBrowseDirectoryPath(initialQuery);
|
|
|
|
|
const browseCwd = getBrowseCwdForEnvironment(environmentId);
|
|
|
|
|
|
|
|
|
|
if (initialBrowsePath.length > 0) {
|
|
|
|
|
await prefetchBrowsePath(initialBrowsePath, environmentId, browseCwd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setAddProjectEnvironmentId(environmentId);
|
|
|
|
|
pushPaletteView({
|
|
|
|
|
addonIcon: <FolderPlusIcon className={ADDON_ICON_CLASS} />,
|
|
|
|
|
groups: [],
|
|
|
|
|
initialQuery: getAddProjectInitialQueryForEnvironment(environmentId),
|
|
|
|
|
initialQuery,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[getAddProjectInitialQueryForEnvironment],
|
|
|
|
|
[getAddProjectInitialQueryForEnvironment, getBrowseCwdForEnvironment, prefetchBrowsePath],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const addProjectEnvironmentItems: CommandPaletteActionItem[] = addProjectEnvironmentOptions.map(
|
|
|
|
@@ -575,7 +602,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
icon: <FolderPlusIcon className={ITEM_ICON_CLASS} />,
|
|
|
|
|
keepOpen: true,
|
|
|
|
|
run: async () => {
|
|
|
|
|
startAddProjectBrowse(option.environmentId);
|
|
|
|
|
await startAddProjectBrowse(option.environmentId);
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
@@ -591,7 +618,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
[addProjectEnvironmentItems],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const openAddProjectFlow = useCallback(() => {
|
|
|
|
|
const openAddProjectFlow = useCallback(async () => {
|
|
|
|
|
if (addProjectEnvironmentOptions.length > 1) {
|
|
|
|
|
pushPaletteView({
|
|
|
|
|
addonIcon: <FolderPlusIcon className={ADDON_ICON_CLASS} />,
|
|
|
|
@@ -610,7 +637,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startAddProjectBrowse(environmentId);
|
|
|
|
|
await startAddProjectBrowse(environmentId);
|
|
|
|
|
}, [
|
|
|
|
|
addProjectEnvironmentGroups,
|
|
|
|
|
addProjectEnvironmentOptions.length,
|
|
|
|
@@ -623,7 +650,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
clearOpenIntent();
|
|
|
|
|
openAddProjectFlow();
|
|
|
|
|
void openAddProjectFlow();
|
|
|
|
|
}, [clearOpenIntent, openAddProjectFlow, openIntent]);
|
|
|
|
|
|
|
|
|
|
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
|
|
|
|
@@ -687,7 +714,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
icon: <FolderPlusIcon className={ITEM_ICON_CLASS} />,
|
|
|
|
|
keepOpen: true,
|
|
|
|
|
run: async () => {
|
|
|
|
|
openAddProjectFlow();
|
|
|
|
|
await openAddProjectFlow();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -808,23 +835,28 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function browseTo(name: string): void {
|
|
|
|
|
const nextQuery = appendBrowsePathSegment(query, name);
|
|
|
|
|
setHighlightedItemValue(null);
|
|
|
|
|
setQuery(nextQuery);
|
|
|
|
|
setBrowseGeneration((generation) => generation + 1);
|
|
|
|
|
}
|
|
|
|
|
const browseTo = useCallback(
|
|
|
|
|
async (name: string): Promise<void> => {
|
|
|
|
|
const nextQuery = appendBrowsePathSegment(query, name);
|
|
|
|
|
await prefetchBrowsePath(getBrowseDirectoryPath(nextQuery));
|
|
|
|
|
setHighlightedItemValue(null);
|
|
|
|
|
setQuery(nextQuery);
|
|
|
|
|
setBrowseGeneration((generation) => generation + 1);
|
|
|
|
|
},
|
|
|
|
|
[prefetchBrowsePath, query],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function browseUp(): void {
|
|
|
|
|
const browseUp = useCallback(async (): Promise<void> => {
|
|
|
|
|
const parentPath = getBrowseParentPath(query);
|
|
|
|
|
if (parentPath === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await prefetchBrowsePath(parentPath);
|
|
|
|
|
setHighlightedItemValue(null);
|
|
|
|
|
setQuery(parentPath);
|
|
|
|
|
setBrowseGeneration((generation) => generation + 1);
|
|
|
|
|
}
|
|
|
|
|
}, [prefetchBrowsePath, query]);
|
|
|
|
|
|
|
|
|
|
// Resolve the add-project path from browse data when available. When the
|
|
|
|
|
// query has a trailing separator (e.g. "~/projects/foo/"), parentPath is the
|
|
|
|
@@ -847,7 +879,7 @@ function OpenCommandPaletteDialog() {
|
|
|
|
|
browseTo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let displayedGroups = filteredGroups;
|
|
|
|
|
let displayedGroups: ReadonlyArray<CommandPaletteGroup> = filteredGroups;
|
|
|
|
|
if (isBrowsing) {
|
|
|
|
|
displayedGroups = relativePathNeedsActiveProject ? [] : browseGroups;
|
|
|
|
|
}
|
|
|
|
|