Skip to content

Commit e2720e7

Browse files
authored
Make getWorkspaceRootForResource work for notebook cells (microsoft#188186)
Fixes microsoft#186811
1 parent a3cfa39 commit e2720e7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

extensions/typescript-language-features/src/typescriptServiceClient.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { PluginManager, TypeScriptServerPlugin } from './tsServer/plugins';
2929
import { TelemetryProperties, TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
3030
import Tracer from './logging/tracer';
3131
import { ProjectType, inferredProjectCompilerOptions } from './tsconfig';
32+
import { Schemes } from './configuration/schemes';
3233

3334

3435
export interface TsDiagnostics {
@@ -762,6 +763,18 @@ export default class TypeScriptServiceClient extends Disposable implements IType
762763
return undefined;
763764
}
764765

766+
// For notebook cells, we need to use the notebook document to look up the workspace
767+
if (resource.scheme === Schemes.notebookCell) {
768+
for (const notebook of vscode.workspace.notebookDocuments) {
769+
for (const cell of notebook.getCells()) {
770+
if (cell.document.uri.toString() === resource.toString()) {
771+
resource = notebook.uri;
772+
break;
773+
}
774+
}
775+
}
776+
}
777+
765778
for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) {
766779
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
767780
if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) {
@@ -770,7 +783,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
770783
}
771784
}
772785

773-
return undefined;
786+
return vscode.workspace.getWorkspaceFolder(resource)?.uri;
774787
}
775788

776789
public execute(command: keyof TypeScriptRequests, args: any, token: vscode.CancellationToken, config?: ExecConfig): Promise<ServerResponse.Response<Proto.Response>> {

0 commit comments

Comments
 (0)