Skip to content

Commit 8d93508

Browse files
authored
Skip resources with no Warning/Error diagnostics when collecting diagnostics (#1785)
1 parent 9bfb081 commit 8d93508

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/extension/tools/node/getErrorsTool.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class GetErrorsTool extends Disposable implements ICopilotTool<IGetErrors
7979
// for non-notebooks, we get all diagnostics and filter down
8080
for (const [resource, entries] of this.languageDiagnosticsService.getAllDiagnostics()) {
8181
const pendingDiagnostics = entries.filter(d => d.severity <= DiagnosticSeverity.Warning);
82+
if (pendingDiagnostics.length === 0) {
83+
continue;
84+
}
8285

8386
// find all path&range pairs and collect the ranges to further filter diagnostics
8487
// if any path matches the resource without a range, take all diagnostics for that file

src/extension/tools/node/test/getErrorsTool.spec.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,33 @@ suite('GetErrorsTool - Tool Invocation', () => {
149149
]);
150150
});
151151

152+
test('getDiagnostics - folder path excludes files with only Info and Hint diagnostics', () => {
153+
// Create a file with only Info and Hint diagnostics
154+
const infoHintOnlyFile = URI.file('/test/workspace/src/infoHintOnly.ts');
155+
diagnosticsService.setDiagnostics(infoHintOnlyFile, [
156+
{
157+
message: 'This is just informational',
158+
range: new Range(0, 0, 0, 5),
159+
severity: DiagnosticSeverity.Information
160+
},
161+
{
162+
message: 'This is a hint',
163+
range: new Range(1, 0, 1, 5),
164+
severity: DiagnosticSeverity.Hint
165+
}
166+
]);
167+
168+
// Request diagnostics for the src folder
169+
const srcFolder = URI.file('/test/workspace/src');
170+
const results = tool.getDiagnostics([{ uri: srcFolder, range: undefined }]);
171+
172+
// Should only include tsFile1 and tsFile2, not infoHintOnlyFile (which has no Warning/Error)
173+
expect(results).toEqual([
174+
{ uri: tsFile1, diagnostics: diagnosticsService.getDiagnostics(tsFile1).filter(d => d.severity <= DiagnosticSeverity.Warning) },
175+
{ uri: tsFile2, diagnostics: diagnosticsService.getDiagnostics(tsFile2).filter(d => d.severity <= DiagnosticSeverity.Warning) }
176+
]);
177+
});
178+
152179
// Tool invocation tests
153180
test('Tool invocation - with no filePaths aggregates all diagnostics and formats workspace message', async () => {
154181
const result = await tool.invoke({ input: {}, toolInvocationToken: null! }, CancellationToken.None);

0 commit comments

Comments
 (0)