@@ -27,7 +27,7 @@ use project_model::{
27
27
} ;
28
28
use rustc_hash:: { FxHashMap , FxHashSet } ;
29
29
use serde:: { de:: DeserializeOwned , Deserialize } ;
30
- use vfs:: AbsPathBuf ;
30
+ use vfs:: { AbsPath , AbsPathBuf } ;
31
31
32
32
use crate :: {
33
33
caps:: completion_item_edit_resolve,
@@ -535,8 +535,9 @@ impl Default for ConfigData {
535
535
536
536
#[ derive( Debug , Clone ) ]
537
537
pub 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 > ,
540
541
caps : lsp_types:: ClientCapabilities ,
541
542
root_path : AbsPathBuf ,
542
543
data : ConfigData ,
@@ -742,7 +743,7 @@ impl Config {
742
743
caps,
743
744
data : ConfigData :: default ( ) ,
744
745
detached_files : Vec :: new ( ) ,
745
- discovered_projects : None ,
746
+ discovered_projects : Vec :: new ( ) ,
746
747
root_path,
747
748
snippets : Default :: default ( ) ,
748
749
workspace_roots,
@@ -755,7 +756,17 @@ impl Config {
755
756
if discovered. is_empty ( ) {
756
757
tracing:: error!( "failed to find any projects in {:?}" , & self . workspace_roots) ;
757
758
}
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) ;
759
770
}
760
771
761
772
pub fn update ( & mut self , mut json : serde_json:: Value ) -> Result < ( ) , ConfigUpdateError > {
@@ -860,25 +871,19 @@ impl Config {
860
871
pub fn linked_projects ( & self ) -> Vec < LinkedProject > {
861
872
match self . data . linkedProjects . as_slice ( ) {
862
873
[ ] => {
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) ) | {
874
881
!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 ( )
882
887
}
883
888
linked_projects => linked_projects
884
889
. iter ( )
0 commit comments