Skip to content

Commit 03555aa

Browse files
committed
Fix #5324: Ask before switching workspaces
Also, verify that we are able to find a workspace root at all. Fixes #5324
1 parent 0fcbfdb commit 03555aa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

vscode-dotty/src/extension.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export function activate(context: ExtensionContext) {
6868
} else if (!fs.existsSync(disableDottyIDEFile)) {
6969

7070
if (!vscode.workspace.workspaceFolders) {
71-
if (vscode.window.activeTextEditor) {
72-
setWorkspaceAndReload(vscode.window.activeTextEditor.document)
71+
const editor = vscode.window.activeTextEditor
72+
if (editor && editor.document.uri.fsPath && editor.document.uri.fsPath.length > 0) {
73+
setWorkspaceAndReload(editor.document)
7374
}
7475
} else {
7576
let configuredProject: Thenable<void> = Promise.resolve()
@@ -108,7 +109,16 @@ export function activate(context: ExtensionContext) {
108109
function setWorkspaceAndReload(document: vscode.TextDocument) {
109110
const documentPath = path.parse(document.uri.fsPath).dir
110111
const workspaceRoot = findWorkspaceRoot(documentPath) || documentPath
111-
vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) })
112+
113+
vscode.window.showInformationMessage(
114+
`It looks like '${workspaceRoot}' is the root of your workspace. ` +
115+
'Would you like to open it?',
116+
'Yes', 'No'
117+
).then((value: String | undefined) => {
118+
if (value === 'Yes') {
119+
vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) })
120+
}
121+
})
112122
}
113123

114124
/**

0 commit comments

Comments
 (0)