From 03555aac7837ffbe4e4bc580389302efce5bec50 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Wed, 31 Oct 2018 17:33:33 +0100 Subject: [PATCH 1/2] Fix #5324: Ask before switching workspaces Also, verify that we are able to find a workspace root at all. Fixes #5324 --- vscode-dotty/src/extension.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/vscode-dotty/src/extension.ts b/vscode-dotty/src/extension.ts index 4c42966243cc..e15d20cc14ee 100644 --- a/vscode-dotty/src/extension.ts +++ b/vscode-dotty/src/extension.ts @@ -68,8 +68,9 @@ export function activate(context: ExtensionContext) { } else if (!fs.existsSync(disableDottyIDEFile)) { if (!vscode.workspace.workspaceFolders) { - if (vscode.window.activeTextEditor) { - setWorkspaceAndReload(vscode.window.activeTextEditor.document) + const editor = vscode.window.activeTextEditor + if (editor && editor.document.uri.fsPath && editor.document.uri.fsPath.length > 0) { + setWorkspaceAndReload(editor.document) } } else { let configuredProject: Thenable = Promise.resolve() @@ -108,7 +109,16 @@ export function activate(context: ExtensionContext) { function setWorkspaceAndReload(document: vscode.TextDocument) { const documentPath = path.parse(document.uri.fsPath).dir const workspaceRoot = findWorkspaceRoot(documentPath) || documentPath - vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) }) + + vscode.window.showInformationMessage( + `It looks like '${workspaceRoot}' is the root of your workspace. ` + + 'Would you like to open it?', + 'Yes', 'No' + ).then((value: String | undefined) => { + if (value === 'Yes') { + vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) }) + } + }) } /** From 78cbc3bdbcda44af406dd5e08740ae8e90b3b6ec Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Wed, 31 Oct 2018 17:47:04 +0100 Subject: [PATCH 2/2] Address review comment --- vscode-dotty/src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode-dotty/src/extension.ts b/vscode-dotty/src/extension.ts index e15d20cc14ee..2ba9f597a32d 100644 --- a/vscode-dotty/src/extension.ts +++ b/vscode-dotty/src/extension.ts @@ -111,7 +111,7 @@ function setWorkspaceAndReload(document: vscode.TextDocument) { const workspaceRoot = findWorkspaceRoot(documentPath) || documentPath vscode.window.showInformationMessage( - `It looks like '${workspaceRoot}' is the root of your workspace. ` + + `It looks like '${workspaceRoot}' is the root of your Scala workspace. ` + 'Would you like to open it?', 'Yes', 'No' ).then((value: String | undefined) => {