Skip to content

Commit 67d7705

Browse files
committed
perf - avoid redundant statSync when opening files via macOS dock
1 parent 7fb2e93 commit 67d7705

File tree

1 file changed

+2
-20
lines changed
  • src/vs/code/electron-main

1 file changed

+2
-20
lines changed

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { app, BrowserWindow, dialog, protocol, session, Session, systemPreferences, WebFrameMain } from 'electron';
77
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain';
8-
import { statSync } from 'fs';
98
import { hostname, release } from 'os';
109
import { VSBuffer } from 'vs/base/common/buffer';
1110
import { toErrorMessage } from 'vs/base/common/errorMessage';
@@ -364,7 +363,7 @@ export class CodeApplication extends Disposable {
364363
event.preventDefault();
365364

366365
// Keep in array because more might come!
367-
macOpenFileURIs.push(this.getWindowOpenableFromPathSync(path));
366+
macOpenFileURIs.push(hasWorkspaceFileExtension(path) ? { workspaceUri: URI.file(path) } : { fileUri: URI.file(path) });
368367

369368
// Clear previous handler if any
370369
if (runningTimeout !== undefined) {
@@ -1018,7 +1017,7 @@ export class CodeApplication extends Disposable {
10181017
return windowsMainService.open({
10191018
context: OpenContext.DOCK,
10201019
cli: args,
1021-
urisToOpen: macOpenFiles.map(file => this.getWindowOpenableFromPathSync(file)),
1020+
urisToOpen: macOpenFiles.map(path => (hasWorkspaceFileExtension(path) ? { workspaceUri: URI.file(path) } : { fileUri: URI.file(path) })),
10221021
noRecentEntry,
10231022
waitMarkerFileURI,
10241023
initialStartup: true,
@@ -1110,23 +1109,6 @@ export class CodeApplication extends Disposable {
11101109
return undefined;
11111110
}
11121111

1113-
private getWindowOpenableFromPathSync(path: string): IWindowOpenable {
1114-
try {
1115-
const fileStat = statSync(path);
1116-
if (fileStat.isDirectory()) {
1117-
return { folderUri: URI.file(path) };
1118-
}
1119-
1120-
if (hasWorkspaceFileExtension(path)) {
1121-
return { workspaceUri: URI.file(path) };
1122-
}
1123-
} catch (error) {
1124-
// ignore errors
1125-
}
1126-
1127-
return { fileUri: URI.file(path) };
1128-
}
1129-
11301112
private afterWindowOpen(accessor: ServicesAccessor, sharedProcess: SharedProcess): void {
11311113
const telemetryService = accessor.get(ITelemetryService);
11321114
const updateService = accessor.get(IUpdateService);

0 commit comments

Comments
 (0)