Skip to content

Commit e08862c

Browse files
committed
Support $/lean/fileProgress notification.
1 parent 0ba5f75 commit e08862c

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/leanclient.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@ import {
66
LanguageClient,
77
LanguageClientOptions,
88
Protocol2CodeConverter,
9-
ServerOptions
9+
ServerOptions,
10+
VersionedTextDocumentIdentifier
1011
} from 'vscode-languageclient/node'
1112
import * as ls from 'vscode-languageserver-protocol'
1213
import { executablePath, addServerEnvPaths, serverLoggingEnabled, serverLoggingPath, getElaborationDelay } from './config'
1314
import { PlainGoal, PlainTermGoal, ServerProgress } from './leanclientTypes'
1415
import { assert } from './utils/assert'
15-
import * as path from 'path'
16+
17+
export interface LeanFileProgressProcessingInfo {
18+
/** Range which is still being processed */
19+
range: ls.Range;
20+
}
21+
22+
export interface LeanFileProgressParams {
23+
/** The text document to which this progress notification applies. */
24+
textDocument: VersionedTextDocumentIdentifier;
25+
26+
/**
27+
* Array containing the parts of the file which are still being processed.
28+
* The array should be empty if and only if the server is finished processing.
29+
*/
30+
processing: LeanFileProgressProcessingInfo[];
31+
}
1632

1733
const processingMessage = 'processing...'
1834

@@ -48,6 +64,8 @@ export class LeanClient implements Disposable {
4864

4965
private isOpen: Set<string> = new Set()
5066

67+
hasFileProgressSupport: boolean = false
68+
5169
constructor() {
5270
this.subscriptions.push(window.onDidChangeVisibleTextEditors((es) =>
5371
es.forEach((e) => this.open(e.document))));
@@ -81,10 +99,12 @@ export class LeanClient implements Disposable {
8199
},
82100
middleware: {
83101
handleDiagnostics: (uri, diagnostics, next) => {
84-
const processedUntil = diagnostics.find((d) =>
85-
d.message === processingMessage)?.range?.start?.line
86-
this.setProgress({...this.progress, [uri.toString()]: processedUntil})
87-
diagnostics = diagnostics.filter((d) => d.message !== processingMessage);
102+
if (!this.hasFileProgressSupport) {
103+
const processedUntil = diagnostics.find((d) =>
104+
d.message === processingMessage)?.range?.start?.line
105+
this.setProgress({...this.progress, [uri.toString()]: processedUntil})
106+
diagnostics = diagnostics.filter((d) => d.message !== processingMessage);
107+
}
88108
for (const diag of diagnostics) {
89109
if (diag.source === 'Lean 4 server') {
90110
diag.source = 'Lean 4';
@@ -148,6 +168,14 @@ export class LeanClient implements Disposable {
148168
this.isOpen = new Set()
149169
await this.client.onReady();
150170

171+
this.client.onNotification('$/lean/fileProgress', (params: LeanFileProgressParams) => {
172+
this.hasFileProgressSupport = true;
173+
const uri = this.client.protocol2CodeConverter.asUri(params.textDocument.uri)
174+
const processedUntil = params.processing.length === 0 ? undefined :
175+
Math.min(...params.processing.map((p) => p.range.start.line));
176+
this.setProgress({...this.progress, [uri.toString()]: processedUntil})
177+
});
178+
151179
// HACK
152180
(this.client as any)._serverProcess.stderr.on('data', () =>
153181
this.client.outputChannel.show(true))

0 commit comments

Comments
 (0)