Skip to content

Commit

Permalink
Make getWorkspaceRootForResource work for notebook cells (#188186)
Browse files Browse the repository at this point in the history
Fixes #186811
  • Loading branch information
mjbvz committed Jul 18, 2023
1 parent a3cfa39 commit e2720e7
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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>> {
Expand Down

0 comments on commit e2720e7

Please sign in to comment.