Skip to content

Commit fbf402c

Browse files
lszomorubpasero
andauthored
Editors - pathsToEditors should ignore folders (microsoft#136359) (microsoft#136840)
Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 96c468b commit fbf402c

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

src/vs/platform/windows/common/windows.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
99
import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
1010
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1111
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
12+
import { FileType } from 'vs/platform/files/common/files';
1213
import { LogLevel } from 'vs/platform/log/common/log';
1314
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1415

@@ -187,13 +188,19 @@ export interface IPathData {
187188

188189
// a hint that the file exists. if true, the
189190
// file exists, if false it does not. with
190-
// undefined the state is unknown.
191+
// `undefined` the state is unknown.
191192
readonly exists?: boolean;
192193

193-
// Specifies if the file should be only be opened if it exists
194+
// a hint about the file type of this path.
195+
// with `undefined` the type is unknown.
196+
readonly type?: FileType;
197+
198+
// Specifies if the file should be only be opened
199+
// if it exists
194200
readonly openOnlyIfExists?: boolean;
195201

196-
// Specifies an optional id to override the editor used to edit the resource, e.g. custom editor.
202+
// Specifies an optional id to override the editor
203+
// used to edit the resource, e.g. custom editor.
197204
readonly editorOverrideId?: string;
198205
}
199206

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
3030
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService';
3131
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
3232
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
33-
import { IFileService } from 'vs/platform/files/common/files';
33+
import { FileType, IFileService } from 'vs/platform/files/common/files';
3434
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3535
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
3636
import { ILogService } from 'vs/platform/log/common/log';
@@ -989,21 +989,29 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
989989
return undefined;
990990
}
991991

992-
return { workspace: { id: workspace.id, configPath: workspace.configPath }, remoteAuthority: workspace.remoteAuthority, exists: true, transient: workspace.transient };
992+
return {
993+
workspace: { id: workspace.id, configPath: workspace.configPath },
994+
type: FileType.File,
995+
exists: true,
996+
remoteAuthority: workspace.remoteAuthority,
997+
transient: workspace.transient
998+
};
993999
}
9941000
}
9951001

9961002
return {
9971003
fileUri: URI.file(path),
998-
selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined,
999-
exists: true
1004+
type: FileType.File,
1005+
exists: true,
1006+
selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined
10001007
};
10011008
}
10021009

10031010
// Folder
10041011
else if (pathStat.isDirectory()) {
10051012
return {
10061013
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
1014+
type: FileType.Directory,
10071015
exists: true
10081016
};
10091017
}
@@ -1015,6 +1023,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10151023
else if (!isWindows && path === '/dev/null') {
10161024
return {
10171025
fileUri: URI.file(path),
1026+
type: FileType.File,
10181027
exists: true
10191028
};
10201029
}
@@ -1028,6 +1037,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10281037
if (options.ignoreFileNotFound) {
10291038
return {
10301039
fileUri,
1040+
type: FileType.File,
10311041
exists: false
10321042
};
10331043
}

src/vs/workbench/common/editor.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
1717
import { IEncodingSupport, IModeSupport } from 'vs/workbench/services/textfile/common/textfiles';
1818
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
1919
import { ICompositeControl, IComposite } from 'vs/workbench/common/composite';
20-
import { IFileService } from 'vs/platform/files/common/files';
20+
import { FileType, IFileService } from 'vs/platform/files/common/files';
2121
import { IPathData } from 'vs/platform/windows/common/windows';
2222
import { coalesce } from 'vs/base/common/arrays';
2323
import { IExtUri } from 'vs/base/common/resources';
@@ -1138,11 +1138,25 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService
11381138
return;
11391139
}
11401140

1141-
const exists = (typeof path.exists === 'boolean') ? path.exists : await fileService.exists(resource);
1141+
let exists = path.exists;
1142+
let type = path.type;
1143+
if (typeof exists !== 'boolean' || typeof type !== 'number') {
1144+
try {
1145+
type = (await fileService.resolve(resource)).isFile ? FileType.File : FileType.Unknown;
1146+
exists = true;
1147+
} catch {
1148+
exists = false;
1149+
}
1150+
}
1151+
11421152
if (!exists && path.openOnlyIfExists) {
11431153
return;
11441154
}
11451155

1156+
if (type !== FileType.File) {
1157+
return;
1158+
}
1159+
11461160
const options: ITextEditorOptions = {
11471161
selection: exists ? path.selection : undefined,
11481162
pinned: true,

0 commit comments

Comments
 (0)