Merge pull request #18727 from roife/fix-issue-18704

fix: remove `always!` check for file_id in `runnables`
This commit is contained in:
Lukas Wirth 2024-12-21 07:10:08 +00:00 committed by GitHub
commit fda8b48bd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 31 deletions

View file

@ -16,7 +16,7 @@ use ide_db::{
}; };
use itertools::Itertools; use itertools::Itertools;
use span::{Edition, TextSize}; use span::{Edition, TextSize};
use stdx::{always, format_to}; use stdx::format_to;
use syntax::{ use syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
SmolStr, SyntaxNode, ToSmolStr, SmolStr, SyntaxNode, ToSmolStr,
@ -130,14 +130,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
// In case an expansion creates multiple runnables we want to name them to avoid emitting a bunch of equally named runnables. // 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::<hir::HirFileId, Vec<Runnable>>::default(); let mut in_macro_expansion = FxHashMap::<hir::HirFileId, Vec<Runnable>>::default();
let mut add_opt = |runnable: Option<Runnable>, def| { let mut add_opt = |runnable: Option<Runnable>, def| {
if let Some(runnable) = runnable.filter(|runnable| { if let Some(runnable) = runnable.filter(|runnable| runnable.nav.file_id == file_id) {
always!(
runnable.nav.file_id == file_id,
"tried adding a runnable pointing to a different file: {:?} for {:?}",
runnable.kind,
file_id
)
}) {
if let Some(def) = def { if let Some(def) = def {
let file_id = match def { let file_id = match def {
Definition::Module(it) => { Definition::Module(it) => {
@ -161,13 +154,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
Definition::SelfType(impl_) => runnable_impl(&sema, &impl_), Definition::SelfType(impl_) => runnable_impl(&sema, &impl_),
_ => None, _ => None,
}; };
add_opt( add_opt(runnable.or_else(|| module_def_doctest(sema.db, def)), Some(def));
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),
);
if let Definition::SelfType(impl_) = def { if let Definition::SelfType(impl_) = def {
impl_.items(db).into_iter().for_each(|assoc| { impl_.items(db).into_iter().for_each(|assoc| {
let runnable = match assoc { let runnable = match assoc {

View file

@ -1584,22 +1584,26 @@ pub(crate) fn code_lens(
}; };
let lens_config = snap.config.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); if has_root {
acc.push(lsp_types::CodeLens { if lens_config.run && client_commands_config.run_single {
range: annotation_range, let command = command::run_single(&r, &title);
command: Some(command), acc.push(lsp_types::CodeLens {
data: None, 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 { if lens_config.debug && can_debug && client_commands_config.debug_single {
range: annotation_range, let command = command::debug_single(&r);
command: Some(command), acc.push(lsp_types::CodeLens {
data: None, range: annotation_range,
}) command: Some(command),
data: None,
})
}
} }
if lens_config.interpret { if lens_config.interpret {
let command = command::interpret_single(&r); let command = command::interpret_single(&r);
acc.push(lsp_types::CodeLens { acc.push(lsp_types::CodeLens {