Skip to content

Commit e31a18e

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

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
@@ -29,7 +29,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2929
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService';
3030
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
3131
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
32-
import { IFileService } from 'vs/platform/files/common/files';
32+
import { FileType, IFileService } from 'vs/platform/files/common/files';
3333
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3434
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
3535
import { ILogService } from 'vs/platform/log/common/log';
@@ -988,21 +988,29 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
988988
return undefined;
989989
}
990990

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

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

10021009
// Folder
10031010
else if (pathStat.isDirectory()) {
10041011
return {
10051012
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
1013+
type: FileType.Directory,
10061014
exists: true
10071015
};
10081016
}
@@ -1014,6 +1022,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10141022
else if (!isWindows && path === '/dev/null') {
10151023
return {
10161024
fileUri: URI.file(path),
1025+
type: FileType.File,
10171026
exists: true
10181027
};
10191028
}
@@ -1027,6 +1036,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10271036
if (options.ignoreFileNotFound) {
10281037
return {
10291038
fileUri,
1039+
type: FileType.File,
10301040
exists: false
10311041
};
10321042
}

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)