From 693b110e3d1c620d2aaca4f43b59b4e9bc4dacf2 Mon Sep 17 00:00:00 2001 From: roife Date: Sat, 21 Dec 2024 07:00:49 +0800 Subject: [PATCH 1/2] fix: remove always! check for file_id in runnables --- crates/ide/src/runnables.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 3bbbd36c1b..d385e453e2 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -16,7 +16,7 @@ use ide_db::{ }; use itertools::Itertools; use span::{Edition, TextSize}; -use stdx::{always, format_to}; +use stdx::format_to; use syntax::{ ast::{self, AstNode}, SmolStr, SyntaxNode, ToSmolStr, @@ -130,14 +130,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec { // In case an expansion creates multiple runnables we want to name them to avoid emitting a bunch of equally named runnables. let mut in_macro_expansion = FxHashMap::>::default(); let mut add_opt = |runnable: Option, def| { - if let Some(runnable) = runnable.filter(|runnable| { - always!( - runnable.nav.file_id == file_id, - "tried adding a runnable pointing to a different file: {:?} for {:?}", - runnable.kind, - file_id - ) - }) { + if let Some(runnable) = runnable.filter(|runnable| runnable.nav.file_id == file_id) { if let Some(def) = def { let file_id = match def { Definition::Module(it) => { @@ -161,13 +154,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec { Definition::SelfType(impl_) => runnable_impl(&sema, &impl_), _ => None, }; - add_opt( - runnable - .or_else(|| module_def_doctest(sema.db, def)) - // #[macro_export] mbe macros are declared in the root, while their definition may reside in a different module - .filter(|it| it.nav.file_id == file_id), - Some(def), - ); + add_opt(runnable.or_else(|| module_def_doctest(sema.db, def)), Some(def)); if let Definition::SelfType(impl_) = def { impl_.items(db).into_iter().for_each(|assoc| { let runnable = match assoc { From 59e3d6684b8b37edad9a369960f2d9199e690335 Mon Sep 17 00:00:00 2001 From: roife Date: Sat, 21 Dec 2024 07:03:45 +0800 Subject: [PATCH 2/2] fix: only show debug lens with a valid root --- crates/rust-analyzer/src/lsp/to_proto.rs | 34 +++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 38bb30c978..05e93b4e6a 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -1584,22 +1584,26 @@ pub(crate) fn code_lens( }; let lens_config = snap.config.lens(); - if lens_config.run && client_commands_config.run_single && has_root { - let command = command::run_single(&r, &title); - acc.push(lsp_types::CodeLens { - range: annotation_range, - command: Some(command), - data: None, - }) - } - if lens_config.debug && can_debug && client_commands_config.debug_single { - let command = command::debug_single(&r); - acc.push(lsp_types::CodeLens { - range: annotation_range, - command: Some(command), - data: None, - }) + + if has_root { + if lens_config.run && client_commands_config.run_single { + let command = command::run_single(&r, &title); + acc.push(lsp_types::CodeLens { + range: annotation_range, + command: Some(command), + data: None, + }) + } + if lens_config.debug && can_debug && client_commands_config.debug_single { + let command = command::debug_single(&r); + acc.push(lsp_types::CodeLens { + range: annotation_range, + command: Some(command), + data: None, + }) + } } + if lens_config.interpret { let command = command::interpret_single(&r); acc.push(lsp_types::CodeLens {