@@ -67,7 +67,7 @@ export class LeanClientProvider implements Disposable {
67
67
const client = this . clients . get ( path )
68
68
void client . restart ( )
69
69
} else {
70
- void this . ensureClient ( this . getDocument ( path ) , version ) ;
70
+ void this . ensureClient ( this . getDocument ( path ) . uri , version ) ;
71
71
}
72
72
}
73
73
} catch {
@@ -102,17 +102,20 @@ export class LeanClientProvider implements Disposable {
102
102
void this . activeClient ?. restart ( ) ;
103
103
}
104
104
105
- didOpenEditor ( document : TextDocument ) {
105
+ async didOpenEditor ( document : TextDocument ) {
106
106
// All open .lean files are assumed to be Lean 4 files.
107
107
// We need to do this because by default, .lean is associated with language id `lean`,
108
108
// i.e. Lean 3. vscode-lean is expected to yield when isLean4Project is true.
109
109
if ( document . languageId === 'lean' ) {
110
110
// Only change the document language for *visible* documents,
111
111
// because this closes and then reopens the document.
112
- void languages . setTextDocumentLanguage ( document , 'lean4' ) ;
113
- } else if ( document . languageId = == 'lean4' ) {
114
- void this . ensureClient ( document , null ) ;
112
+ await languages . setTextDocumentLanguage ( document , 'lean4' ) ;
113
+ } else if ( document . languageId ! == 'lean4' ) {
114
+ return ;
115
115
}
116
+
117
+ const client = await this . ensureClient ( document . uri , null ) ;
118
+ await client . openLean4Document ( document )
116
119
}
117
120
118
121
getClient ( uri : Uri ) {
@@ -123,18 +126,18 @@ export class LeanClientProvider implements Disposable {
123
126
return Array . from ( this . clients . values ( ) ) ;
124
127
}
125
128
126
- async ensureClient ( doc : TextDocument , versionInfo : LeanVersion | null ) {
127
- let folder = workspace . getWorkspaceFolder ( doc . uri ) ;
129
+ async ensureClient ( uri : Uri , versionInfo : LeanVersion | null ) : Promise < LeanClient > {
130
+ let folder = workspace . getWorkspaceFolder ( uri ) ;
128
131
if ( ! folder && workspace . workspaceFolders ) {
129
132
// Could be that doc.uri.scheme === 'untitled'.
130
133
workspace . workspaceFolders . forEach ( ( f ) => {
131
- if ( f . uri . fsPath && doc . uri . fsPath . startsWith ( f . uri . fsPath ) ) {
134
+ if ( f . uri . fsPath && uri . fsPath . startsWith ( f . uri . fsPath ) ) {
132
135
folder = f ;
133
136
}
134
137
} ) ;
135
138
}
136
139
137
- const folderUri = folder ? folder . uri : doc . uri ;
140
+ const folderUri = folder ? folder . uri : uri ;
138
141
const path = folderUri ?. toString ( ) ;
139
142
let client : LeanClient = null ;
140
143
if ( this . clients . has ( path ) ) {
@@ -166,18 +169,20 @@ export class LeanClientProvider implements Disposable {
166
169
this . progressChangedEmitter . fire ( arg ) ;
167
170
} ) ;
168
171
172
+ this . pending . delete ( path ) ;
173
+ this . clientAddedEmitter . fire ( client ) ;
174
+
169
175
if ( ! versionInfo . error ) {
170
176
// we are ready to start, otherwise some sort of install might be happening
171
177
// as a result of UI options shown by testLeanVersion.
172
- void client . start ( ) ;
178
+ await client . start ( ) ;
173
179
}
174
-
175
- this . pending . delete ( path ) ;
176
- this . clientAddedEmitter . fire ( client ) ;
177
180
}
178
181
179
182
// tell the InfoView about this activated client.
180
183
this . activeClient = client ;
184
+
185
+ return client ;
181
186
}
182
187
183
188
dispose ( ) : void {
0 commit comments