@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22import * as lc from "vscode-languageclient/node" ;
33import * as ra from "./lsp_ext" ;
44
5- import { Config , substituteVSCodeVariables } from "./config" ;
5+ import { Config , prepareVSCodeConfig } from "./config" ;
66import { createClient } from "./client" ;
77import {
88 executeDiscoverProject ,
@@ -54,7 +54,7 @@ export async function discoverWorkspace(
5454 command : string [ ] ,
5555 options : ExecOptions
5656) : Promise < JsonProject > {
57- const paths = files . map ( ( f ) => f . uri . fsPath ) . join ( " " ) ;
57+ const paths = files . map ( ( f ) => `" ${ f . uri . fsPath } "` ) . join ( " " ) ;
5858 const joinedCommand = command . join ( " " ) ;
5959 const data = await executeDiscoverProject ( `${ joinedCommand } ${ paths } ` , options ) ;
6060 return JSON . parse ( data ) as JsonProject ;
@@ -71,7 +71,7 @@ export type CtxInit = Ctx & {
7171
7272export class Ctx {
7373 readonly statusBar : vscode . StatusBarItem ;
74- readonly config : Config ;
74+ config : Config ;
7575 readonly workspace : Workspace ;
7676
7777 private _client : lc . LanguageClient | undefined ;
@@ -82,7 +82,6 @@ export class Ctx {
8282 private state : PersistentState ;
8383 private commandFactories : Record < string , CommandFactory > ;
8484 private commandDisposables : Disposable [ ] ;
85- private discoveredWorkspaces : JsonProject [ ] | undefined ;
8685
8786 get client ( ) {
8887 return this . _client ;
@@ -193,20 +192,24 @@ export class Ctx {
193192 if ( discoverProjectCommand ) {
194193 const workspaces : JsonProject [ ] = await Promise . all (
195194 vscode . workspace . workspaceFolders ! . map ( async ( folder ) : Promise < JsonProject > => {
196- return discoverWorkspace (
197- vscode . workspace . textDocuments ,
198- discoverProjectCommand ,
199- { cwd : folder . uri . fsPath }
200- ) ;
195+ const rustDocuments = vscode . workspace . textDocuments . filter ( isRustDocument ) ;
196+ return discoverWorkspace ( rustDocuments , discoverProjectCommand , {
197+ cwd : folder . uri . fsPath ,
198+ } ) ;
201199 } )
202200 ) ;
203201
204- this . discoveredWorkspaces = workspaces ;
202+ this . addToDiscoveredWorkspaces ( workspaces ) ;
205203 }
206204
207- const initializationOptions = substituteVSCodeVariables ( rawInitializationOptions ) ;
208- // this appears to be load-bearing, for better or worse.
209- await initializationOptions . update ( "linkedProjects" , this . discoveredWorkspaces ) ;
205+ const initializationOptions = prepareVSCodeConfig (
206+ rawInitializationOptions ,
207+ ( key , obj ) => {
208+ if ( key === "linkedProjects" ) {
209+ obj [ "linkedProjects" ] = this . config . discoveredWorkspaces ;
210+ }
211+ }
212+ ) ;
210213
211214 this . _client = await createClient (
212215 this . traceOutputChannel ,
@@ -288,6 +291,17 @@ export class Ctx {
288291 return this . _serverPath ;
289292 }
290293
294+ addToDiscoveredWorkspaces ( workspaces : JsonProject [ ] ) {
295+ for ( const workspace of workspaces ) {
296+ const index = this . config . discoveredWorkspaces . indexOf ( workspace ) ;
297+ if ( ~ index ) {
298+ this . config . discoveredWorkspaces [ index ] = workspace ;
299+ } else {
300+ this . config . discoveredWorkspaces . push ( workspace ) ;
301+ }
302+ }
303+ }
304+
291305 private updateCommands ( forceDisable ?: "disable" ) {
292306 this . commandDisposables . forEach ( ( disposable ) => disposable . dispose ( ) ) ;
293307 this . commandDisposables = [ ] ;
0 commit comments