@@ -13,18 +13,15 @@ import {
1313 WorkspaceFolder ,
1414} from 'vscode'
1515import {
16- ClientCapabilities ,
16+ BaseLanguageClient ,
1717 DiagnosticSeverity ,
1818 DidChangeTextDocumentParams ,
1919 DidCloseTextDocumentParams ,
2020 DocumentFilter ,
2121 InitializeResult ,
22- LanguageClient ,
2322 LanguageClientOptions ,
2423 RevealOutputChannelOn ,
25- ServerOptions ,
2624 State ,
27- StaticFeature ,
2825} from 'vscode-languageclient/node'
2926
3027import {
@@ -33,25 +30,13 @@ import {
3330 LeanFileProgressProcessingInfo ,
3431 ServerStoppedReason ,
3532} from '@leanprover/infoview-api'
36- import {
37- getElaborationDelay ,
38- getFallBackToStringOccurrenceHighlighting ,
39- serverArgs ,
40- serverLoggingEnabled ,
41- serverLoggingPath ,
42- shouldAutofocusOutput ,
43- } from './config'
33+ import { getElaborationDelay , getFallBackToStringOccurrenceHighlighting , shouldAutofocusOutput } from './config'
4434import { logger } from './utils/logger'
4535// @ts -ignore
4636import path from 'path'
4737import { SemVer } from 'semver'
48- import {
49- c2pConverter ,
50- LeanPublishDiagnosticsParams ,
51- p2cConverter ,
52- patchConverters ,
53- setDependencyBuildMode ,
54- } from './utils/converters'
38+ import { setupClient } from './leanclientsetup'
39+ import { c2pConverter , LeanPublishDiagnosticsParams , p2cConverter , setDependencyBuildMode } from './utils/converters'
5540import { elanInstalledToolchains } from './utils/elan'
5641import { ExtUri , parseExtUri , toExtUri } from './utils/exturi'
5742import { leanRunner } from './utils/leanCmdRunner'
@@ -61,23 +46,14 @@ import {
6146 displayNotificationWithOptionalInput ,
6247 displayNotificationWithOutput ,
6348} from './utils/notifs'
64- import { willUseLakeServer } from './utils/projectInfo'
65-
66- interface LeanClientCapabilties {
67- silentDiagnosticSupport ?: boolean | undefined
68- }
69-
70- const leanClientCapabilities : LeanClientCapabilties = {
71- silentDiagnosticSupport : true ,
72- }
7349
7450const escapeRegExp = ( s : string ) => s . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
7551
7652export type ServerProgress = Map < ExtUri , LeanFileProgressProcessingInfo [ ] >
7753
7854export class LeanClient implements Disposable {
7955 running : boolean
80- private client : LanguageClient | undefined
56+ private client : BaseLanguageClient | undefined
8157 private outputChannel : OutputChannel
8258 folderUri : ExtUri
8359 private subscriptions : Disposable [ ] = [ ]
@@ -125,7 +101,15 @@ export class LeanClient implements Disposable {
125101 private serverFailedEmitter = new EventEmitter < string > ( )
126102 serverFailed = this . serverFailedEmitter . event
127103
128- constructor ( folderUri : ExtUri , outputChannel : OutputChannel ) {
104+ constructor (
105+ folderUri : ExtUri ,
106+ outputChannel : OutputChannel ,
107+ private setupClient : (
108+ toolchainOverride : string | undefined ,
109+ folderUri : ExtUri ,
110+ clientOptions : LanguageClientOptions ,
111+ ) => Promise < BaseLanguageClient > ,
112+ ) {
129113 this . outputChannel = outputChannel
130114 this . folderUri = folderUri
131115 this . subscriptions . push ( new Disposable ( ( ) => this . staleDepNotifier ?. dispose ( ) ) )
@@ -272,7 +256,7 @@ export class LeanClient implements Disposable {
272256 const toolchainOverride : string | undefined =
273257 toolchainOverrideResult . kind === 'Override' ? toolchainOverrideResult . toolchain : undefined
274258
275- this . client = await this . setupClient ( toolchainOverride )
259+ this . client = await setupClient ( toolchainOverride , this . folderUri , this . obtainClientOptions ( ) )
276260
277261 let insideRestart = true
278262 try {
@@ -521,43 +505,6 @@ export class LeanClient implements Disposable {
521505 return this . running ? this . client ?. initializeResult : undefined
522506 }
523507
524- private async determineServerOptions ( toolchainOverride : string | undefined ) : Promise < ServerOptions > {
525- const env = Object . assign ( { } , process . env )
526- if ( serverLoggingEnabled ( ) ) {
527- env . LEAN_SERVER_LOG_DIR = serverLoggingPath ( )
528- }
529-
530- const [ serverExecutable , options ] = await this . determineExecutable ( )
531- if ( toolchainOverride ) {
532- options . unshift ( '+' + toolchainOverride )
533- }
534-
535- const cwd = this . folderUri . scheme === 'file' ? this . folderUri . fsPath : undefined
536- if ( cwd ) {
537- // Add folder name to command-line so that it shows up in `ps aux`.
538- options . push ( cwd )
539- } else {
540- options . push ( 'untitled' )
541- }
542-
543- return {
544- command : serverExecutable ,
545- args : options . concat ( serverArgs ( ) ) ,
546- options : {
547- cwd,
548- env,
549- } ,
550- }
551- }
552-
553- private async determineExecutable ( ) : Promise < [ string , string [ ] ] > {
554- if ( await willUseLakeServer ( this . folderUri ) ) {
555- return [ 'lake' , [ 'serve' , '--' ] ]
556- } else {
557- return [ 'lean' , [ '--server' ] ]
558- }
559- }
560-
561508 private obtainClientOptions ( ) : LanguageClientOptions {
562509 const documentSelector : DocumentFilter = {
563510 language : 'lean4' ,
@@ -688,25 +635,4 @@ export class LeanClient implements Disposable {
688635 } ,
689636 }
690637 }
691-
692- private async setupClient ( toolchainOverride : string | undefined ) : Promise < LanguageClient > {
693- const serverOptions : ServerOptions = await this . determineServerOptions ( toolchainOverride )
694- const clientOptions : LanguageClientOptions = this . obtainClientOptions ( )
695-
696- const client = new LanguageClient ( 'lean4' , 'Lean 4' , serverOptions , clientOptions )
697- const leanCapabilityFeature : StaticFeature = {
698- initialize ( _1 , _2 ) { } ,
699- getState ( ) {
700- return { kind : 'static' }
701- } ,
702- fillClientCapabilities ( capabilities : ClientCapabilities & { lean ?: LeanClientCapabilties | undefined } ) {
703- capabilities . lean = leanClientCapabilities
704- } ,
705- dispose ( ) { } ,
706- }
707- client . registerFeature ( leanCapabilityFeature )
708-
709- patchConverters ( client . protocol2CodeConverter , client . code2ProtocolConverter )
710- return client
711- }
712638}
0 commit comments