Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editors - pathsToEditors should ignore folders #136359

Merged
merged 4 commits into from Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/vs/platform/windows/common/windows.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 14 additions & 4 deletions src/vs/platform/windows/electron-main/windowsMainService.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -988,21 +988,29 @@ 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
};
}

// Folder
else if (pathStat.isDirectory()) {
return {
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
type: FileType.Directory,
exists: true
};
}
Expand All @@ -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
};
}
Expand All @@ -1027,6 +1036,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
if (options.ignoreFileNotFound) {
return {
fileUri,
type: FileType.File,
exists: false
};
}
Expand Down
18 changes: 16 additions & 2 deletions src/vs/workbench/common/editor.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down