Skip to content

Commit b6bded9

Browse files
feat: add configurable delay for Go diagnostics to prevent premature error reporting (#5863)
* feat: add configurable delay for Go diagnostics to prevent premature error reporting - Add diagnosticsDelayMs setting (default: 2000ms) to allow linters time to process - Add diagnosticsEnabled setting to optionally disable diagnostic checking entirely - Update DiffViewProvider.saveChanges() to use configurable delay before checking diagnostics - Update all tool files (writeToFile, searchAndReplace, insertContent, applyDiff, multiApplyDiff) to pass diagnostic settings - Add comprehensive tests for new diagnostic functionality - Fixes issue where Go diagnostics errors were submitted to LLM before linter could clean up unused imports Resolves #5859 * fix: add missing TypeScript type definitions for diagnostic settings - Add diagnosticsDelayMs and diagnosticsEnabled to globalSettingsSchema - Include properties in ExtensionState Pick type - Add default values to EVALS_SETTINGS - Fix VSCode mock to include DiagnosticSeverity for tests - Resolves compilation errors in ClineProvider and webviewMessageHandler * fix: update test mocks to support diagnostic settings in tool tests - Add providerRef mock to insertContentTool and writeToFileTool tests - Update mocks to include diagnosticsEnabled and diagnosticsDelayMs settings - Fix test expectations to match new implementation with diagnostic configuration - Resolves failing unit tests for insertContentTool.spec.ts and writeToFileTool.spec.ts * fix: remove package-lock.json file (project uses pnpm) * refactor: use existing writeDelayMs instead of diagnosticsDelayMs - Remove diagnosticsDelayMs setting in favor of existing writeDelayMs - Add min(0) validation for writeDelayMs in global settings schema - Add error handling around delay function calls in DiffViewProvider - Create DEFAULT_WRITE_DELAY_MS constant (1000ms) to replace repeated defaults - Update all tool files to pass writeDelayMs instead of diagnosticsDelayMs - Remove diagnosticsDelayMs from webview message handlers and types - Update test files to use writeDelayMs instead of diagnosticsDelayMs This refactoring consolidates diagnostic delay functionality to use the existing writeDelayMs setting as requested in PR feedback. * fix: resolve failing unit tests and TypeScript compilation errors - Fix DiffViewProvider test to expect correct default delay (1000ms instead of 2000ms) - Fix TypeScript type errors in ClineProvider test mock state object - Correct terminalPowershellCounter and terminalZdotdir types to boolean - Fix pinnedApiConfigs type from array to Record<string, boolean> * fix: remove unrelated changes from ClineProvider.spec.ts - Removed extensive unrelated property additions to mock state - Kept only diagnosticsEnabled property which is related to Go diagnostics delay feature - Removed unused DEFAULT_WRITE_DELAY_MS import - Restored original structure and organization of mock state object This addresses the feedback to remove unrelated changes while preserving the necessary diagnostic functionality for the Go diagnostics delay feature. * refactor: move DEFAULT_WRITE_DELAY_MS to packages/types/src/global-settings.ts - Move DEFAULT_WRITE_DELAY_MS constant from src/shared/constants.ts to packages/types/src/global-settings.ts - Update all import statements in affected files to use @roo-code/types - Delete src/shared/constants.ts file as it is no longer needed - Files updated: - src/integrations/editor/DiffViewProvider.ts - src/core/webview/ClineProvider.ts - src/core/tools/multiApplyDiffTool.ts - src/core/tools/applyDiffTool.ts - src/core/tools/searchAndReplaceTool.ts - src/core/tools/insertContentTool.ts - src/core/tools/writeToFileTool.ts --------- Co-authored-by: Roo Code <[email protected]>
1 parent 8c34976 commit b6bded9

File tree

15 files changed

+195
-22
lines changed

15 files changed

+195
-22
lines changed

packages/types/src/global-settings.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import { modeConfigSchema } from "./mode.js"
1515
import { customModePromptsSchema, customSupportPromptsSchema } from "./mode.js"
1616
import { languagesSchema } from "./vscode.js"
1717

18+
/**
19+
* Default delay in milliseconds after writes to allow diagnostics to detect potential problems.
20+
* This delay is particularly important for Go and other languages where tools like goimports
21+
* need time to automatically clean up unused imports.
22+
*/
23+
export const DEFAULT_WRITE_DELAY_MS = 1000
24+
1825
/**
1926
* GlobalSettings
2027
*/
@@ -37,7 +44,7 @@ export const globalSettingsSchema = z.object({
3744
alwaysAllowWrite: z.boolean().optional(),
3845
alwaysAllowWriteOutsideWorkspace: z.boolean().optional(),
3946
alwaysAllowWriteProtected: z.boolean().optional(),
40-
writeDelayMs: z.number().optional(),
47+
writeDelayMs: z.number().min(0).optional(),
4148
alwaysAllowBrowser: z.boolean().optional(),
4249
alwaysApproveResubmit: z.boolean().optional(),
4350
requestDelaySeconds: z.number().optional(),
@@ -87,6 +94,8 @@ export const globalSettingsSchema = z.object({
8794
terminalZdotdir: z.boolean().optional(),
8895
terminalCompressProgressBar: z.boolean().optional(),
8996

97+
diagnosticsEnabled: z.boolean().optional(),
98+
9099
rateLimitSeconds: z.number().optional(),
91100
diffEnabled: z.boolean().optional(),
92101
fuzzyMatchThreshold: z.number().optional(),
@@ -226,6 +235,8 @@ export const EVALS_SETTINGS: RooCodeSettings = {
226235
terminalCompressProgressBar: true,
227236
terminalShellIntegrationDisabled: true,
228237

238+
diagnosticsEnabled: true,
239+
229240
diffEnabled: true,
230241
fuzzyMatchThreshold: 1,
231242

src/core/tools/__tests__/insertContentTool.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ describe("insertContentTool", () => {
7171
cwd: "/",
7272
consecutiveMistakeCount: 0,
7373
didEditFile: false,
74+
providerRef: {
75+
deref: vi.fn().mockReturnValue({
76+
getState: vi.fn().mockResolvedValue({
77+
diagnosticsEnabled: true,
78+
writeDelayMs: 1000,
79+
}),
80+
}),
81+
},
7482
rooIgnoreController: {
7583
validateAccess: vi.fn().mockReturnValue(true),
7684
},

src/core/tools/__tests__/writeToFileTool.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ describe("writeToFileTool", () => {
132132
mockCline.consecutiveMistakeCount = 0
133133
mockCline.didEditFile = false
134134
mockCline.diffStrategy = undefined
135+
mockCline.providerRef = {
136+
deref: vi.fn().mockReturnValue({
137+
getState: vi.fn().mockResolvedValue({
138+
diagnosticsEnabled: true,
139+
writeDelayMs: 1000,
140+
}),
141+
}),
142+
}
135143
mockCline.rooIgnoreController = {
136144
validateAccess: vi.fn().mockReturnValue(true),
137145
}
@@ -376,7 +384,7 @@ describe("writeToFileTool", () => {
376384
userEdits: userEditsValue,
377385
finalContent: "modified content",
378386
})
379-
// Manually set the property on the mock instance because the original saveChanges is not called
387+
// Set the userEdits property on the diffViewProvider mock to simulate user edits
380388
mockCline.diffViewProvider.userEdits = userEditsValue
381389

382390
await executeWriteFileTool({}, { fileExists: true })

src/core/tools/applyDiffTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import fs from "fs/promises"
33

44
import { TelemetryService } from "@roo-code/telemetry"
5+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
56

67
import { ClineSayTool } from "../../shared/ExtensionMessage"
78
import { getReadablePath } from "../../utils/path"
@@ -170,7 +171,11 @@ export async function applyDiffToolLegacy(
170171
}
171172

172173
// Call saveChanges to update the DiffViewProvider properties
173-
await cline.diffViewProvider.saveChanges()
174+
const provider = cline.providerRef.deref()
175+
const state = await provider?.getState()
176+
const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
177+
const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
178+
await cline.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
174179

175180
// Track file edit operation
176181
if (relPath) {

src/core/tools/insertContentTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ClineSayTool } from "../../shared/ExtensionMessage"
1010
import { RecordSource } from "../context-tracking/FileContextTrackerTypes"
1111
import { fileExistsAtPath } from "../../utils/fs"
1212
import { insertGroups } from "../diff/insert-groups"
13+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
1314

1415
export async function insertContentTool(
1516
cline: Task,
@@ -155,7 +156,11 @@ export async function insertContentTool(
155156
}
156157

157158
// Call saveChanges to update the DiffViewProvider properties
158-
await cline.diffViewProvider.saveChanges()
159+
const provider = cline.providerRef.deref()
160+
const state = await provider?.getState()
161+
const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
162+
const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
163+
await cline.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
159164

160165
// Track file edit operation
161166
if (relPath) {

src/core/tools/multiApplyDiffTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import fs from "fs/promises"
33

44
import { TelemetryService } from "@roo-code/telemetry"
5+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
56

67
import { ClineSayTool } from "../../shared/ExtensionMessage"
78
import { getReadablePath } from "../../utils/path"
@@ -553,7 +554,11 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
553554
}
554555

555556
// Call saveChanges to update the DiffViewProvider properties
556-
await cline.diffViewProvider.saveChanges()
557+
const provider = cline.providerRef.deref()
558+
const state = await provider?.getState()
559+
const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
560+
const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
561+
await cline.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
557562

558563
// Track file edit operation
559564
await cline.fileContextTracker.trackFileContext(relPath, "roo_edited" as RecordSource)

src/core/tools/searchAndReplaceTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ClineSayTool } from "../../shared/ExtensionMessage"
1111
import { getReadablePath } from "../../utils/path"
1212
import { fileExistsAtPath } from "../../utils/fs"
1313
import { RecordSource } from "../context-tracking/FileContextTrackerTypes"
14+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
1415

1516
/**
1617
* Tool for performing search and replace operations on files
@@ -227,7 +228,11 @@ export async function searchAndReplaceTool(
227228
}
228229

229230
// Call saveChanges to update the DiffViewProvider properties
230-
await cline.diffViewProvider.saveChanges()
231+
const provider = cline.providerRef.deref()
232+
const state = await provider?.getState()
233+
const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
234+
const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
235+
await cline.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
231236

232237
// Track file edit operation
233238
if (relPath) {

src/core/tools/writeToFileTool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getReadablePath } from "../../utils/path"
1313
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
1414
import { detectCodeOmission } from "../../integrations/editor/detect-omission"
1515
import { unescapeHtmlEntities } from "../../utils/text-normalization"
16+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
1617

1718
export async function writeToFileTool(
1819
cline: Task,
@@ -213,7 +214,11 @@ export async function writeToFileTool(
213214
}
214215

215216
// Call saveChanges to update the DiffViewProvider properties
216-
await cline.diffViewProvider.saveChanges()
217+
const provider = cline.providerRef.deref()
218+
const state = await provider?.getState()
219+
const diagnosticsEnabled = state?.diagnosticsEnabled ?? true
220+
const writeDelayMs = state?.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS
221+
await cline.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
217222

218223
// Track file edit operation
219224
if (relPath) {

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { ExtensionMessage, MarketplaceInstalledMetadata } from "../../shared/Ext
4242
import { Mode, defaultModeSlug } from "../../shared/modes"
4343
import { experimentDefault, experiments, EXPERIMENT_IDS } from "../../shared/experiments"
4444
import { formatLanguage } from "../../shared/language"
45+
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
4546
import { Terminal } from "../../integrations/terminal/Terminal"
4647
import { downloadTask } from "../../integrations/misc/export-markdown"
4748
import { getTheme } from "../../integrations/theme/getTheme"
@@ -1436,6 +1437,7 @@ export class ClineProvider
14361437
profileThresholds,
14371438
alwaysAllowFollowupQuestions,
14381439
followupAutoApproveTimeoutMs,
1440+
diagnosticsEnabled,
14391441
} = await this.getState()
14401442

14411443
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1489,7 +1491,7 @@ export class ClineProvider
14891491
remoteBrowserHost,
14901492
remoteBrowserEnabled: remoteBrowserEnabled ?? false,
14911493
cachedChromeHostUrl: cachedChromeHostUrl,
1492-
writeDelayMs: writeDelayMs ?? 1000,
1494+
writeDelayMs: writeDelayMs ?? DEFAULT_WRITE_DELAY_MS,
14931495
terminalOutputLineLimit: terminalOutputLineLimit ?? 500,
14941496
terminalShellIntegrationTimeout: terminalShellIntegrationTimeout ?? Terminal.defaultShellIntegrationTimeout,
14951497
terminalShellIntegrationDisabled: terminalShellIntegrationDisabled ?? false,
@@ -1555,6 +1557,7 @@ export class ClineProvider
15551557
hasOpenedModeSelector: this.getGlobalState("hasOpenedModeSelector") ?? false,
15561558
alwaysAllowFollowupQuestions: alwaysAllowFollowupQuestions ?? false,
15571559
followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000,
1560+
diagnosticsEnabled: diagnosticsEnabled ?? true,
15581561
}
15591562
}
15601563

@@ -1638,6 +1641,7 @@ export class ClineProvider
16381641
alwaysAllowFollowupQuestions: stateValues.alwaysAllowFollowupQuestions ?? false,
16391642
alwaysAllowUpdateTodoList: stateValues.alwaysAllowUpdateTodoList ?? false,
16401643
followupAutoApproveTimeoutMs: stateValues.followupAutoApproveTimeoutMs ?? 60000,
1644+
diagnosticsEnabled: stateValues.diagnosticsEnabled ?? true,
16411645
allowedMaxRequests: stateValues.allowedMaxRequests,
16421646
autoCondenseContext: stateValues.autoCondenseContext ?? true,
16431647
autoCondenseContextPercent: stateValues.autoCondenseContextPercent ?? 100,
@@ -1656,7 +1660,7 @@ export class ClineProvider
16561660
remoteBrowserEnabled: stateValues.remoteBrowserEnabled ?? false,
16571661
cachedChromeHostUrl: stateValues.cachedChromeHostUrl as string | undefined,
16581662
fuzzyMatchThreshold: stateValues.fuzzyMatchThreshold ?? 1.0,
1659-
writeDelayMs: stateValues.writeDelayMs ?? 1000,
1663+
writeDelayMs: stateValues.writeDelayMs ?? DEFAULT_WRITE_DELAY_MS,
16601664
terminalOutputLineLimit: stateValues.terminalOutputLineLimit ?? 500,
16611665
terminalShellIntegrationTimeout:
16621666
stateValues.terminalShellIntegrationTimeout ?? Terminal.defaultShellIntegrationTimeout,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ describe("ClineProvider", () => {
540540
sharingEnabled: false,
541541
profileThresholds: {},
542542
hasOpenedModeSelector: false,
543+
diagnosticsEnabled: true,
543544
}
544545

545546
const message: ExtensionMessage = {

0 commit comments

Comments
 (0)