File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -208,13 +208,24 @@ fn run_server() -> anyhow::Result<()> {
208208 tracing:: info!( "InitializeParams: {}" , initialize_params) ;
209209 let lsp_types:: InitializeParams {
210210 root_uri,
211- capabilities,
211+ mut capabilities,
212212 workspace_folders,
213213 initialization_options,
214214 client_info,
215215 ..
216216 } = from_json :: < lsp_types:: InitializeParams > ( "InitializeParams" , & initialize_params) ?;
217217
218+ // lsp-types has a typo in the `/capabilities/workspace/diagnostics` field, its typoed as `diagnostic`
219+ if let Some ( val) = initialize_params. pointer ( "/capabilities/workspace/diagnostics" )
220+ && let Ok ( diag_caps) = from_json :: < lsp_types:: DiagnosticWorkspaceClientCapabilities > (
221+ "DiagnosticWorkspaceClientCapabilities" ,
222+ val,
223+ )
224+ {
225+ tracing:: info!( "Patching lsp-types workspace diagnostics capabilities: {diag_caps:#?}" ) ;
226+ capabilities. workspace . get_or_insert_default ( ) . diagnostic . get_or_insert ( diag_caps) ;
227+ }
228+
218229 let root_path = match root_uri
219230 . and_then ( |it| it. to_file_path ( ) . ok ( ) )
220231 . map ( patch_path_prefix)
Original file line number Diff line number Diff line change @@ -183,6 +183,10 @@ pub(crate) struct GlobalState {
183183 /// this queue should run only *after* [`GlobalState::process_changes`] has
184184 /// been called.
185185 pub ( crate ) deferred_task_queue : TaskQueue ,
186+ /// HACK: Workaround for https://github.com/rust-lang/rust-analyzer/issues/19709
187+ /// This is marked true if we failed to load a crate root file at crate graph creation,
188+ /// which will usually end up causing a bunch of incorrect diagnostics on startup.
189+ pub ( crate ) incomplete_crate_graph : bool ,
186190}
187191
188192/// An immutable snapshot of the world's state at a point in time.
@@ -298,6 +302,7 @@ impl GlobalState {
298302 discover_workspace_queue : OpQueue :: default ( ) ,
299303
300304 deferred_task_queue : task_queue,
305+ incomplete_crate_graph : false ,
301306 } ;
302307 // Apply any required database inputs from the config.
303308 this. update_configuration ( config) ;
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ impl RequestDispatcher<'_> {
141141 Result : Serialize ,
142142 > + ' static ,
143143 {
144- if !self . global_state . vfs_done {
144+ if !self . global_state . vfs_done || self . global_state . incomplete_crate_graph {
145145 if let Some ( lsp_server:: Request { id, .. } ) =
146146 self . req . take_if ( |it| it. method == R :: METHOD )
147147 {
Original file line number Diff line number Diff line change @@ -741,13 +741,16 @@ impl GlobalState {
741741 } )
742742 . collect ( ) ;
743743
744+ self . incomplete_crate_graph = false ;
744745 let ( crate_graph, proc_macro_paths) = {
745746 // Create crate graph from all the workspaces
746747 let vfs = & self . vfs . read ( ) . 0 ;
747748 let load = |path : & AbsPath | {
748749 let vfs_path = vfs:: VfsPath :: from ( path. to_path_buf ( ) ) ;
749750 self . crate_graph_file_dependencies . insert ( vfs_path. clone ( ) ) ;
750- vfs. file_id ( & vfs_path) . and_then ( |( file_id, excluded) | {
751+ let file_id = vfs. file_id ( & vfs_path) ;
752+ self . incomplete_crate_graph |= file_id. is_none ( ) ;
753+ file_id. and_then ( |( file_id, excluded) | {
751754 ( excluded == vfs:: FileExcluded :: No ) . then_some ( file_id)
752755 } )
753756 } ;
You can’t perform that action at this time.
0 commit comments