@@ -14,34 +14,26 @@ import {
14
14
WorkspaceFolder ,
15
15
} from 'vscode'
16
16
import {
17
+ BaseLanguageClient ,
17
18
DiagnosticSeverity ,
18
19
DidChangeTextDocumentParams ,
19
20
DidCloseTextDocumentParams ,
20
21
DocumentFilter ,
21
22
InitializeResult ,
22
- LanguageClient ,
23
23
LanguageClientOptions ,
24
24
PublishDiagnosticsParams ,
25
25
RevealOutputChannelOn ,
26
- ServerOptions ,
27
26
State ,
28
27
} from 'vscode-languageclient/node'
29
28
import * as ls from 'vscode-languageserver-protocol'
30
29
31
30
import { LeanFileProgressParams , LeanFileProgressProcessingInfo , ServerStoppedReason } from '@leanprover/infoview-api'
32
- import {
33
- getElaborationDelay ,
34
- getFallBackToStringOccurrenceHighlighting ,
35
- serverArgs ,
36
- serverLoggingEnabled ,
37
- serverLoggingPath ,
38
- shouldAutofocusOutput ,
39
- } from './config'
31
+ import { getElaborationDelay , getFallBackToStringOccurrenceHighlighting , shouldAutofocusOutput } from './config'
40
32
import { logger } from './utils/logger'
41
33
// @ts -ignore
42
34
import path from 'path'
43
35
import { SemVer } from 'semver'
44
- import { c2pConverter , p2cConverter , patchConverters , setDependencyBuildMode } from './utils/converters'
36
+ import { c2pConverter , p2cConverter , setDependencyBuildMode } from './utils/converters'
45
37
import { elanInstalledToolchains } from './utils/elan'
46
38
import { ExtUri , parseExtUri , toExtUri } from './utils/exturi'
47
39
import { leanRunner } from './utils/leanCmdRunner'
@@ -51,15 +43,14 @@ import {
51
43
displayNotificationWithOptionalInput ,
52
44
displayNotificationWithOutput ,
53
45
} from './utils/notifs'
54
- import { willUseLakeServer } from './utils/projectInfo'
55
46
56
47
const escapeRegExp = ( s : string ) => s . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
57
48
58
49
export type ServerProgress = Map < ExtUri , LeanFileProgressProcessingInfo [ ] >
59
50
60
51
export class LeanClient implements Disposable {
61
52
running : boolean
62
- private client : LanguageClient | undefined
53
+ private client : BaseLanguageClient | undefined
63
54
private outputChannel : OutputChannel
64
55
folderUri : ExtUri
65
56
private subscriptions : Disposable [ ] = [ ]
@@ -107,7 +98,15 @@ export class LeanClient implements Disposable {
107
98
private serverFailedEmitter = new EventEmitter < string > ( )
108
99
serverFailed = this . serverFailedEmitter . event
109
100
110
- constructor ( folderUri : ExtUri , outputChannel : OutputChannel ) {
101
+ constructor (
102
+ folderUri : ExtUri ,
103
+ outputChannel : OutputChannel ,
104
+ private setupClient : (
105
+ toolchainOverride : string | undefined ,
106
+ clientOptions : LanguageClientOptions ,
107
+ folderUri : ExtUri ,
108
+ ) => Promise < BaseLanguageClient > ,
109
+ ) {
111
110
this . outputChannel = outputChannel
112
111
this . folderUri = folderUri
113
112
this . subscriptions . push ( new Disposable ( ( ) => this . staleDepNotifier ?. dispose ( ) ) )
@@ -254,7 +253,7 @@ export class LeanClient implements Disposable {
254
253
const toolchainOverride : string | undefined =
255
254
toolchainOverrideResult . kind === 'Override' ? toolchainOverrideResult . toolchain : undefined
256
255
257
- this . client = await this . setupClient ( toolchainOverride )
256
+ this . client = await this . setupClient ( toolchainOverride , this . obtainClientOptions ( ) , this . folderUri )
258
257
259
258
let insideRestart = true
260
259
try {
@@ -503,43 +502,6 @@ export class LeanClient implements Disposable {
503
502
return this . running ? this . client ?. initializeResult : undefined
504
503
}
505
504
506
- private async determineServerOptions ( toolchainOverride : string | undefined ) : Promise < ServerOptions > {
507
- const env = Object . assign ( { } , process . env )
508
- if ( serverLoggingEnabled ( ) ) {
509
- env . LEAN_SERVER_LOG_DIR = serverLoggingPath ( )
510
- }
511
-
512
- const [ serverExecutable , options ] = await this . determineExecutable ( )
513
- if ( toolchainOverride ) {
514
- options . unshift ( '+' + toolchainOverride )
515
- }
516
-
517
- const cwd = this . folderUri . scheme === 'file' ? this . folderUri . fsPath : undefined
518
- if ( cwd ) {
519
- // Add folder name to command-line so that it shows up in `ps aux`.
520
- options . push ( cwd )
521
- } else {
522
- options . push ( 'untitled' )
523
- }
524
-
525
- return {
526
- command : serverExecutable ,
527
- args : options . concat ( serverArgs ( ) ) ,
528
- options : {
529
- cwd,
530
- env,
531
- } ,
532
- }
533
- }
534
-
535
- private async determineExecutable ( ) : Promise < [ string , string [ ] ] > {
536
- if ( await willUseLakeServer ( this . folderUri ) ) {
537
- return [ 'lake' , [ 'serve' , '--' ] ]
538
- } else {
539
- return [ 'lean' , [ '--server' ] ]
540
- }
541
- }
542
-
543
505
private obtainClientOptions ( ) : LanguageClientOptions {
544
506
const documentSelector : DocumentFilter = {
545
507
language : 'lean4' ,
@@ -668,14 +630,4 @@ export class LeanClient implements Disposable {
668
630
} ,
669
631
}
670
632
}
671
-
672
- private async setupClient ( toolchainOverride : string | undefined ) : Promise < LanguageClient > {
673
- const serverOptions : ServerOptions = await this . determineServerOptions ( toolchainOverride )
674
- const clientOptions : LanguageClientOptions = this . obtainClientOptions ( )
675
-
676
- const client = new LanguageClient ( 'lean4' , 'Lean 4' , serverOptions , clientOptions )
677
-
678
- patchConverters ( client . protocol2CodeConverter , client . code2ProtocolConverter )
679
- return client
680
- }
681
633
}
0 commit comments