-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add configurable delay for Go diagnostics to prevent premature error reporting #5863
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
87e7b3e
feat: add configurable delay for Go diagnostics to prevent premature …
roomote a1e7983
fix: add missing TypeScript type definitions for diagnostic settings
roomote 53e828b
fix: update test mocks to support diagnostic settings in tool tests
roomote e1a105d
fix: remove package-lock.json file (project uses pnpm)
roomote 0d49afd
refactor: use existing writeDelayMs instead of diagnosticsDelayMs
roomote 1e76168
fix: resolve failing unit tests and TypeScript compilation errors
roomote cdffefc
fix: remove unrelated changes from ClineProvider.spec.ts
roomote 0bfe05a
refactor: move DEFAULT_WRITE_DELAY_MS to packages/types/src/global-se…
roomote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,12 @@ | ||||||
| import { DiffViewProvider, DIFF_VIEW_URI_SCHEME, DIFF_VIEW_LABEL_CHANGES } from "../DiffViewProvider" | ||||||
| import * as vscode from "vscode" | ||||||
| import * as path from "path" | ||||||
| import delay from "delay" | ||||||
|
|
||||||
| // Mock delay | ||||||
| vi.mock("delay", () => ({ | ||||||
| default: vi.fn().mockResolvedValue(undefined), | ||||||
| })) | ||||||
|
|
||||||
| // Mock fs/promises | ||||||
| vi.mock("fs/promises", () => ({ | ||||||
|
|
@@ -45,6 +51,12 @@ vi.mock("vscode", () => ({ | |||||
| languages: { | ||||||
| getDiagnostics: vi.fn(() => []), | ||||||
| }, | ||||||
| DiagnosticSeverity: { | ||||||
| Error: 0, | ||||||
| Warning: 1, | ||||||
| Information: 2, | ||||||
| Hint: 3, | ||||||
| }, | ||||||
| WorkspaceEdit: vi.fn().mockImplementation(() => ({ | ||||||
| replace: vi.fn(), | ||||||
| delete: vi.fn(), | ||||||
|
|
@@ -327,4 +339,83 @@ describe("DiffViewProvider", () => { | |||||
| ).toBeUndefined() | ||||||
| }) | ||||||
| }) | ||||||
|
|
||||||
| describe("saveChanges method with diagnostic settings", () => { | ||||||
| beforeEach(() => { | ||||||
| // Setup common mocks for saveChanges tests | ||||||
| ;(diffViewProvider as any).relPath = "test.ts" | ||||||
| ;(diffViewProvider as any).newContent = "new content" | ||||||
| ;(diffViewProvider as any).activeDiffEditor = { | ||||||
| document: { | ||||||
| getText: vi.fn().mockReturnValue("new content"), | ||||||
| isDirty: false, | ||||||
| save: vi.fn().mockResolvedValue(undefined), | ||||||
| }, | ||||||
| } | ||||||
| ;(diffViewProvider as any).preDiagnostics = [] | ||||||
|
|
||||||
| // Mock vscode functions | ||||||
| vi.mocked(vscode.window.showTextDocument).mockResolvedValue({} as any) | ||||||
| vi.mocked(vscode.languages.getDiagnostics).mockReturnValue([]) | ||||||
| }) | ||||||
|
|
||||||
| it("should apply diagnostic delay when diagnosticsEnabled is true", async () => { | ||||||
| const mockDelay = vi.mocked(delay) | ||||||
| mockDelay.mockClear() | ||||||
|
|
||||||
| // Mock closeAllDiffViews | ||||||
| ;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined) | ||||||
|
|
||||||
| const result = await diffViewProvider.saveChanges(true, 3000) | ||||||
|
|
||||||
| // Verify delay was called with correct duration | ||||||
| expect(mockDelay).toHaveBeenCalledWith(3000) | ||||||
| expect(vscode.languages.getDiagnostics).toHaveBeenCalled() | ||||||
| expect(result.newProblemsMessage).toBe("") | ||||||
| }) | ||||||
|
|
||||||
| it("should skip diagnostics when diagnosticsEnabled is false", async () => { | ||||||
| const mockDelay = vi.mocked(delay) | ||||||
| mockDelay.mockClear() | ||||||
|
|
||||||
| // Mock closeAllDiffViews | ||||||
| ;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined) | ||||||
|
|
||||||
| const result = await diffViewProvider.saveChanges(false, 2000) | ||||||
|
|
||||||
| // Verify delay was NOT called and diagnostics were NOT checked | ||||||
| expect(mockDelay).not.toHaveBeenCalled() | ||||||
| expect(vscode.languages.getDiagnostics).not.toHaveBeenCalled() | ||||||
| expect(result.newProblemsMessage).toBe("") | ||||||
| }) | ||||||
|
|
||||||
| it("should use default values when no parameters provided", async () => { | ||||||
| const mockDelay = vi.mocked(delay) | ||||||
| mockDelay.mockClear() | ||||||
|
|
||||||
| // Mock closeAllDiffViews | ||||||
| ;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined) | ||||||
|
|
||||||
| const result = await diffViewProvider.saveChanges() | ||||||
|
|
||||||
| // Verify default behavior (enabled=true, delay=2000ms) | ||||||
|
Contributor
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 comment mentions a delay of 2000ms (// Verify default behavior (enabled=true, delay=2000ms)), but the expectation on line 402 now uses 1000ms. Please update the comment to match the new behavior.
Suggested change
|
||||||
| expect(mockDelay).toHaveBeenCalledWith(2000) | ||||||
| expect(vscode.languages.getDiagnostics).toHaveBeenCalled() | ||||||
| expect(result.newProblemsMessage).toBe("") | ||||||
| }) | ||||||
|
|
||||||
| it("should handle custom delay values", async () => { | ||||||
| const mockDelay = vi.mocked(delay) | ||||||
| mockDelay.mockClear() | ||||||
|
|
||||||
| // Mock closeAllDiffViews | ||||||
| ;(diffViewProvider as any).closeAllDiffViews = vi.fn().mockResolvedValue(undefined) | ||||||
|
|
||||||
| const result = await diffViewProvider.saveChanges(true, 5000) | ||||||
|
|
||||||
| // Verify custom delay was used | ||||||
| expect(mockDelay).toHaveBeenCalledWith(5000) | ||||||
| expect(vscode.languages.getDiagnostics).toHaveBeenCalled() | ||||||
| }) | ||||||
| }) | ||||||
| }) | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
New diagnostic settings (diagnosticsDelayMs, diagnosticsEnabled) added to the schema. Consider validating that diagnosticsDelayMs is non-negative to avoid invalid delay values.