@@ -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,12 @@ 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 { c2pConverter , LeanPublishDiagnosticsParams , p2cConverter , setDependencyBuildMode } from './utils/converters'
5539import { elanInstalledToolchains } from './utils/elan'
5640import { ExtUri , parseExtUri , toExtUri } from './utils/exturi'
5741import { leanRunner } from './utils/leanCmdRunner'
@@ -61,7 +45,6 @@ import {
6145 displayNotificationWithOptionalInput ,
6246 displayNotificationWithOutput ,
6347} from './utils/notifs'
64- import { willUseLakeServer } from './utils/projectInfo'
6548
6649interface LeanClientCapabilties {
6750 silentDiagnosticSupport ?: boolean | undefined
@@ -77,7 +60,7 @@ export type ServerProgress = Map<ExtUri, LeanFileProgressProcessingInfo[]>
7760
7861export class LeanClient implements Disposable {
7962 running : boolean
80- private client : LanguageClient | undefined
63+ private client : BaseLanguageClient | undefined
8164 private outputChannel : OutputChannel
8265 folderUri : ExtUri
8366 private subscriptions : Disposable [ ] = [ ]
@@ -125,7 +108,15 @@ export class LeanClient implements Disposable {
125108 private serverFailedEmitter = new EventEmitter < string > ( )
126109 serverFailed = this . serverFailedEmitter . event
127110
128- constructor ( folderUri : ExtUri , outputChannel : OutputChannel ) {
111+ constructor (
112+ folderUri : ExtUri ,
113+ outputChannel : OutputChannel ,
114+ private setupClient : (
115+ toolchainOverride : string | undefined ,
116+ clientOptions : LanguageClientOptions ,
117+ folderUri : ExtUri ,
118+ ) => Promise < BaseLanguageClient > ,
119+ ) {
129120 this . outputChannel = outputChannel
130121 this . folderUri = folderUri
131122 this . subscriptions . push ( new Disposable ( ( ) => this . staleDepNotifier ?. dispose ( ) ) )
@@ -272,7 +263,7 @@ export class LeanClient implements Disposable {
272263 const toolchainOverride : string | undefined =
273264 toolchainOverrideResult . kind === 'Override' ? toolchainOverrideResult . toolchain : undefined
274265
275- this . client = await this . setupClient ( toolchainOverride )
266+ this . client = await this . setupClient ( toolchainOverride , this . obtainClientOptions ( ) , this . folderUri )
276267
277268 let insideRestart = true
278269 try {
@@ -521,43 +512,6 @@ export class LeanClient implements Disposable {
521512 return this . running ? this . client ?. initializeResult : undefined
522513 }
523514
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-
561515 private obtainClientOptions ( ) : LanguageClientOptions {
562516 const documentSelector : DocumentFilter = {
563517 language : 'lean4' ,
@@ -688,25 +642,4 @@ export class LeanClient implements Disposable {
688642 } ,
689643 }
690644 }
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- }
712645}
0 commit comments