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 { 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 version = this . client . initializeResult ?. serverInfo ?. version
545561 if ( version && new SemVer ( version ) . compare ( '0.2.0' ) < 0 ) {
546562 if ( this . staleDepNotifier ) {
@@ -708,6 +724,9 @@ export class LeanClient implements Disposable {
708724
709725 this . noPrompt = false
710726 this . progress = new Map ( )
727+ this . diagnosticCollection ?. vsCodeCollection . dispose ( )
728+ this . diagnosticCollection ?. dispose ( )
729+ this . diagnosticCollection = undefined
711730 this . client = undefined
712731 this . openServerDocuments = new Set ( )
713732 this . running = false
@@ -779,7 +798,7 @@ export class LeanClient implements Disposable {
779798 }
780799
781800 getDiagnostics ( ) : DiagnosticCollection | undefined {
782- return this . running ? this . client ?. diagnostics : undefined
801+ return this . running ? this . diagnosticCollection ?. vsCodeCollection : undefined
783802 }
784803
785804 get initializeResult ( ) : InitializeResult | undefined {
@@ -873,18 +892,11 @@ export class LeanClient implements Disposable {
873892 }
874893 return next ( type , param )
875894 } ,
876- handleDiagnostics : ( uri , diagnostics , next ) => {
877- const diagnosticsInVsCode = diagnostics . filter ( d => ! ( 'isSilent' in d && d . isSilent ) )
878- next ( uri , diagnosticsInVsCode )
879- const uri_ = c2pConverter . asUri ( uri )
880- const diagnostics_ : LeanDiagnostic [ ] = [ ]
881- for ( const d of diagnostics ) {
882- const d_ : LeanDiagnostic = {
883- ...c2pConverter . asDiagnostic ( d ) ,
884- }
885- diagnostics_ . push ( d_ )
886- }
887- this . diagnosticsEmitter . fire ( { uri : uri_ , diagnostics : diagnostics_ } )
895+ handleDiagnostics : ( ) => {
896+ // Suppress the default diagnostics handling by the LanguageClient.
897+ // We handle diagnostics ourselves via a custom notification handler
898+ // so that we can access the full LeanPublishDiagnosticsParams
899+ // (including version and isIncremental).
888900 } ,
889901
890902 didOpen : async ( doc , next ) => {
0 commit comments