Skip to content

Commit 94d70d4

Browse files
authored
Merge pull request #5353 from dotty-staging/fix/5324
Fix #5324: Ask before switching workspaces
2 parents 5a465af + 78cbc3b commit 94d70d4

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
@@ -76,8 +76,9 @@ export function activate(context: ExtensionContext) {
7676
} else if (!fs.existsSync(disableDottyIDEFile)) {
7777

7878
if (!vscode.workspace.workspaceFolders) {
79-
if (vscode.window.activeTextEditor) {
80-
setWorkspaceAndReload(vscode.window.activeTextEditor.document)
79+
const editor = vscode.window.activeTextEditor
80+
if (editor && editor.document.uri.fsPath && editor.document.uri.fsPath.length > 0) {
81+
setWorkspaceAndReload(editor.document)
8182
}
8283
} else {
8384
let configuredProject: Thenable<void> = Promise.resolve()
@@ -116,7 +117,16 @@ export function activate(context: ExtensionContext) {
116117
function setWorkspaceAndReload(document: vscode.TextDocument) {
117118
const documentPath = path.parse(document.uri.fsPath).dir
118119
const workspaceRoot = findWorkspaceRoot(documentPath) || documentPath
119-
vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) })
120+
121+
vscode.window.showInformationMessage(
122+
`It looks like '${workspaceRoot}' is the root of your Scala workspace. ` +
123+
'Would you like to open it?',
124+
'Yes', 'No'
125+
).then((value: String | undefined) => {
126+
if (value === 'Yes') {
127+
vscode.workspace.updateWorkspaceFolders(0, null, { uri: vscode.Uri.file(workspaceRoot) })
128+
}
129+
})
120130
}
121131

122132
/**

0 commit comments

Comments
 (0)