Skip to content

Commit 9951dd7

Browse files
committed
Await rust-analyzer quiescence before gathering diagnostics
1 parent 3deeb0c commit 9951dd7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { formatResponse } from "../../core/prompts/responses"
77
import { DecorationController } from "./DecorationController"
88
import * as diff from "diff"
99
import { diagnosticsToProblemsString, getNewDiagnostics } from "../diagnostics"
10+
import delay from "delay"
1011

1112
export const DIFF_VIEW_URI_SCHEME = "cline-diff"
1213

@@ -157,6 +158,35 @@ export class DiffViewProvider {
157158
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false })
158159
await this.closeAllDiffViews()
159160

161+
try {
162+
// Wait for Rust Analyzer to catch up before fetching post-diagnostics
163+
const rustAnalyzer = vscode.extensions.getExtension("rust-lang.rust-analyzer")
164+
if (rustAnalyzer?.isActive && (absolutePath.endsWith(".rs") || absolutePath.endsWith(".toml"))) {
165+
const startTime = Date.now()
166+
const INITIAL_DELAY = 1000 // 1 second
167+
const TIMEOUT = 30000 // 30 seconds
168+
169+
// Give rust-analyzer some time to detect changes
170+
while (rustAnalyzer.exports?.lastStatus?.quiescent === true) {
171+
if (Date.now() - startTime > INITIAL_DELAY) {
172+
break
173+
}
174+
await delay(50)
175+
}
176+
177+
while (rustAnalyzer.exports?.lastStatus?.quiescent === false) {
178+
if (Date.now() - startTime > TIMEOUT) {
179+
console.error("Timeout waiting for rust-analyzer to become quiescent")
180+
console.dir(rustAnalyzer.exports?.lastStatus)
181+
break
182+
}
183+
await delay(100)
184+
}
185+
}
186+
} catch (err) {
187+
// We don't mind if rust-analyzer isn't installed
188+
}
189+
160190
/*
161191
Getting diagnostics before and after the file edit is a better approach than
162192
automatically tracking problems in real-time. This method ensures we only

0 commit comments

Comments
 (0)