-
Notifications
You must be signed in to change notification settings - Fork 1.3k
get errors for a notebook URI #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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<IGetErrorsParams> | |||||
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<IGetErrorsParams> | |||||
return uris.map(formatUriForFileWidget).join(', '); | ||||||
} | ||||||
|
||||||
private getNotebookCellDiagnostics(uri: URI) { | ||||||
const notebook = this.workspaceService.notebookDocuments | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using |
||||||
.find((doc: { uri: URI }) => doc.uri.toString() === uri.toString()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URI comparison using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's not a real function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the better approach is to use |
||||||
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<IGetErrorsParams | undefined> { | ||||||
const seen = new Set<string>(); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be used for all notebooks, not just Jupyter?
I think you can use
INotebookService.hasSupportedNotebook
to check if Uri is a notebook document