diff --git a/src/vs/code/node/windowsFinder.ts b/src/vs/code/node/windowsFinder.ts index 2579cc33ba3..61d9427fa69 100644 --- a/src/vs/code/node/windowsFinder.ts +++ b/src/vs/code/node/windowsFinder.ts @@ -5,8 +5,6 @@ 'use strict'; -import * as path from 'path'; -import * as fs from 'fs'; import * as platform from 'vs/base/common/platform'; import * as paths from 'vs/base/common/paths'; import { OpenContext } from 'vs/platform/windows/common/windows'; @@ -35,22 +33,9 @@ export interface IBestWindowOrFolderOptions { export function findBestWindowOrFolderForFile({ windows, newWindow, reuseWindow, context, filePath, userHome, codeSettingsFolder, workspaceResolver }: IBestWindowOrFolderOptions): W | string { if (!newWindow && filePath && (context === OpenContext.DESKTOP || context === OpenContext.CLI || context === OpenContext.DOCK)) { const windowOnFilePath = findWindowOnFilePath(windows, filePath, workspaceResolver); - - // 1) window wins if it has a workspace opened - if (windowOnFilePath && !!windowOnFilePath.openedWorkspace) { + if (windowOnFilePath) { return windowOnFilePath; } - - // 2) window wins if it has a folder opened that is more specific than settings folder - const folderWithCodeSettings = !reuseWindow && findFolderWithCodeSettings(filePath, userHome, codeSettingsFolder); - if (windowOnFilePath && !(folderWithCodeSettings && folderWithCodeSettings.length > windowOnFilePath.openedFolderPath.length)) { - return windowOnFilePath; - } - - // 3) finally return path to folder with settings - if (folderWithCodeSettings) { - return folderWithCodeSettings; - } } return !newWindow ? getLastActiveWindow(windows) : null; @@ -77,36 +62,6 @@ function findWindowOnFilePath(windows: W[], filePath: s return null; } -function findFolderWithCodeSettings(filePath: string, userHome?: string, codeSettingsFolder?: string): string { - let folder = path.dirname(paths.normalize(filePath, true)); - let homeFolder = userHome && paths.normalize(userHome, true); - if (!platform.isLinux) { - homeFolder = homeFolder && homeFolder.toLowerCase(); - } - - let previous = null; - while (folder !== previous) { - if (hasCodeSettings(folder, homeFolder, codeSettingsFolder)) { - return folder; - } - - previous = folder; - folder = path.dirname(folder); - } - - return null; -} - -function hasCodeSettings(folder: string, normalizedUserHome?: string, codeSettingsFolder = '.vscode') { - try { - return fs.statSync(path.join(folder, codeSettingsFolder, 'settings.json')).isFile(); - } catch (err) { - // assume impossible to access - } - - return false; -} - export function getLastActiveWindow(windows: W[]): W { const lastFocusedDate = Math.max.apply(Math, windows.map(window => window.lastFocusTime)); diff --git a/src/vs/code/test/node/windowsFinder.test.ts b/src/vs/code/test/node/windowsFinder.test.ts index 6084a62ee43..985f06f0bbc 100644 --- a/src/vs/code/test/node/windowsFinder.test.ts +++ b/src/vs/code/test/node/windowsFinder.test.ts @@ -48,25 +48,22 @@ suite('WindowsFinder', () => { })), null); assert.equal(findBestWindowOrFolderForFile(options({ filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'), - newWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later. + newWindow: true })), null); assert.equal(findBestWindowOrFolderForFile(options({ filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'), - reuseWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later. + reuseWindow: true })), null); assert.equal(findBestWindowOrFolderForFile(options({ filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'), context: OpenContext.API })), null); - }); - - test('New window with folder when no windows exist', () => { assert.equal(findBestWindowOrFolderForFile(options({ filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt') - })), path.join(fixturesFolder, 'vscode_folder')); + })), null); assert.equal(findBestWindowOrFolderForFile(options({ filePath: path.join(fixturesFolder, 'vscode_folder', 'new_folder', 'new_file.txt') - })), path.join(fixturesFolder, 'vscode_folder')); + })), null); }); test('New window without folder when windows exist', () => { @@ -106,19 +103,11 @@ suite('WindowsFinder', () => { windows, filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt') })), vscodeFolderWindow); - }); - - test('Existing window wins over vscode folder if more specific', () => { const window = { lastFocusTime: 1, openedFolderPath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder') }; assert.equal(findBestWindowOrFolderForFile(options({ windows: [window], filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt') })), window); - // check - assert.equal(findBestWindowOrFolderForFile(options({ - windows: [window], - filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder2', 'subfolder', 'file.txt') - })), path.join(fixturesFolder, 'vscode_folder')); }); test('More specific existing window wins', () => { @@ -130,25 +119,6 @@ suite('WindowsFinder', () => { })), nestedFolderWindow); }); - test('VSCode folder wins over existing window if more specific', () => { - const window = { lastFocusTime: 1, openedFolderPath: path.join(fixturesFolder, 'vscode_folder') }; - assert.equal(findBestWindowOrFolderForFile(options({ - windows: [window], - filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt') - })), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder')); - // check - assert.equal(findBestWindowOrFolderForFile(options({ - windows: [window], - filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt') - })), window); - }); - - test('More specific VSCode folder wins', () => { - assert.equal(findBestWindowOrFolderForFile(options({ - filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt') - })), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder')); - }); - test('Workspace folder wins', () => { const window = { lastFocusTime: 1, openedWorkspace: testWorkspace }; assert.equal(findBestWindowOrFolderForFile(options({