1
1
import * as vscode from "vscode" ;
2
- import type * as lc from "vscode-languageclient/node" ;
2
+ import * as lc from "vscode-languageclient/node" ;
3
3
import * as ra from "./lsp_ext" ;
4
4
5
5
import { Config , prepareVSCodeConfig } from "./config" ;
@@ -22,6 +22,7 @@ import {
22
22
import { execRevealDependency } from "./commands" ;
23
23
import { PersistentState } from "./persistent_state" ;
24
24
import { bootstrap } from "./bootstrap" ;
25
+ import type { RustAnalyzerExtensionApi } from "./main" ;
25
26
26
27
// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
27
28
// only those are in use. We use "Empty" to represent these scenarios
@@ -64,7 +65,7 @@ export type CtxInit = Ctx & {
64
65
readonly client : lc . LanguageClient ;
65
66
} ;
66
67
67
- export class Ctx {
68
+ export class Ctx implements RustAnalyzerExtensionApi {
68
69
readonly statusBar : vscode . StatusBarItem ;
69
70
config : Config ;
70
71
readonly workspace : Workspace ;
@@ -189,8 +190,11 @@ export class Ctx {
189
190
if ( this . config . discoverProjectRunner ) {
190
191
const command = `${ this . config . discoverProjectRunner } .discoverWorkspaceCommand` ;
191
192
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 ) ;
194
198
}
195
199
196
200
if ( this . workspace . kind === "Detached Files" ) {
@@ -342,15 +346,17 @@ export class Ctx {
342
346
return this . _serverPath ;
343
347
}
344
348
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
+ } ) ;
354
360
}
355
361
356
362
private updateCommands ( forceDisable ?: "disable" ) {
0 commit comments