@@ -27,7 +27,7 @@ use project_model::{
2727} ;
2828use rustc_hash:: { FxHashMap , FxHashSet } ;
2929use serde:: { de:: DeserializeOwned , Deserialize } ;
30- use vfs:: AbsPathBuf ;
30+ use vfs:: { AbsPath , AbsPathBuf } ;
3131
3232use crate :: {
3333 caps:: completion_item_edit_resolve,
@@ -535,8 +535,9 @@ impl Default for ConfigData {
535535
536536#[ derive( Debug , Clone ) ]
537537pub struct Config {
538- pub discovered_projects : Option < Vec < ProjectManifest > > ,
539- pub workspace_roots : Vec < AbsPathBuf > ,
538+ discovered_projects : Vec < ProjectManifest > ,
539+ /// The workspace roots as registered by the LSP client
540+ workspace_roots : Vec < AbsPathBuf > ,
540541 caps : lsp_types:: ClientCapabilities ,
541542 root_path : AbsPathBuf ,
542543 data : ConfigData ,
@@ -742,7 +743,7 @@ impl Config {
742743 caps,
743744 data : ConfigData :: default ( ) ,
744745 detached_files : Vec :: new ( ) ,
745- discovered_projects : None ,
746+ discovered_projects : Vec :: new ( ) ,
746747 root_path,
747748 snippets : Default :: default ( ) ,
748749 workspace_roots,
@@ -755,7 +756,17 @@ impl Config {
755756 if discovered. is_empty ( ) {
756757 tracing:: error!( "failed to find any projects in {:?}" , & self . workspace_roots) ;
757758 }
758- self . discovered_projects = Some ( discovered) ;
759+ self . discovered_projects = discovered;
760+ }
761+
762+ pub fn remove_workspace ( & mut self , path : & AbsPath ) {
763+ if let Some ( position) = self . workspace_roots . iter ( ) . position ( |it| it == path) {
764+ self . workspace_roots . remove ( position) ;
765+ }
766+ }
767+
768+ pub fn add_workspaces ( & mut self , paths : impl Iterator < Item = AbsPathBuf > ) {
769+ self . workspace_roots . extend ( paths) ;
759770 }
760771
761772 pub fn update ( & mut self , mut json : serde_json:: Value ) -> Result < ( ) , ConfigUpdateError > {
@@ -860,25 +871,19 @@ impl Config {
860871 pub fn linked_projects ( & self ) -> Vec < LinkedProject > {
861872 match self . data . linkedProjects . as_slice ( ) {
862873 [ ] => {
863- match self . discovered_projects . as_ref ( ) {
864- Some ( discovered_projects) => {
865- let exclude_dirs: Vec < _ > = self
866- . data
867- . files_excludeDirs
868- . iter ( )
869- . map ( |p| self . root_path . join ( p) )
870- . collect ( ) ;
871- discovered_projects
872- . iter ( )
873- . filter ( |( ProjectManifest :: ProjectJson ( path) | ProjectManifest :: CargoToml ( path) ) | {
874+ let exclude_dirs: Vec < _ > =
875+ self . data . files_excludeDirs . iter ( ) . map ( |p| self . root_path . join ( p) ) . collect ( ) ;
876+ self . discovered_projects
877+ . iter ( )
878+ . filter (
879+ |( ProjectManifest :: ProjectJson ( path)
880+ | ProjectManifest :: CargoToml ( path) ) | {
874881 !exclude_dirs. iter ( ) . any ( |p| path. starts_with ( p) )
875- } )
876- . cloned ( )
877- . map ( LinkedProject :: from)
878- . collect ( )
879- }
880- None => Vec :: new ( ) ,
881- }
882+ } ,
883+ )
884+ . cloned ( )
885+ . map ( LinkedProject :: from)
886+ . collect ( )
882887 }
883888 linked_projects => linked_projects
884889 . iter ( )
0 commit comments