@@ -11,6 +11,7 @@ import {
11
11
workspace ,
12
12
WorkspaceFolder ,
13
13
WorkspaceFoldersChangeEvent ,
14
+ Memento ,
14
15
} from 'vscode' ;
15
16
import * as lc from 'vscode-languageclient' ;
16
17
@@ -32,17 +33,21 @@ export interface Api {
32
33
}
33
34
34
35
export async function activate ( context : ExtensionContext ) : Promise < Api > {
36
+ // Weave in global state when handling changed active text editor
37
+ const handleChangedActiveTextEd = ( ed : TextEditor | undefined ) =>
38
+ onDidChangeActiveTextEditor ( ed , context . globalState ) ;
39
+
35
40
context . subscriptions . push (
36
41
...[
37
42
configureLanguage ( ) ,
38
43
...registerCommands ( ) ,
39
44
workspace . onDidChangeWorkspaceFolders ( whenChangingWorkspaceFolders ) ,
40
- window . onDidChangeActiveTextEditor ( onDidChangeActiveTextEditor ) ,
45
+ window . onDidChangeActiveTextEditor ( handleChangedActiveTextEd ) ,
41
46
] ,
42
47
) ;
43
48
// Manually trigger the first event to start up server instance if necessary,
44
49
// since VSCode doesn't do that on startup by itself.
45
- onDidChangeActiveTextEditor ( window . activeTextEditor ) ;
50
+ handleChangedActiveTextEd ( window . activeTextEditor ) ;
46
51
47
52
// Migrate the users of multi-project setup for RLS to disable the setting
48
53
// entirely (it's always on now)
@@ -81,13 +86,16 @@ export async function deactivate() {
81
86
/** Tracks dynamically updated progress for the active client workspace for UI purposes. */
82
87
let progressObserver : Disposable | undefined ;
83
88
84
- function onDidChangeActiveTextEditor ( editor : TextEditor | undefined ) {
89
+ function onDidChangeActiveTextEditor (
90
+ editor : TextEditor | undefined ,
91
+ globalState : Memento ,
92
+ ) {
85
93
if ( ! editor || ! editor . document ) {
86
94
return ;
87
95
}
88
96
const { languageId, uri } = editor . document ;
89
97
90
- const workspace = clientWorkspaceForUri ( uri , {
98
+ const workspace = clientWorkspaceForUri ( uri , globalState , {
91
99
initializeIfMissing : languageId === 'rust' || languageId === 'toml' ,
92
100
} ) ;
93
101
if ( ! workspace ) {
@@ -135,6 +143,7 @@ const workspaces: Map<string, ClientWorkspace> = new Map();
135
143
*/
136
144
function clientWorkspaceForUri (
137
145
uri : Uri ,
146
+ globalState : Memento ,
138
147
options ?: { initializeIfMissing : boolean } ,
139
148
) : ClientWorkspace | undefined {
140
149
const rootFolder = workspace . getWorkspaceFolder ( uri ) ;
@@ -149,7 +158,7 @@ function clientWorkspaceForUri(
149
158
150
159
const existing = workspaces . get ( folder . uri . toString ( ) ) ;
151
160
if ( ! existing && options && options . initializeIfMissing ) {
152
- const workspace = new ClientWorkspace ( folder ) ;
161
+ const workspace = new ClientWorkspace ( folder , globalState ) ;
153
162
workspaces . set ( folder . uri . toString ( ) , workspace ) ;
154
163
workspace . autoStart ( ) ;
155
164
}
@@ -173,15 +182,17 @@ export class ClientWorkspace {
173
182
private lc : lc . LanguageClient | null = null ;
174
183
private disposables : Disposable [ ] ;
175
184
private _progress : Observable < WorkspaceProgress > ;
185
+ private globalState : Memento ;
176
186
get progress ( ) {
177
187
return this . _progress ;
178
188
}
179
189
180
- constructor ( folder : WorkspaceFolder ) {
190
+ constructor ( folder : WorkspaceFolder , globalState : Memento ) {
181
191
this . config = RLSConfiguration . loadFromWorkspace ( folder . uri . fsPath ) ;
182
192
this . folder = folder ;
183
193
this . disposables = [ ] ;
184
194
this . _progress = new Observable < WorkspaceProgress > ( { state : 'standby' } ) ;
195
+ this . globalState = globalState ;
185
196
}
186
197
187
198
/**
@@ -198,18 +209,22 @@ export class ClientWorkspace {
198
209
const { createLanguageClient, setupClient, setupProgress } =
199
210
this . config . engine === 'rls' ? rls : rustAnalyzer ;
200
211
201
- const client = await createLanguageClient ( this . folder , {
202
- updateOnStartup : this . config . updateOnStartup ,
203
- revealOutputChannelOn : this . config . revealOutputChannelOn ,
204
- logToFile : this . config . logToFile ,
205
- rustup : {
206
- channel : this . config . channel ,
207
- path : this . config . rustupPath ,
208
- disabled : this . config . rustupDisabled ,
212
+ const client = await createLanguageClient (
213
+ this . folder ,
214
+ {
215
+ updateOnStartup : this . config . updateOnStartup ,
216
+ revealOutputChannelOn : this . config . revealOutputChannelOn ,
217
+ logToFile : this . config . logToFile ,
218
+ rustup : {
219
+ channel : this . config . channel ,
220
+ path : this . config . rustupPath ,
221
+ disabled : this . config . rustupDisabled ,
222
+ } ,
223
+ rls : { path : this . config . rlsPath } ,
224
+ rustAnalyzer : this . config . rustAnalyzer ,
209
225
} ,
210
- rls : { path : this . config . rlsPath } ,
211
- rustAnalyzer : this . config . rustAnalyzer ,
212
- } ) ;
226
+ this . globalState ,
227
+ ) ;
213
228
214
229
client . onDidChangeState ( ( { newState } ) => {
215
230
if ( newState === lc . State . Starting ) {
0 commit comments