Skip to content

Commit

Permalink
Editors - pathsToEditors should ignore folders (#136359)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Pasero <[email protected]>
  • Loading branch information
lszomoru and bpasero authored Nov 4, 2021
1 parent 8ad817b commit e31a18e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/vs/platform/windows/common/windows.ts
Original file line number Diff line number Diff line change
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

This comment has been minimized.

Copy link
@jogo-

jogo- Nov 8, 2021

Contributor

Specifies if the file should be only be opened -> Specifies if the file should 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit e31a18e

Please sign in to comment.