Avoid not null assertion and use joinPath

This commit is contained in:
Matt Bierner
2022-01-18 16:40:58 -08:00
parent 789bdb8189
commit b39c8e9989

View File

@@ -45,10 +45,14 @@ class TsconfigLinkProvider implements vscode.DocumentLinkProvider {
);
}
const workspaceFolderPath = vscode.workspace.getWorkspaceFolder(document.uri)!.uri.fsPath;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
if (!workspaceFolder) {
return undefined;
}
return new vscode.DocumentLink(
this.getRange(document, extendsNode),
vscode.Uri.file(join(workspaceFolderPath, 'node_modules', extendsNode.value + (extendsNode.value.endsWith('.json') ? '' : '.json')))
vscode.Uri.joinPath(workspaceFolder.uri, 'node_modules', extendsNode.value + (extendsNode.value.endsWith('.json') ? '' : '.json'))
);
}