File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed
src/tools/rust-analyzer/crates/rust-analyzer/src 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<()> {
208
208
tracing:: info!( "InitializeParams: {}" , initialize_params) ;
209
209
let lsp_types:: InitializeParams {
210
210
root_uri,
211
- capabilities,
211
+ mut capabilities,
212
212
workspace_folders,
213
213
initialization_options,
214
214
client_info,
215
215
..
216
216
} = from_json :: < lsp_types:: InitializeParams > ( "InitializeParams" , & initialize_params) ?;
217
217
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
+
218
229
let root_path = match root_uri
219
230
. and_then ( |it| it. to_file_path ( ) . ok ( ) )
220
231
. map ( patch_path_prefix)
Original file line number Diff line number Diff line change @@ -183,6 +183,10 @@ pub(crate) struct GlobalState {
183
183
/// this queue should run only *after* [`GlobalState::process_changes`] has
184
184
/// been called.
185
185
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 ,
186
190
}
187
191
188
192
/// An immutable snapshot of the world's state at a point in time.
@@ -298,6 +302,7 @@ impl GlobalState {
298
302
discover_workspace_queue : OpQueue :: default ( ) ,
299
303
300
304
deferred_task_queue : task_queue,
305
+ incomplete_crate_graph : false ,
301
306
} ;
302
307
// Apply any required database inputs from the config.
303
308
this. update_configuration ( config) ;
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ impl RequestDispatcher<'_> {
141
141
Result : Serialize ,
142
142
> + ' static ,
143
143
{
144
- if !self . global_state . vfs_done {
144
+ if !self . global_state . vfs_done || self . global_state . incomplete_crate_graph {
145
145
if let Some ( lsp_server:: Request { id, .. } ) =
146
146
self . req . take_if ( |it| it. method == R :: METHOD )
147
147
{
Original file line number Diff line number Diff line change @@ -741,13 +741,16 @@ impl GlobalState {
741
741
} )
742
742
. collect ( ) ;
743
743
744
+ self . incomplete_crate_graph = false ;
744
745
let ( crate_graph, proc_macro_paths) = {
745
746
// Create crate graph from all the workspaces
746
747
let vfs = & self . vfs . read ( ) . 0 ;
747
748
let load = |path : & AbsPath | {
748
749
let vfs_path = vfs:: VfsPath :: from ( path. to_path_buf ( ) ) ;
749
750
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) | {
751
754
( excluded == vfs:: FileExcluded :: No ) . then_some ( file_id)
752
755
} )
753
756
} ;
You can’t perform that action at this time.
0 commit comments