11import * as vscode from "vscode" ;
2- import type * as lc from "vscode-languageclient/node" ;
2+ import * as lc from "vscode-languageclient/node" ;
33import * as ra from "./lsp_ext" ;
44
55import { Config , prepareVSCodeConfig } from "./config" ;
@@ -22,6 +22,7 @@ import {
2222import { execRevealDependency } from "./commands" ;
2323import { PersistentState } from "./persistent_state" ;
2424import { bootstrap } from "./bootstrap" ;
25+ import type { RustAnalyzerExtensionApi } from "./main" ;
2526
2627// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
2728// only those are in use. We use "Empty" to represent these scenarios
@@ -64,7 +65,7 @@ export type CtxInit = Ctx & {
6465 readonly client : lc . LanguageClient ;
6566} ;
6667
67- export class Ctx {
68+ export class Ctx implements RustAnalyzerExtensionApi {
6869 readonly statusBar : vscode . StatusBarItem ;
6970 config : Config ;
7071 readonly workspace : Workspace ;
@@ -189,8 +190,11 @@ export class Ctx {
189190 if ( this . config . discoverProjectRunner ) {
190191 const command = `${ this . config . discoverProjectRunner } .discoverWorkspaceCommand` ;
191192 log . info ( `running command: ${ command } ` ) ;
192- const project : JsonProject = await vscode . commands . executeCommand ( command ) ;
193- this . addToDiscoveredWorkspaces ( [ project ] ) ;
193+ const uris = vscode . workspace . textDocuments
194+ . filter ( isRustDocument )
195+ . map ( ( document ) => document . uri ) ;
196+ const projects : JsonProject [ ] = await vscode . commands . executeCommand ( command , uris ) ;
197+ this . setWorkspaces ( projects ) ;
194198 }
195199
196200 if ( this . workspace . kind === "Detached Files" ) {
@@ -342,15 +346,17 @@ export class Ctx {
342346 return this . _serverPath ;
343347 }
344348
345- addToDiscoveredWorkspaces ( workspaces : JsonProject [ ] ) {
346- for ( const workspace of workspaces ) {
347- const index = this . config . discoveredWorkspaces . indexOf ( workspace ) ;
348- if ( ~ index ) {
349- this . config . discoveredWorkspaces [ index ] = workspace ;
350- } else {
351- this . config . discoveredWorkspaces . push ( workspace ) ;
352- }
353- }
349+ setWorkspaces ( workspaces : JsonProject [ ] ) {
350+ this . config . discoveredWorkspaces = workspaces ;
351+ }
352+
353+ async notifyRustAnalyzer ( ) : Promise < void > {
354+ // this is a workaround to avoid needing writing the `rust-project.json` into
355+ // a workspace-level VS Code-specific settings folder. We'd like to keep the
356+ // `rust-project.json` entirely in-memory.
357+ await this . client ?. sendNotification ( lc . DidChangeConfigurationNotification . type , {
358+ settings : "" ,
359+ } ) ;
354360 }
355361
356362 private updateCommands ( forceDisable ?: "disable" ) {
0 commit comments