Skip to content

Commit

Permalink
Fix crashes where workspaceFolders was undefined (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Sep 26, 2024
1 parent 1aa9129 commit 79c8964
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/BrightScriptCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/DebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/DeclarationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/LanguageServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('bsdk');
const parsed = this.parseVersionInfo(versionInfo, workspaceFolder.uri.fsPath);
if (parsed) {
acc.set(parsed.value, parsed);
}
return acc;
}, new Map<string, ParsedVersionInfo>());
}, new Map<string, ParsedVersionInfo>()) ?? new Map<string, ParsedVersionInfo>();

//no results found, use the embedded version
if (folderResults.size === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/LanguageServerInfoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class LanguageServerInfoCommand {
*/
public async selectBrighterScriptVersion(): Promise<string> {
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
Expand Down

0 comments on commit 79c8964

Please sign in to comment.