Skip to content

Commit f653ff4

Browse files
committed
Add more workaround hacks for incorrect startup diagnostics
1 parent 56e82d2 commit f653ff4

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

crates/rust-analyzer/src/handlers/dispatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
{

crates/rust-analyzer/src/reload.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,16 @@ impl GlobalState {
739739
})
740740
.collect();
741741

742+
self.incomplete_crate_graph = false;
742743
let (crate_graph, proc_macro_paths) = {
743744
// Create crate graph from all the workspaces
744745
let vfs = &self.vfs.read().0;
745746
let load = |path: &AbsPath| {
746747
let vfs_path = vfs::VfsPath::from(path.to_path_buf());
747748
self.crate_graph_file_dependencies.insert(vfs_path.clone());
748-
vfs.file_id(&vfs_path).and_then(|(file_id, excluded)| {
749+
let file_id = vfs.file_id(&vfs_path);
750+
self.incomplete_crate_graph |= file_id.is_none();
751+
file_id.and_then(|(file_id, excluded)| {
749752
(excluded == vfs::FileExcluded::No).then_some(file_id)
750753
})
751754
};

0 commit comments

Comments
 (0)