From e31a18ea8c6cf53e205e481c98f290e6d8c20460 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 4 Nov 2021 21:03:04 +0100 Subject: [PATCH] Editors - pathsToEditors should ignore folders (#136359) Co-authored-by: Benjamin Pasero --- src/vs/platform/windows/common/windows.ts | 13 ++++++++++--- .../electron-main/windowsMainService.ts | 18 ++++++++++++++---- src/vs/workbench/common/editor.ts | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index a18b71e8a0314..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,13 +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; - // Specifies if the file should be only be opened if it exists + // 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 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 3806e8921612d..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,14 +988,21 @@ 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 }, + type: FileType.File, + exists: true, + remoteAuthority: workspace.remoteAuthority, + transient: workspace.transient + }; } } return { fileUri: URI.file(path), - selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined, - exists: true + type: FileType.File, + exists: true, + selection: lineNumber ? { startLineNumber: lineNumber, startColumn: columnNumber || 1 } : undefined }; } @@ -1003,6 +1010,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (pathStat.isDirectory()) { return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), + type: FileType.Directory, exists: true }; } @@ -1014,6 +1022,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic else if (!isWindows && path === '/dev/null') { return { fileUri: URI.file(path), + type: FileType.File, exists: true }; } @@ -1027,6 +1036,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic if (options.ignoreFileNotFound) { return { fileUri, + type: FileType.File, exists: false }; } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 3ec2663a9ff7b..682522d5688f4 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 { 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'; @@ -1138,11 +1138,25 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService return; } - const exists = (typeof path.exists === 'boolean') ? path.exists : await fileService.exists(resource); + let exists = path.exists; + let type = path.type; + if (typeof exists !== 'boolean' || typeof type !== 'number') { + try { + type = (await fileService.resolve(resource)).isFile ? FileType.File : FileType.Unknown; + exists = true; + } catch { + exists = false; + } + } + if (!exists && path.openOnlyIfExists) { return; } + if (type !== FileType.File) { + return; + } + const options: ITextEditorOptions = { selection: exists ? path.selection : undefined, pinned: true,