Skip to content

Commit 328e5da

Browse files
committed
feat: add diagnostics delay configuration after save
1 parent 2f4d833 commit 328e5da

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ export class DiffViewProvider {
214214
// and can address them accordingly. If problems don't change immediately after
215215
// applying a fix, won't be notified, which is generally fine since the
216216
// initial fix is usually correct and it may just take time for linters to catch up.
217+
218+
// Get the configured delay for diagnostics after save
219+
const diagnosticsDelay = vscode.workspace.getConfiguration("roo-cline").get<number>("diagnosticsDelayAfterSave", 0)
220+
221+
// Add a delay if configured to give linters time to process the file
222+
if (diagnosticsDelay > 0) {
223+
await new Promise((resolve) => setTimeout(resolve, diagnosticsDelay))
224+
}
225+
217226
const postDiagnostics = vscode.languages.getDiagnostics()
218227

219228
const newProblems = await diagnosticsToProblemsString(

src/integrations/editor/__tests__/DiffViewProvider.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,78 @@ describe("DiffViewProvider", () => {
327327
).toBeUndefined()
328328
})
329329
})
330+
331+
describe("saveChanges method", () => {
332+
it("should apply configured delay before getting diagnostics", async () => {
333+
// Mock the configuration to return a specific delay
334+
const mockGetConfiguration = vi.fn().mockReturnValue({
335+
get: vi.fn().mockImplementation((key: string, defaultValue: any) => {
336+
if (key === "diagnosticsDelayAfterSave") {
337+
return 1000 // 1 second delay
338+
}
339+
return defaultValue
340+
})
341+
})
342+
343+
// Save original implementation
344+
const originalGetConfiguration = vscode.workspace.getConfiguration
345+
346+
// Replace with our mock
347+
Object.defineProperty(vscode.workspace, "getConfiguration", {
348+
value: mockGetConfiguration,
349+
configurable: true
350+
})
351+
352+
// Mock setTimeout to track if it was called
353+
const originalSetTimeout = global.setTimeout
354+
const mockSetTimeout = vi.fn().mockImplementation((callback, delay) => {
355+
// Execute the callback immediately for testing
356+
callback()
357+
return 1 // Return a timeout ID
358+
})
359+
global.setTimeout = mockSetTimeout as any
360+
361+
// Setup the diffViewProvider for testing
362+
;(diffViewProvider as any).relPath = "test.txt"
363+
;(diffViewProvider as any).newContent = "Test content"
364+
;(diffViewProvider as any).originalContent = "Original content"
365+
;(diffViewProvider as any).activeDiffEditor = {
366+
document: {
367+
uri: { fsPath: `${mockCwd}/test.txt` },
368+
getText: vi.fn().mockReturnValue("Test content"),
369+
lineCount: 1,
370+
},
371+
isDirty: false,
372+
save: vi.fn().mockResolvedValue(undefined),
373+
}
374+
375+
// Mock getDiagnostics to track when it's called
376+
const mockGetDiagnostics = vi.fn().mockReturnValue([])
377+
const originalGetDiagnostics = vscode.languages.getDiagnostics
378+
vscode.languages.getDiagnostics = mockGetDiagnostics
379+
380+
// Mock showTextDocument
381+
vi.mocked(vscode.window.showTextDocument).mockResolvedValue({} as any)
382+
383+
// Execute saveChanges
384+
await diffViewProvider.saveChanges()
385+
386+
// Verify that getConfiguration was called with "roo-cline"
387+
expect(mockGetConfiguration).toHaveBeenCalledWith("roo-cline")
388+
389+
// Verify that setTimeout was called with the correct delay
390+
expect(mockSetTimeout).toHaveBeenCalledWith(expect.any(Function), 1000)
391+
392+
// Verify that getDiagnostics was called after the delay
393+
expect(mockGetDiagnostics).toHaveBeenCalled()
394+
395+
// Restore original implementations
396+
Object.defineProperty(vscode.workspace, "getConfiguration", {
397+
value: originalGetConfiguration,
398+
configurable: true
399+
})
400+
global.setTimeout = originalSetTimeout
401+
vscode.languages.getDiagnostics = originalGetDiagnostics
402+
})
403+
})
330404
})

src/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@
373373
"type": "string",
374374
"default": "",
375375
"description": "%settings.autoImportSettingsPath.description%"
376+
},
377+
"roo-cline.diagnosticsDelayAfterSave": {
378+
"type": "number",
379+
"default": 0,
380+
"minimum": 0,
381+
"maximum": 5000,
382+
"description": "Delay (in milliseconds) after saving a file before checking for linting errors"
376383
}
377384
}
378385
}

0 commit comments

Comments
 (0)