Skip to content

Commit f00fa56

Browse files
committed
🎁 Add shrinkWorkspaceFolderCwdPairs to drop repeated CWDs
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 45f9ce7 commit f00fa56

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/vs/workbench/contrib/terminal/browser/terminalActions.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,23 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
5353
import { getIconId, getColorClass, getUriClasses } from 'vs/workbench/contrib/terminal/browser/terminalIcon';
5454
import { clearShellFileHistory, getCommandHistory } from 'vs/workbench/contrib/terminal/common/history';
5555
import { CATEGORIES } from 'vs/workbench/common/actions';
56+
import { IModelService } from 'vs/editor/common/services/model';
57+
import { ILanguageService } from 'vs/editor/common/languages/language';
58+
import { CancellationToken } from 'vs/base/common/cancellation';
59+
import { dirname } from 'vs/base/common/resources';
60+
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
61+
import { FileKind } from 'vs/platform/files/common/files';
5662

5763
export const switchTerminalActionViewItemSeparator = '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500';
5864
export const switchTerminalShowTabsTitle = localize('showTerminalTabs', "Show Tabs");
5965

66+
export interface WorkspaceFolderCwdPair {
67+
folder: IWorkspaceFolder;
68+
cwd: URI;
69+
isAbsolute: boolean;
70+
isOverridden: boolean;
71+
}
72+
6073
export async function getCwdForSplit(configHelper: ITerminalConfigHelper, instance: ITerminalInstance, folders?: IWorkspaceFolder[], commandService?: ICommandService): Promise<string | URI | undefined> {
6174
switch (configHelper.config.splitCwd) {
6275
case 'workspaceRoot':
@@ -2490,3 +2503,20 @@ function doWithInstance(accessor: ServicesAccessor, resource: unknown): ITermina
24902503
const instance = terminalService.getInstanceFromResource(castedResource) || terminalService.activeInstance;
24912504
return instance;
24922505
}
2506+
2507+
/**
2508+
* Drops repeated CWDs, if any, by keeping the one which best matches the workspace folder. It also preserves the original order.
2509+
*/
2510+
export function shrinkWorkspaceFolderCwdPairs(pairs: WorkspaceFolderCwdPair[]): WorkspaceFolderCwdPair[] {
2511+
const map = new Map<string, WorkspaceFolderCwdPair>();
2512+
for (const pair of pairs) {
2513+
const key = pair.cwd.toString();
2514+
const value = map.get(key);
2515+
if (!value || key === pair.folder.uri.toString()) {
2516+
map.set(key, pair);
2517+
}
2518+
}
2519+
const selectedPairs = new Set(map.values());
2520+
const selectedPairsInOrder = pairs.filter(x => selectedPairs.has(x));
2521+
return selectedPairsInOrder;
2522+
}

0 commit comments

Comments
 (0)