From 79c8964f3e2b56b6917d54b8550a87133b9862ee Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Thu, 26 Sep 2024 14:39:16 -0400 Subject: [PATCH] Fix crashes where workspaceFolders was undefined (#593) --- src/BrightScriptCommands.ts | 4 ++-- src/DebugConfigurationProvider.ts | 2 +- src/DeclarationProvider.ts | 2 +- src/LanguageServerManager.ts | 4 ++-- src/commands/LanguageServerInfoCommand.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BrightScriptCommands.ts b/src/BrightScriptCommands.ts index c81e722a..65a8e963 100644 --- a/src/BrightScriptCommands.ts +++ b/src/BrightScriptCommands.ts @@ -454,8 +454,8 @@ export class BrightScriptCommands { this.workspacePath = await this.context.workspaceState.get('workspacePath'); //let folderUri: vscode.Uri; if (!this.workspacePath) { - if (vscode.workspace.workspaceFolders.length === 1) { - this.workspacePath = vscode.workspace.workspaceFolders[0].uri.fsPath; + if (vscode.workspace.workspaceFolders?.length === 1) { + this.workspacePath = vscode.workspace.workspaceFolders?.[0].uri.fsPath; } else { //there are multiple workspaces, ask the user to specify which one they want to use let workspaceFolder = await vscode.window.showWorkspaceFolderPick(); diff --git a/src/DebugConfigurationProvider.ts b/src/DebugConfigurationProvider.ts index e7de2cb3..26147add 100644 --- a/src/DebugConfigurationProvider.ts +++ b/src/DebugConfigurationProvider.ts @@ -234,7 +234,7 @@ export class BrightScriptDebugConfigurationProvider implements DebugConfiguratio folderUri = folder.uri; //if there's only one workspace, use that workspace's folder path - } else if (vscode.workspace.workspaceFolders.length === 1) { + } else if (vscode.workspace.workspaceFolders?.length === 1) { folderUri = vscode.workspace.workspaceFolders[0].uri; } else { //there are multiple workspaces, ask the user to specify which one they want to use diff --git a/src/DeclarationProvider.ts b/src/DeclarationProvider.ts index 9cc94ddd..e1b3979c 100644 --- a/src/DeclarationProvider.ts +++ b/src/DeclarationProvider.ts @@ -49,7 +49,7 @@ export class WorkspaceEncoding { public reset() { this.encoding = []; - for (const folder of vscode.workspace.workspaceFolders) { + for (const folder of vscode.workspace.workspaceFolders ?? []) { this.encoding.push([folder.uri.fsPath, this.getConfiguration(folder.uri)]); } } diff --git a/src/LanguageServerManager.ts b/src/LanguageServerManager.ts index 69449d64..ffa6041c 100644 --- a/src/LanguageServerManager.ts +++ b/src/LanguageServerManager.ts @@ -468,14 +468,14 @@ export class LanguageServerManager { } //collect `brightscript.bsdk` setting value from each workspaceFolder - const folderResults = vscode.workspace.workspaceFolders.reduce((acc, workspaceFolder) => { + const folderResults = vscode.workspace.workspaceFolders?.reduce((acc, workspaceFolder) => { const versionInfo = vscode.workspace.getConfiguration('brightscript', workspaceFolder).get('bsdk'); const parsed = this.parseVersionInfo(versionInfo, workspaceFolder.uri.fsPath); if (parsed) { acc.set(parsed.value, parsed); } return acc; - }, new Map()); + }, new Map()) ?? new Map(); //no results found, use the embedded version if (folderResults.size === 0) { diff --git a/src/commands/LanguageServerInfoCommand.ts b/src/commands/LanguageServerInfoCommand.ts index 59060393..44311adb 100644 --- a/src/commands/LanguageServerInfoCommand.ts +++ b/src/commands/LanguageServerInfoCommand.ts @@ -141,7 +141,7 @@ export class LanguageServerInfoCommand { */ public async selectBrighterScriptVersion(): Promise { const quickPickItems = this.discoverBrighterScriptVersions( - vscode.workspace.workspaceFolders.map(x => this.getWorkspaceOrFolderPath(x.uri.fsPath)) + vscode.workspace.workspaceFolders?.map(x => this.getWorkspaceOrFolderPath(x.uri.fsPath)) ?? [] ); //start the request right now, we will leverage it later