diff --git a/src/extension/tools/node/getErrorsTool.tsx b/src/extension/tools/node/getErrorsTool.tsx index a7b7bc062..bd5186e1e 100644 --- a/src/extension/tools/node/getErrorsTool.tsx +++ b/src/extension/tools/node/getErrorsTool.tsx @@ -11,7 +11,9 @@ import { ILogService } from '../../../platform/log/common/logService'; import { IPromptPathRepresentationService } from '../../../platform/prompts/common/promptPathRepresentationService'; import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService'; import { getLanguage } from '../../../util/common/languages'; +import { isJupyterNotebookUri } from '../../../util/common/notebooks'; import { isLocation } from '../../../util/common/types'; +import { coalesce } from '../../../util/vs/base/common/arrays'; import { CancellationToken } from '../../../util/vs/base/common/cancellation'; import { Disposable } from '../../../util/vs/base/common/lifecycle'; import { URI } from '../../../util/vs/base/common/uri'; @@ -25,7 +27,6 @@ import { DiagnosticContext, Diagnostics } from '../../prompts/node/inline/diagno import { ToolName } from '../common/toolNames'; import { ICopilotTool, ToolRegistry } from '../common/toolsRegistry'; import { checkCancellation, formatUriForFileWidget, resolveToolInputPath } from './toolUtils'; -import { coalesce } from '../../../util/vs/base/common/arrays'; interface IGetErrorsParams { // Note that empty array is not the same as absence; empty array @@ -62,14 +63,17 @@ class GetErrorsTool extends Disposable implements ICopilotTool throw new Error(`Invalid input path ${filePath}`); } - let diagnostics = range - ? findDiagnosticForSelectionAndPrompt(this.languageDiagnosticsService, uri, new Range(...range), undefined) - : this.languageDiagnosticsService.getDiagnostics(uri); - - diagnostics = diagnostics.filter(d => d.severity <= DiagnosticSeverity.Warning); + let diagnostics: vscode.Diagnostic[] = []; + if (isJupyterNotebookUri(uri)) { + diagnostics = this.getNotebookCellDiagnostics(uri); + } else { + diagnostics = range + ? findDiagnosticForSelectionAndPrompt(this.languageDiagnosticsService, uri, new Range(...range), undefined) + : this.languageDiagnosticsService.getDiagnostics(uri); + } return { - diagnostics, + diagnostics: diagnostics.filter(d => d.severity <= DiagnosticSeverity.Warning), uri, }; }); @@ -140,6 +144,21 @@ class GetErrorsTool extends Disposable implements ICopilotTool return uris.map(formatUriForFileWidget).join(', '); } + private getNotebookCellDiagnostics(uri: URI) { + const notebook = this.workspaceService.notebookDocuments + .find((doc: { uri: URI }) => doc.uri.toString() === uri.toString()); + if (!notebook) { + this.logService.error(`Notebook not found: ${uri.toString()}, could not retrieve diagnostics`); + return []; + } + + return notebook.getCells() + .flatMap((cell) => { + const uri = cell.document.uri; + return this.languageDiagnosticsService.getDiagnostics(uri); + }); + } + async provideInput(promptContext: IBuildPromptContext): Promise { const seen = new Set();