@@ -53,10 +53,23 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
53
53
import { getIconId , getColorClass , getUriClasses } from 'vs/workbench/contrib/terminal/browser/terminalIcon' ;
54
54
import { clearShellFileHistory , getCommandHistory } from 'vs/workbench/contrib/terminal/common/history' ;
55
55
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' ;
56
62
57
63
export const switchTerminalActionViewItemSeparator = '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500' ;
58
64
export const switchTerminalShowTabsTitle = localize ( 'showTerminalTabs' , "Show Tabs" ) ;
59
65
66
+ export interface WorkspaceFolderCwdPair {
67
+ folder : IWorkspaceFolder ;
68
+ cwd : URI ;
69
+ isAbsolute : boolean ;
70
+ isOverridden : boolean ;
71
+ }
72
+
60
73
export async function getCwdForSplit ( configHelper : ITerminalConfigHelper , instance : ITerminalInstance , folders ?: IWorkspaceFolder [ ] , commandService ?: ICommandService ) : Promise < string | URI | undefined > {
61
74
switch ( configHelper . config . splitCwd ) {
62
75
case 'workspaceRoot' :
@@ -2490,3 +2503,20 @@ function doWithInstance(accessor: ServicesAccessor, resource: unknown): ITermina
2490
2503
const instance = terminalService . getInstanceFromResource ( castedResource ) || terminalService . activeInstance ;
2491
2504
return instance ;
2492
2505
}
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