Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-completion/src/context/analysis.rs12
-rw-r--r--crates/ide-completion/src/tests/flyimport.rs12
-rw-r--r--crates/ide/src/inlay_hints.rs92
-rw-r--r--crates/ide/src/inlay_hints/adjustment.rs16
-rw-r--r--crates/ide/src/navigation_target.rs5
-rw-r--r--crates/ide/src/runnables.rs16
-rw-r--r--crates/ide/src/signature_help.rs4
-rw-r--r--crates/ide/src/syntax_highlighting.rs24
8 files changed, 81 insertions, 100 deletions
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index b65c68a240..4f1c00b1ee 100644
--- a/crates/ide-completion/src/context/analysis.rs
+++ b/crates/ide-completion/src/context/analysis.rs
@@ -88,15 +88,9 @@ pub(super) fn expand_and_analyze<'db>(
let original_offset = expansion.original_offset + relative_offset;
let token = expansion.original_file.token_at_offset(original_offset).left_biased()?;
- hir::attach_db(sema.db, || analyze(sema, expansion, original_token, &token)).map(
- |(analysis, expected, qualifier_ctx)| AnalysisResult {
- analysis,
- expected,
- qualifier_ctx,
- token,
- original_offset,
- },
- )
+ analyze(sema, expansion, original_token, &token).map(|(analysis, expected, qualifier_ctx)| {
+ AnalysisResult { analysis, expected, qualifier_ctx, token, original_offset }
+ })
}
fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Option<SyntaxToken> {
diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs
index cf86618de6..c9755525a5 100644
--- a/crates/ide-completion/src/tests/flyimport.rs
+++ b/crates/ide-completion/src/tests/flyimport.rs
@@ -16,11 +16,11 @@ fn check_with_config(
expect: Expect,
) {
let (db, position) = crate::tests::position(ra_fixture);
- let (ctx, analysis) =
- crate::context::CompletionContext::new(&db, position, &config, None).unwrap();
+ hir::attach_db(&db, || {
+ let (ctx, analysis) =
+ crate::context::CompletionContext::new(&db, position, &config, None).unwrap();
- let mut acc = crate::completions::Completions::default();
- hir::attach_db(ctx.db, || {
+ let mut acc = crate::completions::Completions::default();
if let CompletionAnalysis::Name(NameContext { kind: NameKind::IdentPat(pat_ctx), .. }) =
&analysis
{
@@ -42,9 +42,9 @@ fn check_with_config(
_ => (),
}
}
- });
- expect.assert_eq(&super::render_completion_list(Vec::from(acc)));
+ expect.assert_eq(&super::render_completion_list(Vec::from(acc)));
+ });
}
#[test]
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index d05c7811b0..f57f2883b1 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -108,16 +108,14 @@ pub(crate) fn inlay_hints(
}
};
let mut preorder = file.preorder();
- hir::attach_db(sema.db, || {
- while let Some(event) = preorder.next() {
- if matches!((&event, range_limit), (WalkEvent::Enter(node), Some(range)) if range.intersect(node.text_range()).is_none())
- {
- preorder.skip_subtree();
- continue;
- }
- hints(event);
+ while let Some(event) = preorder.next() {
+ if matches!((&event, range_limit), (WalkEvent::Enter(node), Some(range)) if range.intersect(node.text_range()).is_none())
+ {
+ preorder.skip_subtree();
+ continue;
}
- });
+ hints(event);
+ }
if let Some(range_limit) = range_limit {
acc.retain(|hint| range_limit.contains_range(hint.range));
}
@@ -749,46 +747,44 @@ fn label_of_ty(
config: &InlayHintsConfig<'_>,
display_target: DisplayTarget,
) -> Result<(), HirDisplayError> {
- hir::attach_db(sema.db, || {
- let iter_item_type = hint_iterator(sema, famous_defs, ty);
- match iter_item_type {
- Some((iter_trait, item, ty)) => {
- const LABEL_START: &str = "impl ";
- const LABEL_ITERATOR: &str = "Iterator";
- const LABEL_MIDDLE: &str = "<";
- const LABEL_ITEM: &str = "Item";
- const LABEL_MIDDLE2: &str = " = ";
- const LABEL_END: &str = ">";
-
- max_length = max_length.map(|len| {
- len.saturating_sub(
- LABEL_START.len()
- + LABEL_ITERATOR.len()
- + LABEL_MIDDLE.len()
- + LABEL_MIDDLE2.len()
- + LABEL_END.len(),
- )
- });
-
- label_builder.write_str(LABEL_START)?;
- label_builder.start_location_link(ModuleDef::from(iter_trait).into());
- label_builder.write_str(LABEL_ITERATOR)?;
- label_builder.end_location_link();
- label_builder.write_str(LABEL_MIDDLE)?;
- label_builder.start_location_link(ModuleDef::from(item).into());
- label_builder.write_str(LABEL_ITEM)?;
- label_builder.end_location_link();
- label_builder.write_str(LABEL_MIDDLE2)?;
- rec(sema, famous_defs, max_length, &ty, label_builder, config, display_target)?;
- label_builder.write_str(LABEL_END)?;
- Ok(())
- }
- None => ty
- .display_truncated(sema.db, max_length, display_target)
- .with_closure_style(config.closure_style)
- .write_to(label_builder),
+ let iter_item_type = hint_iterator(sema, famous_defs, ty);
+ match iter_item_type {
+ Some((iter_trait, item, ty)) => {
+ const LABEL_START: &str = "impl ";
+ const LABEL_ITERATOR: &str = "Iterator";
+ const LABEL_MIDDLE: &str = "<";
+ const LABEL_ITEM: &str = "Item";
+ const LABEL_MIDDLE2: &str = " = ";
+ const LABEL_END: &str = ">";
+
+ max_length = max_length.map(|len| {
+ len.saturating_sub(
+ LABEL_START.len()
+ + LABEL_ITERATOR.len()
+ + LABEL_MIDDLE.len()
+ + LABEL_MIDDLE2.len()
+ + LABEL_END.len(),
+ )
+ });
+
+ label_builder.write_str(LABEL_START)?;
+ label_builder.start_location_link(ModuleDef::from(iter_trait).into());
+ label_builder.write_str(LABEL_ITERATOR)?;
+ label_builder.end_location_link();
+ label_builder.write_str(LABEL_MIDDLE)?;
+ label_builder.start_location_link(ModuleDef::from(item).into());
+ label_builder.write_str(LABEL_ITEM)?;
+ label_builder.end_location_link();
+ label_builder.write_str(LABEL_MIDDLE2)?;
+ rec(sema, famous_defs, max_length, &ty, label_builder, config, display_target)?;
+ label_builder.write_str(LABEL_END)?;
+ Ok(())
}
- })
+ None => ty
+ .display_truncated(sema.db, max_length, display_target)
+ .with_closure_style(config.closure_style)
+ .write_to(label_builder),
+ }
}
let mut label_builder = InlayHintLabelBuilder {
diff --git a/crates/ide/src/inlay_hints/adjustment.rs b/crates/ide/src/inlay_hints/adjustment.rs
index b2584b6f75..283ec29dc0 100644
--- a/crates/ide/src/inlay_hints/adjustment.rs
+++ b/crates/ide/src/inlay_hints/adjustment.rs
@@ -216,15 +216,13 @@ pub(super) fn hints(
text: if postfix { format!(".{}", text.trim_end()) } else { text.to_owned() },
linked_location: None,
tooltip: Some(config.lazy_tooltip(|| {
- hir::attach_db(sema.db, || {
- InlayTooltip::Markdown(format!(
- "`{}` → `{}`\n\n**{}**\n\n{}",
- source.display(sema.db, display_target),
- target.display(sema.db, display_target),
- coercion,
- detailed_tooltip
- ))
- })
+ InlayTooltip::Markdown(format!(
+ "`{}` → `{}`\n\n**{}**\n\n{}",
+ source.display(sema.db, display_target),
+ target.display(sema.db, display_target),
+ coercion,
+ detailed_tooltip
+ ))
})),
};
if postfix { &mut post } else { &mut pre }.label.append_part(label);
diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs
index 29530ed02b..020f235d3a 100644
--- a/crates/ide/src/navigation_target.rs
+++ b/crates/ide/src/navigation_target.rs
@@ -431,9 +431,8 @@ where
)
.map(|mut res| {
res.docs = self.docs(db).map(Documentation::into_owned);
- res.description = hir::attach_db(db, || {
- Some(self.display(db, self.krate(db).to_display_target(db)).to_string())
- });
+ res.description =
+ Some(self.display(db, self.krate(db).to_display_target(db)).to_string());
res.container_name = self.container_name(db);
res
}),
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index a61be93ea9..c562a9b30b 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -412,13 +412,11 @@ pub(crate) fn runnable_impl(
let ty = def.self_ty(sema.db);
let adt_name = ty.as_adt()?.name(sema.db);
let mut ty_args = ty.generic_parameters(sema.db, display_target).peekable();
- let params = hir::attach_db(sema.db, || {
- if ty_args.peek().is_some() {
- format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)))
- } else {
- String::new()
- }
- });
+ let params = if ty_args.peek().is_some() {
+ format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)))
+ } else {
+ String::new()
+ };
let mut test_id = format!("{}{params}", adt_name.display(sema.db, edition));
test_id.retain(|c| c != ' ');
let test_id = TestId::Path(test_id);
@@ -528,9 +526,7 @@ fn module_def_doctest(sema: &Semantics<'_, RootDatabase>, def: Definition) -> Op
let mut ty_args = ty.generic_parameters(db, display_target).peekable();
format_to!(path, "{}", name.display(db, edition));
if ty_args.peek().is_some() {
- hir::attach_db(db, || {
- format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)));
- });
+ format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)));
}
format_to!(path, "::{}", def_name.display(db, edition));
path.retain(|c| c != ' ');
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index 78dc3f7e86..9ab07565e9 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -268,12 +268,12 @@ fn signature_help_for_call(
// In that case, fall back to render definitions of the respective parameters.
// This is overly conservative: we do not substitute known type vars
// (see FIXME in tests::impl_trait) and falling back on any unknowns.
- hir::attach_db(db, || match (p.ty().contains_unknown(), fn_params.as_deref()) {
+ match (p.ty().contains_unknown(), fn_params.as_deref()) {
(true, Some(fn_params)) => {
format_to!(buf, "{}", fn_params[idx].ty().display(db, display_target))
}
_ => format_to!(buf, "{}", p.ty().display(db, display_target)),
- });
+ }
res.push_call_param(&buf);
}
}
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index fd5ede865f..e7c5f95a25 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -435,17 +435,15 @@ fn traverse(
|node| unsafe_ops.contains(&InFile::new(descended_element.file_id, node));
let element = match descended_element.value {
NodeOrToken::Node(name_like) => {
- let hl = hir::attach_db(sema.db, || {
- highlight::name_like(
- sema,
- krate,
- bindings_shadow_count,
- &is_unsafe_node,
- config.syntactic_name_ref_highlighting,
- name_like,
- edition,
- )
- });
+ let hl = highlight::name_like(
+ sema,
+ krate,
+ bindings_shadow_count,
+ &is_unsafe_node,
+ config.syntactic_name_ref_highlighting,
+ name_like,
+ edition,
+ );
if hl.is_some() && !in_macro {
// skip highlighting the contained token of our name-like node
// as that would potentially overwrite our result
@@ -453,10 +451,10 @@ fn traverse(
}
hl
}
- NodeOrToken::Token(token) => hir::attach_db(sema.db, || {
+ NodeOrToken::Token(token) => {
highlight::token(sema, token, edition, &is_unsafe_node, tt_level > 0)
.zip(Some(None))
- }),
+ }
};
if let Some((mut highlight, binding_hash)) = element {
if is_unlinked && highlight.tag == HlTag::UnresolvedReference {