Skip to content

Commit 112136d

Browse files
committed
Fix critical issue with diagnostics in CoqProofChecker
1 parent 4208a99 commit 112136d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/coqLsp/coqLspClient.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export class CoqLspClient implements CoqLspClientInterface {
189189
requestType: ProtocolNotificationType<any, any>,
190190
params: any,
191191
uri: Uri,
192+
version: number,
192193
lastDocumentEndPosition?: Position,
193194
timeout: number = 300000
194195
): Promise<DiagnosticMessage> {
@@ -210,7 +211,10 @@ export class CoqLspClient implements CoqLspClientInterface {
210211
this.client.onNotification(
211212
PublishDiagnosticsNotification.type,
212213
(params) => {
213-
if (params.uri.toString() === uri.uri) {
214+
if (
215+
params.uri.toString() === uri.uri &&
216+
params.version === version
217+
) {
214218
pendingDiagnostic = false;
215219
awaitedDiagnostics = params.diagnostics;
216220

@@ -242,6 +246,8 @@ export class CoqLspClient implements CoqLspClientInterface {
242246
throw new CoqLspError("coq-lsp did not respond in time");
243247
}
244248

249+
this.subscriptions.forEach((d) => d.dispose());
250+
245251
return this.filterDiagnostics(
246252
awaitedDiagnostics,
247253
lastDocumentEndPosition ?? Position.create(0, 0)
@@ -266,7 +272,8 @@ export class CoqLspClient implements CoqLspClientInterface {
266272
return await this.waitUntilFileFullyChecked(
267273
DidOpenTextDocumentNotification.type,
268274
params,
269-
uri
275+
uri,
276+
version
270277
);
271278
}
272279

@@ -302,6 +309,7 @@ export class CoqLspClient implements CoqLspClientInterface {
302309
DidChangeTextDocumentNotification.type,
303310
params,
304311
uri,
312+
version,
305313
oldEndPosition
306314
);
307315
}

src/core/coqProofChecker.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export class CoqProofChecker implements CoqProofCheckerInterface {
126126
auxFileVersion += 1;
127127
// 3.2. Append the proof the end of the aux file
128128
appendFileSync(auxFileUri.fsPath, proof);
129-
130129
// 3.3. Issue update text request
131130
const diagnosticMessage =
132131
await this.coqLspClient.updateTextDocument(
@@ -145,6 +144,15 @@ export class CoqProofChecker implements CoqProofCheckerInterface {
145144

146145
// 3.5. Bring file to the previous state
147146
writeFileSync(auxFileUri.fsPath, sourceFileContent);
147+
148+
// 3.6. Issue update text request
149+
auxFileVersion += 1;
150+
await this.coqLspClient.updateTextDocument(
151+
sourceFileContentPrefix,
152+
"",
153+
auxFileUri,
154+
auxFileVersion
155+
);
148156
}
149157
} finally {
150158
// 4. Issue close text document request

0 commit comments

Comments
 (0)