Skip to content

Commit 6fe0c32

Browse files
committed
Don't check parent folders for settings / settings folder (fixes microsoft#45121)
1 parent 4f399a4 commit 6fe0c32

2 files changed

Lines changed: 5 additions & 80 deletions

File tree

src/vs/code/node/windowsFinder.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
'use strict';
77

8-
import * as path from 'path';
9-
import * as fs from 'fs';
108
import * as platform from 'vs/base/common/platform';
119
import * as paths from 'vs/base/common/paths';
1210
import { OpenContext } from 'vs/platform/windows/common/windows';
@@ -35,22 +33,9 @@ export interface IBestWindowOrFolderOptions<W extends ISimpleWindow> {
3533
export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows, newWindow, reuseWindow, context, filePath, userHome, codeSettingsFolder, workspaceResolver }: IBestWindowOrFolderOptions<W>): W | string {
3634
if (!newWindow && filePath && (context === OpenContext.DESKTOP || context === OpenContext.CLI || context === OpenContext.DOCK)) {
3735
const windowOnFilePath = findWindowOnFilePath(windows, filePath, workspaceResolver);
38-
39-
// 1) window wins if it has a workspace opened
40-
if (windowOnFilePath && !!windowOnFilePath.openedWorkspace) {
36+
if (windowOnFilePath) {
4137
return windowOnFilePath;
4238
}
43-
44-
// 2) window wins if it has a folder opened that is more specific than settings folder
45-
const folderWithCodeSettings = !reuseWindow && findFolderWithCodeSettings(filePath, userHome, codeSettingsFolder);
46-
if (windowOnFilePath && !(folderWithCodeSettings && folderWithCodeSettings.length > windowOnFilePath.openedFolderPath.length)) {
47-
return windowOnFilePath;
48-
}
49-
50-
// 3) finally return path to folder with settings
51-
if (folderWithCodeSettings) {
52-
return folderWithCodeSettings;
53-
}
5439
}
5540

5641
return !newWindow ? getLastActiveWindow(windows) : null;
@@ -77,36 +62,6 @@ function findWindowOnFilePath<W extends ISimpleWindow>(windows: W[], filePath: s
7762
return null;
7863
}
7964

80-
function findFolderWithCodeSettings(filePath: string, userHome?: string, codeSettingsFolder?: string): string {
81-
let folder = path.dirname(paths.normalize(filePath, true));
82-
let homeFolder = userHome && paths.normalize(userHome, true);
83-
if (!platform.isLinux) {
84-
homeFolder = homeFolder && homeFolder.toLowerCase();
85-
}
86-
87-
let previous = null;
88-
while (folder !== previous) {
89-
if (hasCodeSettings(folder, homeFolder, codeSettingsFolder)) {
90-
return folder;
91-
}
92-
93-
previous = folder;
94-
folder = path.dirname(folder);
95-
}
96-
97-
return null;
98-
}
99-
100-
function hasCodeSettings(folder: string, normalizedUserHome?: string, codeSettingsFolder = '.vscode') {
101-
try {
102-
return fs.statSync(path.join(folder, codeSettingsFolder, 'settings.json')).isFile();
103-
} catch (err) {
104-
// assume impossible to access
105-
}
106-
107-
return false;
108-
}
109-
11065
export function getLastActiveWindow<W extends ISimpleWindow>(windows: W[]): W {
11166
const lastFocusedDate = Math.max.apply(Math, windows.map(window => window.lastFocusTime));
11267

src/vs/code/test/node/windowsFinder.test.ts

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,22 @@ suite('WindowsFinder', () => {
4848
})), null);
4949
assert.equal(findBestWindowOrFolderForFile(options({
5050
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
51-
newWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later.
51+
newWindow: true
5252
})), null);
5353
assert.equal(findBestWindowOrFolderForFile(options({
5454
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
55-
reuseWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later.
55+
reuseWindow: true
5656
})), null);
5757
assert.equal(findBestWindowOrFolderForFile(options({
5858
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
5959
context: OpenContext.API
6060
})), null);
61-
});
62-
63-
test('New window with folder when no windows exist', () => {
6461
assert.equal(findBestWindowOrFolderForFile(options({
6562
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt')
66-
})), path.join(fixturesFolder, 'vscode_folder'));
63+
})), null);
6764
assert.equal(findBestWindowOrFolderForFile(options({
6865
filePath: path.join(fixturesFolder, 'vscode_folder', 'new_folder', 'new_file.txt')
69-
})), path.join(fixturesFolder, 'vscode_folder'));
66+
})), null);
7067
});
7168

7269
test('New window without folder when windows exist', () => {
@@ -106,19 +103,11 @@ suite('WindowsFinder', () => {
106103
windows,
107104
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt')
108105
})), vscodeFolderWindow);
109-
});
110-
111-
test('Existing window wins over vscode folder if more specific', () => {
112106
const window = { lastFocusTime: 1, openedFolderPath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder') };
113107
assert.equal(findBestWindowOrFolderForFile(options({
114108
windows: [window],
115109
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt')
116110
})), window);
117-
// check
118-
assert.equal(findBestWindowOrFolderForFile(options({
119-
windows: [window],
120-
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder2', 'subfolder', 'file.txt')
121-
})), path.join(fixturesFolder, 'vscode_folder'));
122111
});
123112

124113
test('More specific existing window wins', () => {
@@ -130,25 +119,6 @@ suite('WindowsFinder', () => {
130119
})), nestedFolderWindow);
131120
});
132121

133-
test('VSCode folder wins over existing window if more specific', () => {
134-
const window = { lastFocusTime: 1, openedFolderPath: path.join(fixturesFolder, 'vscode_folder') };
135-
assert.equal(findBestWindowOrFolderForFile(options({
136-
windows: [window],
137-
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt')
138-
})), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder'));
139-
// check
140-
assert.equal(findBestWindowOrFolderForFile(options({
141-
windows: [window],
142-
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt')
143-
})), window);
144-
});
145-
146-
test('More specific VSCode folder wins', () => {
147-
assert.equal(findBestWindowOrFolderForFile(options({
148-
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt')
149-
})), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder'));
150-
});
151-
152122
test('Workspace folder wins', () => {
153123
const window = { lastFocusTime: 1, openedWorkspace: testWorkspace };
154124
assert.equal(findBestWindowOrFolderForFile(options({

0 commit comments

Comments
 (0)