Skip to content

Commit 6ab504a

Browse files
committed
fix: add diagnostics settings to global state (#2379)
- Add includeDiagnostics, maxDiagnosticsCount, and diagnosticsFilter to global settings - Create DiagnosticsSettings component for UI configuration - Update ClineProvider to handle diagnostics settings messages - Modify diagnosticsToProblemsString to accept options parameter - Update ExtensionState type and related components - Add proper defaults: includeDiagnostics=false, maxDiagnosticsCount=5, diagnosticsFilter=['error','warning'] This allows users to configure diagnostics settings that persist across sessions instead of being reset to defaults on each restart.
1 parent 54edab5 commit 6ab504a

File tree

13 files changed

+236
-1
lines changed

13 files changed

+236
-1
lines changed

packages/types/src/global-settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export const globalSettingsSchema = z.object({
7070
showRooIgnoredFiles: z.boolean().optional(),
7171
maxReadFileLine: z.number().optional(),
7272

73+
includeDiagnostics: z.boolean().optional(),
74+
maxDiagnosticsCount: z.number().optional(),
75+
diagnosticsFilter: z.array(z.string()).optional(),
76+
7377
terminalOutputLineLimit: z.number().optional(),
7478
terminalShellIntegrationTimeout: z.number().optional(),
7579
terminalShellIntegrationDisabled: z.boolean().optional(),

src/core/mentions/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ async function getFileOrFolderContent(
246246
}
247247

248248
async function getWorkspaceProblems(cwd: string): Promise<string> {
249+
// Check if diagnostics are enabled
250+
const config = vscode.workspace.getConfiguration("roo-cline")
251+
const includeDiagnostics = config.get<boolean>("includeDiagnostics", true)
252+
253+
if (!includeDiagnostics) {
254+
return "Diagnostics are disabled in settings."
255+
}
256+
249257
const diagnostics = vscode.languages.getDiagnostics()
250258
const result = await diagnosticsToProblemsString(
251259
diagnostics,

src/core/webview/ClineProvider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,9 @@ export class ClineProvider
13291329
showRooIgnoredFiles,
13301330
language,
13311331
maxReadFileLine,
1332+
includeDiagnostics,
1333+
maxDiagnosticsCount,
1334+
diagnosticsFilter,
13321335
terminalCompressProgressBar,
13331336
historyPreviewCollapsed,
13341337
cloudUserInfo,
@@ -1439,6 +1442,9 @@ export class ClineProvider
14391442
renderContext: this.renderContext,
14401443
maxReadFileLine: maxReadFileLine ?? -1,
14411444
maxConcurrentFileReads: maxConcurrentFileReads ?? 5,
1445+
includeDiagnostics: includeDiagnostics ?? false,
1446+
maxDiagnosticsCount: maxDiagnosticsCount ?? 5,
1447+
diagnosticsFilter: diagnosticsFilter ?? ["error", "warning"],
14421448
settingsImportedAt: this.settingsImportedAt,
14431449
terminalCompressProgressBar: terminalCompressProgressBar ?? true,
14441450
hasSystemPromptOverride,
@@ -1590,6 +1596,9 @@ export class ClineProvider
15901596
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
15911597
maxReadFileLine: stateValues.maxReadFileLine ?? -1,
15921598
maxConcurrentFileReads: stateValues.maxConcurrentFileReads ?? 5,
1599+
includeDiagnostics: stateValues.includeDiagnostics ?? false,
1600+
maxDiagnosticsCount: stateValues.maxDiagnosticsCount ?? 5,
1601+
diagnosticsFilter: stateValues.diagnosticsFilter ?? ["error", "warning"],
15931602
historyPreviewCollapsed: stateValues.historyPreviewCollapsed ?? false,
15941603
cloudUserInfo,
15951604
cloudIsAuthenticated,

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ describe("ClineProvider", () => {
432432
autoCondenseContextPercent: 100,
433433
cloudIsAuthenticated: false,
434434
sharingEnabled: false,
435+
includeDiagnostics: false,
436+
maxDiagnosticsCount: 5,
437+
diagnosticsFilter: ["error", "warning"],
435438
}
436439

437440
const message: ExtensionMessage = {

src/core/webview/webviewMessageHandler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,18 @@ export const webviewMessageHandler = async (
995995
await updateGlobalState("maxConcurrentFileReads", valueToSave)
996996
await provider.postStateToWebview()
997997
break
998+
case "includeDiagnostics":
999+
await updateGlobalState("includeDiagnostics", message.bool ?? false)
1000+
await provider.postStateToWebview()
1001+
break
1002+
case "maxDiagnosticsCount":
1003+
await updateGlobalState("maxDiagnosticsCount", message.value ?? 5)
1004+
await provider.postStateToWebview()
1005+
break
1006+
case "diagnosticsFilter":
1007+
await updateGlobalState("diagnosticsFilter", message.values ?? ["error", "warning"])
1008+
await provider.postStateToWebview()
1009+
break
9981010
case "setHistoryPreviewCollapsed": // Add the new case handler
9991011
await updateGlobalState("historyPreviewCollapsed", message.bool ?? false)
10001012
// No need to call postStateToWebview here as the UI already updated optimistically

src/integrations/diagnostics/index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,62 @@ export async function diagnosticsToProblemsString(
7474
diagnostics: [vscode.Uri, vscode.Diagnostic[]][],
7575
severities: vscode.DiagnosticSeverity[],
7676
cwd: string,
77+
options?: {
78+
includeDiagnostics?: boolean
79+
maxDiagnosticsCount?: number
80+
diagnosticsFilter?: string[]
81+
},
7782
): Promise<string> {
83+
// Use provided options or fall back to VSCode configuration
84+
const includeDiagnostics =
85+
options?.includeDiagnostics ??
86+
vscode.workspace.getConfiguration("roo-cline").get<boolean>("includeDiagnostics", false)
87+
88+
if (!includeDiagnostics) {
89+
return ""
90+
}
91+
92+
const maxDiagnosticsCount =
93+
options?.maxDiagnosticsCount ??
94+
vscode.workspace.getConfiguration("roo-cline").get<number>("maxDiagnosticsCount", 5)
95+
const diagnosticsFilter =
96+
options?.diagnosticsFilter ??
97+
vscode.workspace.getConfiguration("roo-cline").get<string[]>("diagnosticsFilter", ["error", "warning"])
98+
7899
const documents = new Map<vscode.Uri, vscode.TextDocument>()
79100
const fileStats = new Map<vscode.Uri, vscode.FileStat>()
80101
let result = ""
102+
let totalDiagnosticsCount = 0
103+
81104
for (const [uri, fileDiagnostics] of diagnostics) {
82105
const problems = fileDiagnostics
83106
.filter((d) => severities.includes(d.severity))
107+
.filter((d) => {
108+
// Apply diagnostics filter
109+
if (diagnosticsFilter.length === 0) return true
110+
111+
const source = d.source || ""
112+
const code = typeof d.code === "object" ? d.code.value : d.code
113+
const filterKey = source ? `${source} ${code || ""}`.trim() : `${code || ""}`.trim()
114+
115+
// Check if this diagnostic should be filtered out
116+
return !diagnosticsFilter.some((filter) => {
117+
// Support partial matching
118+
return filterKey.includes(filter) || d.message.includes(filter)
119+
})
120+
})
84121
.sort((a, b) => a.range.start.line - b.range.start.line)
122+
85123
if (problems.length > 0) {
86124
result += `\n\n${path.relative(cwd, uri.fsPath).toPosix()}`
125+
87126
for (const diagnostic of problems) {
127+
// Check if we've reached the max count
128+
if (maxDiagnosticsCount > 0 && totalDiagnosticsCount >= maxDiagnosticsCount) {
129+
result += `\n... (${diagnostics.reduce((sum, [, diags]) => sum + diags.filter((d) => severities.includes(d.severity)).length, 0) - totalDiagnosticsCount} more diagnostics omitted)`
130+
return result.trim()
131+
}
132+
88133
let label: string
89134
switch (diagnostic.severity) {
90135
case vscode.DiagnosticSeverity.Error:
@@ -121,6 +166,8 @@ export async function diagnosticsToProblemsString(
121166
} catch {
122167
result += `\n- [${source}${label}] ${line} | (unavailable) : ${diagnostic.message}`
123168
}
169+
170+
totalDiagnosticsCount++
124171
}
125172
}
126173
}

src/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,25 @@
344344
"type": "boolean",
345345
"default": false,
346346
"description": "%settings.rooCodeCloudEnabled.description%"
347+
},
348+
"roo-cline.includeDiagnostics": {
349+
"type": "boolean",
350+
"default": true,
351+
"description": "%settings.includeDiagnostics.description%"
352+
},
353+
"roo-cline.maxDiagnosticsCount": {
354+
"type": "number",
355+
"default": 50,
356+
"minimum": 0,
357+
"description": "%settings.maxDiagnosticsCount.description%"
358+
},
359+
"roo-cline.diagnosticsFilter": {
360+
"type": "array",
361+
"items": {
362+
"type": "string"
363+
},
364+
"default": [],
365+
"description": "%settings.diagnosticsFilter.description%"
347366
}
348367
}
349368
}

src/package.nls.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"settings.vsCodeLmModelSelector.vendor.description": "The vendor of the language model (e.g. copilot)",
3131
"settings.vsCodeLmModelSelector.family.description": "The family of the language model (e.g. gpt-4)",
3232
"settings.customStoragePath.description": "Custom storage path. Leave empty to use the default location. Supports absolute paths (e.g. 'D:\\RooCodeStorage')",
33-
"settings.rooCodeCloudEnabled.description": "Enable Roo Code Cloud."
33+
"settings.rooCodeCloudEnabled.description": "Enable Roo Code Cloud.",
34+
"settings.includeDiagnostics.description": "Include diagnostics (errors/warnings) in API requests. Disable this when creating multi-file features to avoid temporary errors distracting the AI.",
35+
"settings.maxDiagnosticsCount.description": "Maximum number of diagnostics to include in API requests (0 for unlimited). Helps control token usage.",
36+
"settings.diagnosticsFilter.description": "Filter diagnostics by code or source. Add diagnostic codes (e.g., 'dart Error', 'eslint/no-unused-vars') to exclude specific types."
3437
}

src/shared/ExtensionMessage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export type ExtensionState = Pick<
177177
// | "showRooIgnoredFiles" // Optional in GlobalSettings, required here.
178178
// | "maxReadFileLine" // Optional in GlobalSettings, required here.
179179
| "maxConcurrentFileReads" // Optional in GlobalSettings, required here.
180+
| "includeDiagnostics"
181+
| "maxDiagnosticsCount"
182+
| "diagnosticsFilter"
180183
| "terminalOutputLineLimit"
181184
| "terminalShellIntegrationTimeout"
182185
| "terminalShellIntegrationDisabled"
@@ -223,6 +226,10 @@ export type ExtensionState = Pick<
223226
showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
224227
maxReadFileLine: number // Maximum number of lines to read from a file before truncating
225228

229+
includeDiagnostics: boolean // Whether to include diagnostics in context
230+
maxDiagnosticsCount: number // Maximum number of diagnostics to include
231+
diagnosticsFilter: string[] // Filter for diagnostic severities
232+
226233
experiments: Experiments // Map of experiment IDs to their enabled state
227234

228235
mcpEnabled: boolean

src/shared/WebviewMessage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export interface WebviewMessage {
144144
| "language"
145145
| "maxReadFileLine"
146146
| "maxConcurrentFileReads"
147+
| "includeDiagnostics"
148+
| "maxDiagnosticsCount"
149+
| "diagnosticsFilter"
147150
| "searchFiles"
148151
| "toggleApiConfigPin"
149152
| "setHistoryPreviewCollapsed"

0 commit comments

Comments
 (0)