@@ -14,7 +14,7 @@ use pgt_workspace::PartialConfigurationExt;
1414use pgt_workspace:: Workspace ;
1515use pgt_workspace:: configuration:: { LoadedConfiguration , load_configuration} ;
1616use pgt_workspace:: features;
17- use pgt_workspace:: workspace:: UpdateSettingsParams ;
17+ use pgt_workspace:: workspace:: { RegisterProjectFolderParams , UpdateSettingsParams } ;
1818use pgt_workspace:: { DynRef , WorkspaceError } ;
1919use rustc_hash:: FxHashMap ;
2020use serde_json:: Value ;
@@ -31,6 +31,14 @@ use tower_lsp::lsp_types::{MessageType, Registration};
3131use tower_lsp:: lsp_types:: { Unregistration , WorkspaceFolder } ;
3232use tracing:: { error, info} ;
3333
34+ pub ( crate ) struct ClientInformation {
35+ /// The name of the client
36+ pub ( crate ) name : String ,
37+
38+ /// The version of the client
39+ pub ( crate ) version : Option < String > ,
40+ }
41+
3442/// Key, uniquely identifying a LSP session.
3543#[ derive( Clone , Copy , Eq , PartialEq , Hash , Debug ) ]
3644pub ( crate ) struct SessionKey ( pub u64 ) ;
@@ -68,6 +76,7 @@ pub(crate) struct Session {
6876struct InitializeParams {
6977 /// The capabilities provided by the client as part of [`lsp_types::InitializeParams`]
7078 client_capabilities : lsp_types:: ClientCapabilities ,
79+ client_information : Option < ClientInformation > ,
7180 root_uri : Option < Url > ,
7281 #[ allow( unused) ]
7382 workspace_folders : Option < Vec < WorkspaceFolder > > ,
@@ -164,11 +173,13 @@ impl Session {
164173 pub ( crate ) fn initialize (
165174 & self ,
166175 client_capabilities : lsp_types:: ClientCapabilities ,
176+ client_information : Option < ClientInformation > ,
167177 root_uri : Option < Url > ,
168178 workspace_folders : Option < Vec < WorkspaceFolder > > ,
169179 ) {
170180 let result = self . initialize_params . set ( InitializeParams {
171181 client_capabilities,
182+ client_information,
172183 root_uri,
173184 workspace_folders,
174185 } ) ;
@@ -446,6 +457,8 @@ impl Session {
446457 info ! ( "Configuration loaded successfully from disk." ) ;
447458 info ! ( "Update workspace settings." ) ;
448459
460+ let fs = & self . fs ;
461+
449462 if let Some ( ws_configuration) = extra_config {
450463 fs_configuration. merge_with ( ws_configuration) ;
451464 }
@@ -455,6 +468,31 @@ impl Session {
455468
456469 match result {
457470 Ok ( ( vcs_base_path, gitignore_matches) ) => {
471+ let register_result =
472+ if let ConfigurationPathHint :: FromWorkspace ( path) = & base_path {
473+ // We don't need the key
474+ self . workspace
475+ . register_project_folder ( RegisterProjectFolderParams {
476+ path : Some ( path. clone ( ) ) ,
477+ // This is naive, but we don't know if the user has a file already open or not, so we register every project as the current one.
478+ // The correct one is actually set when the LSP calls `textDocument/didOpen`
479+ set_as_current_workspace : true ,
480+ } )
481+ . err ( )
482+ } else {
483+ self . workspace
484+ . register_project_folder ( RegisterProjectFolderParams {
485+ path : fs. working_directory ( ) ,
486+ set_as_current_workspace : true ,
487+ } )
488+ . err ( )
489+ } ;
490+ if let Some ( error) = register_result {
491+ error ! ( "Failed to register the project folder: {}" , error) ;
492+ self . client . log_message ( MessageType :: ERROR , & error) . await ;
493+ return ConfigurationStatus :: Error ;
494+ }
495+
458496 let result = self . workspace . update_settings ( UpdateSettingsParams {
459497 workspace_directory : self . fs . working_directory ( ) ,
460498 configuration : fs_configuration,
0 commit comments