@@ -11,6 +11,7 @@ import {
1111 workspace ,
1212 WorkspaceFolder ,
1313 WorkspaceFoldersChangeEvent ,
14+ Memento ,
1415} from 'vscode' ;
1516import * as lc from 'vscode-languageclient' ;
1617
@@ -32,17 +33,21 @@ export interface Api {
3233}
3334
3435export 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+
3540 context . subscriptions . push (
3641 ...[
3742 configureLanguage ( ) ,
3843 ...registerCommands ( ) ,
3944 workspace . onDidChangeWorkspaceFolders ( whenChangingWorkspaceFolders ) ,
40- window . onDidChangeActiveTextEditor ( onDidChangeActiveTextEditor ) ,
45+ window . onDidChangeActiveTextEditor ( handleChangedActiveTextEd ) ,
4146 ] ,
4247 ) ;
4348 // Manually trigger the first event to start up server instance if necessary,
4449 // since VSCode doesn't do that on startup by itself.
45- onDidChangeActiveTextEditor ( window . activeTextEditor ) ;
50+ handleChangedActiveTextEd ( window . activeTextEditor ) ;
4651
4752 // Migrate the users of multi-project setup for RLS to disable the setting
4853 // entirely (it's always on now)
@@ -81,13 +86,16 @@ export async function deactivate() {
8186/** Tracks dynamically updated progress for the active client workspace for UI purposes. */
8287let progressObserver : Disposable | undefined ;
8388
84- function onDidChangeActiveTextEditor ( editor : TextEditor | undefined ) {
89+ function onDidChangeActiveTextEditor (
90+ editor : TextEditor | undefined ,
91+ globalState : Memento ,
92+ ) {
8593 if ( ! editor || ! editor . document ) {
8694 return ;
8795 }
8896 const { languageId, uri } = editor . document ;
8997
90- const workspace = clientWorkspaceForUri ( uri , {
98+ const workspace = clientWorkspaceForUri ( uri , globalState , {
9199 initializeIfMissing : languageId === 'rust' || languageId === 'toml' ,
92100 } ) ;
93101 if ( ! workspace ) {
@@ -135,6 +143,7 @@ const workspaces: Map<string, ClientWorkspace> = new Map();
135143 */
136144function clientWorkspaceForUri (
137145 uri : Uri ,
146+ globalState : Memento ,
138147 options ?: { initializeIfMissing : boolean } ,
139148) : ClientWorkspace | undefined {
140149 const rootFolder = workspace . getWorkspaceFolder ( uri ) ;
@@ -149,7 +158,7 @@ function clientWorkspaceForUri(
149158
150159 const existing = workspaces . get ( folder . uri . toString ( ) ) ;
151160 if ( ! existing && options && options . initializeIfMissing ) {
152- const workspace = new ClientWorkspace ( folder ) ;
161+ const workspace = new ClientWorkspace ( folder , globalState ) ;
153162 workspaces . set ( folder . uri . toString ( ) , workspace ) ;
154163 workspace . autoStart ( ) ;
155164 }
@@ -173,15 +182,17 @@ export class ClientWorkspace {
173182 private lc : lc . LanguageClient | null = null ;
174183 private disposables : Disposable [ ] ;
175184 private _progress : Observable < WorkspaceProgress > ;
185+ private globalState : Memento ;
176186 get progress ( ) {
177187 return this . _progress ;
178188 }
179189
180- constructor ( folder : WorkspaceFolder ) {
190+ constructor ( folder : WorkspaceFolder , globalState : Memento ) {
181191 this . config = RLSConfiguration . loadFromWorkspace ( folder . uri . fsPath ) ;
182192 this . folder = folder ;
183193 this . disposables = [ ] ;
184194 this . _progress = new Observable < WorkspaceProgress > ( { state : 'standby' } ) ;
195+ this . globalState = globalState ;
185196 }
186197
187198 /**
@@ -198,18 +209,22 @@ export class ClientWorkspace {
198209 const { createLanguageClient, setupClient, setupProgress } =
199210 this . config . engine === 'rls' ? rls : rustAnalyzer ;
200211
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 ,
209225 } ,
210- rls : { path : this . config . rlsPath } ,
211- rustAnalyzer : this . config . rustAnalyzer ,
212- } ) ;
226+ this . globalState ,
227+ ) ;
213228
214229 client . onDidChangeState ( ( { newState } ) => {
215230 if ( newState === lc . State . Starting ) {
0 commit comments