44 Disposable ,
55 EventEmitter ,
66 FileSystemWatcher ,
7+ languages ,
78 OutputChannel ,
89 Progress ,
910 ProgressLocation ,
@@ -32,7 +33,6 @@ import {
3233} from 'vscode-languageclient/node'
3334
3435import {
35- LeanDiagnostic ,
3636 LeanFileProgressParams ,
3737 LeanFileProgressProcessingInfo ,
3838 LeanServerCapabilities ,
@@ -52,6 +52,7 @@ import { logger } from './utils/logger'
5252import * as fs from 'fs'
5353import { glob } from 'glob'
5454import * as semver from 'semver'
55+ import { DiagnosticChangeEvent , LeanClientDiagnosticCollection } from './diagnostics'
5556import { formatCommandExecutionOutput } from './utils/batch'
5657import {
5758 c2pConverter ,
@@ -98,11 +99,13 @@ function logConfig(): LogConfig | undefined {
9899}
99100
100101interface LeanClientCapabilties {
102+ incrementalDiagnosticSupport ?: boolean
101103 silentDiagnosticSupport ?: boolean
102104 rpcWireFormat ?: RpcWireFormat
103105}
104106
105107const leanClientCapabilities : LeanClientCapabilties = {
108+ incrementalDiagnosticSupport : true ,
106109 silentDiagnosticSupport : true ,
107110 rpcWireFormat : 'v1'
108111}
@@ -140,6 +143,8 @@ export class LeanClient implements Disposable {
140143 private didChangeEmitter = new EventEmitter < DidChangeTextDocumentParams > ( )
141144 didChange = this . didChangeEmitter . event
142145
146+ private diagnosticCollection : LeanClientDiagnosticCollection | undefined
147+
143148 private diagnosticsEmitter = new EventEmitter < LeanPublishDiagnosticsParams > ( )
144149 diagnostics = this . diagnosticsEmitter . event
145150
@@ -540,7 +545,18 @@ export class LeanClient implements Disposable {
540545 }
541546 }
542547 } )
548+ this . diagnosticCollection ?. dispose ( )
549+ const vsCodeCollection = languages . createDiagnosticCollection ( 'lean4' )
550+ this . diagnosticCollection = new LeanClientDiagnosticCollection ( vsCodeCollection )
551+ this . diagnosticCollection . onDidChangeDiagnostics ( ( e : DiagnosticChangeEvent ) => {
552+ this . diagnosticsEmitter . fire ( e . accumulatedParams ( ) )
553+ } )
554+ this . client . onNotification ( 'textDocument/publishDiagnostics' , ( params : LeanPublishDiagnosticsParams ) => {
555+ this . diagnosticCollection ?. publishDiagnostics ( params )
556+ } )
557+
543558 await this . client . start ( )
559+
544560 const rawVersion = this . client . initializeResult ?. serverInfo ?. version
545561 const version = rawVersion !== undefined ? semver . parse ( rawVersion ) : null
546562 if ( version !== null && version . compare ( '0.2.0' ) < 0 ) {
@@ -709,6 +725,9 @@ export class LeanClient implements Disposable {
709725
710726 this . noPrompt = false
711727 this . progress = new Map ( )
728+ this . diagnosticCollection ?. vsCodeCollection . dispose ( )
729+ this . diagnosticCollection ?. dispose ( )
730+ this . diagnosticCollection = undefined
712731 this . client = undefined
713732 this . openServerDocuments = new Set ( )
714733 this . running = false
@@ -780,7 +799,7 @@ export class LeanClient implements Disposable {
780799 }
781800
782801 getDiagnostics ( ) : DiagnosticCollection | undefined {
783- return this . running ? this . client ?. diagnostics : undefined
802+ return this . running ? this . diagnosticCollection ?. vsCodeCollection : undefined
784803 }
785804
786805 get initializeResult ( ) : InitializeResult | undefined {
@@ -874,18 +893,11 @@ export class LeanClient implements Disposable {
874893 }
875894 return next ( type , param )
876895 } ,
877- handleDiagnostics : ( uri , diagnostics , next ) => {
878- const diagnosticsInVsCode = diagnostics . filter ( d => ! ( 'isSilent' in d && d . isSilent ) )
879- next ( uri , diagnosticsInVsCode )
880- const uri_ = c2pConverter . asUri ( uri )
881- const diagnostics_ : LeanDiagnostic [ ] = [ ]
882- for ( const d of diagnostics ) {
883- const d_ : LeanDiagnostic = {
884- ...c2pConverter . asDiagnostic ( d ) ,
885- }
886- diagnostics_ . push ( d_ )
887- }
888- this . diagnosticsEmitter . fire ( { uri : uri_ , diagnostics : diagnostics_ } )
896+ handleDiagnostics : ( ) => {
897+ // Suppress the default diagnostics handling by the LanguageClient.
898+ // We handle diagnostics ourselves via a custom notification handler
899+ // so that we can access the full LeanPublishDiagnosticsParams
900+ // (including version and isIncremental).
889901 } ,
890902
891903 didOpen : async ( doc , next ) => {
0 commit comments