Make getWorkspaceRootForResource work for notebook cells (#188186)

Fixes #186811
This commit is contained in:
Matt Bierner 2023-07-18 12:29:22 -07:00 committed by GitHub
parent a3cfa39a08
commit e2720e7bf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,7 @@ import { PluginManager, TypeScriptServerPlugin } from './tsServer/plugins';
import { TelemetryProperties, TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
import Tracer from './logging/tracer';
import { ProjectType, inferredProjectCompilerOptions } from './tsconfig';
import { Schemes } from './configuration/schemes';
export interface TsDiagnostics {
@ -762,6 +763,18 @@ export default class TypeScriptServiceClient extends Disposable implements IType
return undefined;
}
// For notebook cells, we need to use the notebook document to look up the workspace
if (resource.scheme === Schemes.notebookCell) {
for (const notebook of vscode.workspace.notebookDocuments) {
for (const cell of notebook.getCells()) {
if (cell.document.uri.toString() === resource.toString()) {
resource = notebook.uri;
break;
}
}
}
}
for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) {
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) {
@ -770,7 +783,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
}
return undefined;
return vscode.workspace.getWorkspaceFolder(resource)?.uri;
}
public execute(command: keyof TypeScriptRequests, args: any, token: vscode.CancellationToken, config?: ExecConfig): Promise<ServerResponse.Response<Proto.Response>> {