From 4353ca79b501ec0dedcc4ded60859e54c33c5ccd Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Wed, 3 Nov 2021 15:25:35 +0100 Subject: [PATCH 1/4] pathsToEditors should ignore folders --- src/vs/workbench/common/editor.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index d363466b598a3..b547501a6c038 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -1133,6 +1133,11 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService return; } + const fileStat = await fileService.resolve(resource); + if (fileStat.isDirectory) { + return; + } + const canHandleResource = await fileService.canHandleResource(resource); if (!canHandleResource) { return; From 9c8fa78c168c13f90bfd692f62210b3f1ffc8d8d Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 4 Nov 2021 09:24:03 +0100 Subject: [PATCH 2/4] Pull request feedback --- src/vs/workbench/common/editor.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index b547501a6c038..9c45b64640c45 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -17,7 +17,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { IEncodingSupport, IModeSupport } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ICompositeControl, IComposite } from 'vs/workbench/common/composite'; -import { IFileService } from 'vs/platform/files/common/files'; +import { IFileService, IFileStat } from 'vs/platform/files/common/files'; import { IPathData } from 'vs/platform/windows/common/windows'; import { coalesce } from 'vs/base/common/arrays'; import { IExtUri } from 'vs/base/common/resources'; @@ -1133,17 +1133,20 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService return; } - const fileStat = await fileService.resolve(resource); - if (fileStat.isDirectory) { - return; - } - const canHandleResource = await fileService.canHandleResource(resource); if (!canHandleResource) { return; } - const exists = (typeof path.exists === 'boolean') ? path.exists : await fileService.exists(resource); + let stat: IFileStat | undefined; + try { + stat = await fileService.resolve(resource); + if (stat.isDirectory) { + return; + } + } catch { } + + const exists = (typeof path.exists === 'boolean') ? path.exists : !!stat; if (!exists && path.openOnlyIfExists) { return; } From 961edf5c2a6c12743a5c6ddd4bd56e99e2f17504 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 4 Nov 2021 13:15:59 +0100 Subject: [PATCH 3/4] Add isFile to IPathData --- src/vs/platform/windows/common/windows.ts | 6 +++++ .../electron-main/windowsMainService.ts | 14 ++++++---- src/vs/workbench/common/editor.ts | 26 ++++++++++++------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index a18b71e8a0314..a9ab7cf975ba5 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -190,6 +190,12 @@ export interface IPathData { // undefined the state is unknown. readonly exists?: boolean; + // a hint that the resource is a file. if + // true, the resource is a file, if false + // it is a folder. with undefined the type + // is unknown. + readonly isFile?: boolean; + // Specifies if the file should be only be opened if it exists readonly openOnlyIfExists?: boolean; diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 3806e8921612d..79e1464c29ffb 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -988,14 +988,15 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return undefined; } - return { workspace: { id: workspace.id, configPath: workspace.configPath }, remoteAuthority: workspace.remoteAuthority, exists: true, transient: workspace.transient }; + return { workspace: { id: workspace.id, configPath: workspace.configPath }, remoteAuthority: workspace.remoteAuthority, exists: true, isFile: true, transient: workspace.transient }; } } return { fileUri: URI.file(path), selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined, - exists: true + exists: true, + isFile: true }; } @@ -1003,7 +1004,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (pathStat.isDirectory()) { return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), - exists: true + exists: true, + isFile: false }; } @@ -1014,7 +1016,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (!isWindows && path === '/dev/null') { return { fileUri: URI.file(path), - exists: true + exists: true, + isFile: true }; } } catch (error) { @@ -1027,7 +1030,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic if (options.ignoreFileNotFound) { return { fileUri, - exists: false + exists: false, + isFile: true }; } } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 9c45b64640c45..a79433d92d5f9 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -1138,16 +1138,24 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService return; } - let stat: IFileStat | undefined; - try { - stat = await fileService.resolve(resource); - if (stat.isDirectory) { - return; - } - } catch { } + let exists = path.exists; + let isFile = path.isFile; + if (typeof exists !== 'boolean' || typeof isFile !== 'boolean') { + let stat: IFileStat | undefined; + + try { + stat = await fileService.resolve(resource); + isFile = typeof isFile === 'boolean' ? isFile : stat.isFile; + } catch { } + + exists = typeof exists === 'boolean' ? exists : !!stat; + } + + if (exists === false && path.openOnlyIfExists) { + return; + } - const exists = (typeof path.exists === 'boolean') ? path.exists : !!stat; - if (!exists && path.openOnlyIfExists) { + if (isFile === false) { return; } From 80eaf32da5ba1428a0ad592d43c2bd4e0abeae5d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 4 Nov 2021 19:58:26 +0100 Subject: [PATCH 4/4] :lipstick: --- src/vs/platform/windows/common/windows.ts | 17 ++++++------ .../electron-main/windowsMainService.ts | 26 ++++++++++++------- src/vs/workbench/common/editor.ts | 22 +++++++--------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index a9ab7cf975ba5..20f12e9bc7da8 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -9,6 +9,7 @@ import { URI, UriComponents } from 'vs/base/common/uri'; import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; +import { FileType } from 'vs/platform/files/common/files'; import { LogLevel } from 'vs/platform/log/common/log'; import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; @@ -187,19 +188,19 @@ export interface IPathData { // a hint that the file exists. if true, the // file exists, if false it does not. with - // undefined the state is unknown. + // `undefined` the state is unknown. readonly exists?: boolean; - // a hint that the resource is a file. if - // true, the resource is a file, if false - // it is a folder. with undefined the type - // is unknown. - readonly isFile?: boolean; + // a hint about the file type of this path. + // with `undefined` the type is unknown. + readonly type?: FileType; - // Specifies if the file should be only be opened if it exists + // Specifies if the file should be only be opened + // if it exists readonly openOnlyIfExists?: boolean; - // Specifies an optional id to override the editor used to edit the resource, e.g. custom editor. + // Specifies an optional id to override the editor + // used to edit the resource, e.g. custom editor. readonly editorOverrideId?: string; } diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 79e1464c29ffb..8720d6f7f168d 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -29,7 +29,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService'; import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService'; -import { IFileService } from 'vs/platform/files/common/files'; +import { FileType, IFileService } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; import { ILogService } from 'vs/platform/log/common/log'; @@ -988,15 +988,21 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic return undefined; } - return { workspace: { id: workspace.id, configPath: workspace.configPath }, remoteAuthority: workspace.remoteAuthority, exists: true, isFile: true, transient: workspace.transient }; + return { + workspace: { id: workspace.id, configPath: workspace.configPath }, + type: FileType.File, + exists: true, + remoteAuthority: workspace.remoteAuthority, + transient: workspace.transient + }; } } return { fileUri: URI.file(path), - selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined, + type: FileType.File, exists: true, - isFile: true + selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined }; } @@ -1004,8 +1010,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (pathStat.isDirectory()) { return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), - exists: true, - isFile: false + type: FileType.Directory, + exists: true }; } @@ -1016,8 +1022,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (!isWindows && path === '/dev/null') { return { fileUri: URI.file(path), - exists: true, - isFile: true + type: FileType.File, + exists: true }; } } catch (error) { @@ -1030,8 +1036,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic if (options.ignoreFileNotFound) { return { fileUri, - exists: false, - isFile: true + type: FileType.File, + exists: false }; } } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index a79433d92d5f9..22bc6b72419b9 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -17,7 +17,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { IEncodingSupport, IModeSupport } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ICompositeControl, IComposite } from 'vs/workbench/common/composite'; -import { IFileService, IFileStat } from 'vs/platform/files/common/files'; +import { FileType, IFileService } from 'vs/platform/files/common/files'; import { IPathData } from 'vs/platform/windows/common/windows'; import { coalesce } from 'vs/base/common/arrays'; import { IExtUri } from 'vs/base/common/resources'; @@ -1139,23 +1139,21 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService } let exists = path.exists; - let isFile = path.isFile; - if (typeof exists !== 'boolean' || typeof isFile !== 'boolean') { - let stat: IFileStat | undefined; - + let type = path.type; + if (typeof exists !== 'boolean' || typeof type !== 'number') { try { - stat = await fileService.resolve(resource); - isFile = typeof isFile === 'boolean' ? isFile : stat.isFile; - } catch { } - - exists = typeof exists === 'boolean' ? exists : !!stat; + type = (await fileService.resolve(resource)).isFile ? FileType.File : FileType.Unknown; + exists = true; + } catch { + exists = false; + } } - if (exists === false && path.openOnlyIfExists) { + if (!exists && path.openOnlyIfExists) { return; } - if (isFile === false) { + if (type !== FileType.File) { return; }