Skip to content

Commit 6a2f08a

Browse files
committed
Don't re-attach to salsa database in some places
1 parent 3f6d9e2 commit 6a2f08a

File tree

5 files changed

+112
-81
lines changed

5 files changed

+112
-81
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,25 @@ impl Analysis {
443443
})
444444
}
445445

446+
pub fn inlay_hints_preattached(
447+
db: &RootDatabase,
448+
file_id: FileId,
449+
range: Option<TextRange>,
450+
config: &InlayHintsConfig,
451+
) -> Vec<InlayHint> {
452+
inlay_hints::inlay_hints(db, file_id, range, config)
453+
}
454+
446455
/// Returns a list of the places in the file where type hints can be displayed.
447456
pub fn inlay_hints(
448457
&self,
449458
config: &InlayHintsConfig,
450459
file_id: FileId,
451460
range: Option<TextRange>,
452461
) -> Cancellable<Vec<InlayHint>> {
453-
self.with_db(|db| inlay_hints::inlay_hints(db, file_id, range, config))
462+
self.with_db(|db| Self::inlay_hints_preattached(db, file_id, range, config))
454463
}
464+
455465
pub fn inlay_hints_resolve(
456466
&self,
457467
config: &InlayHintsConfig,
@@ -851,16 +861,28 @@ impl Analysis {
851861
})
852862
}
853863

864+
pub fn annotations_preattached(
865+
db: &RootDatabase,
866+
config: &AnnotationConfig,
867+
file_id: FileId,
868+
) -> Vec<Annotation> {
869+
annotations::annotations(db, config, file_id)
870+
}
871+
854872
pub fn annotations(
855873
&self,
856874
config: &AnnotationConfig,
857875
file_id: FileId,
858876
) -> Cancellable<Vec<Annotation>> {
859-
self.with_db(|db| annotations::annotations(db, config, file_id))
877+
self.with_db(|db| Self::annotations_preattached(db, config, file_id))
878+
}
879+
880+
pub fn resolve_annotation_preattached(db: &RootDatabase, annotation: Annotation) -> Annotation {
881+
annotations::resolve_annotation(db, annotation)
860882
}
861883

862884
pub fn resolve_annotation(&self, annotation: Annotation) -> Cancellable<Annotation> {
863-
self.with_db(|db| annotations::resolve_annotation(db, annotation))
885+
self.with_db(|db| Self::resolve_annotation_preattached(db, annotation))
864886
}
865887

866888
pub fn move_item(

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ hir-def.workspace = true
5959
hir-ty.workspace = true
6060
hir.workspace = true
6161
ide-db.workspace = true
62+
ide-diagnostics.workspace = true
6263
intern.workspace = true
6364
# This should only be used in CLI
6465
ide-ssr.workspace = true

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 85 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ide_db::{
2828
EditionedFileId, LineIndexDatabase, SnippetCap,
2929
base_db::{
3030
SourceDatabase,
31-
salsa::{self, Database},
31+
salsa::{self, Cancelled, Database},
3232
},
3333
};
3434
use itertools::Itertools;
@@ -1128,36 +1128,44 @@ impl flags::AnalysisStats {
11281128
file_ids.dedup();
11291129
let mut sw = self.stop_watch();
11301130

1131+
HirDatabase::zalsa_register_downcaster(db);
1132+
11311133
let mut bar = create_bar();
11321134
for &file_id in &file_ids {
11331135
let msg = format!("diagnostics: {}", vfs.file_path(file_id.file_id(db)));
11341136
bar.set_message(move || msg.clone());
1135-
_ = analysis.full_diagnostics(
1136-
&DiagnosticsConfig {
1137-
enabled: true,
1138-
proc_macros_enabled: true,
1139-
proc_attr_macros_enabled: true,
1140-
disable_experimental: false,
1141-
disabled: Default::default(),
1142-
expr_fill_default: Default::default(),
1143-
snippet_cap: SnippetCap::new(true),
1144-
insert_use: ide_db::imports::insert_use::InsertUseConfig {
1145-
granularity: ide_db::imports::insert_use::ImportGranularity::Crate,
1146-
enforce_granularity: true,
1147-
prefix_kind: hir::PrefixKind::ByCrate,
1148-
group: true,
1149-
skip_glob_imports: true,
1150-
},
1151-
prefer_no_std: false,
1152-
prefer_prelude: true,
1153-
prefer_absolute: false,
1154-
style_lints: false,
1155-
term_search_fuel: 400,
1156-
term_search_borrowck: true,
1137+
1138+
let config = DiagnosticsConfig {
1139+
enabled: true,
1140+
proc_macros_enabled: true,
1141+
proc_attr_macros_enabled: true,
1142+
disable_experimental: false,
1143+
disabled: Default::default(),
1144+
expr_fill_default: Default::default(),
1145+
snippet_cap: SnippetCap::new(true),
1146+
insert_use: ide_db::imports::insert_use::InsertUseConfig {
1147+
granularity: ide_db::imports::insert_use::ImportGranularity::Crate,
1148+
enforce_granularity: true,
1149+
prefix_kind: hir::PrefixKind::ByCrate,
1150+
group: true,
1151+
skip_glob_imports: true,
11571152
},
1158-
ide::AssistResolveStrategy::All,
1159-
analysis.editioned_file_id_to_vfs(file_id),
1160-
);
1153+
prefer_no_std: false,
1154+
prefer_prelude: true,
1155+
prefer_absolute: false,
1156+
style_lints: false,
1157+
term_search_fuel: 400,
1158+
term_search_borrowck: true,
1159+
};
1160+
let id_vfs = analysis.editioned_file_id_to_vfs(file_id);
1161+
_ = Cancelled::catch(|| {
1162+
ide_diagnostics::full_diagnostics(
1163+
db,
1164+
&config,
1165+
&ide::AssistResolveStrategy::All,
1166+
id_vfs,
1167+
)
1168+
});
11611169
bar.inc(1);
11621170
}
11631171
bar.finish_and_clear();
@@ -1166,41 +1174,40 @@ impl flags::AnalysisStats {
11661174
for &file_id in &file_ids {
11671175
let msg = format!("inlay hints: {}", vfs.file_path(file_id.file_id(db)));
11681176
bar.set_message(move || msg.clone());
1169-
_ = analysis.inlay_hints(
1170-
&InlayHintsConfig {
1171-
render_colons: false,
1177+
let config = InlayHintsConfig {
1178+
render_colons: false,
1179+
type_hints: true,
1180+
sized_bound: false,
1181+
discriminant_hints: ide::DiscriminantHints::Always,
1182+
parameter_hints: true,
1183+
generic_parameter_hints: ide::GenericParameterHints {
11721184
type_hints: true,
1173-
sized_bound: false,
1174-
discriminant_hints: ide::DiscriminantHints::Always,
1175-
parameter_hints: true,
1176-
generic_parameter_hints: ide::GenericParameterHints {
1177-
type_hints: true,
1178-
lifetime_hints: true,
1179-
const_hints: true,
1180-
},
1181-
chaining_hints: true,
1182-
adjustment_hints: ide::AdjustmentHints::Always,
1183-
adjustment_hints_disable_reborrows: true,
1184-
adjustment_hints_mode: ide::AdjustmentHintsMode::Postfix,
1185-
adjustment_hints_hide_outside_unsafe: false,
1186-
closure_return_type_hints: ide::ClosureReturnTypeHints::Always,
1187-
closure_capture_hints: true,
1188-
binding_mode_hints: true,
1189-
implicit_drop_hints: true,
1190-
lifetime_elision_hints: ide::LifetimeElisionHints::Always,
1191-
param_names_for_lifetime_elision_hints: true,
1192-
hide_named_constructor_hints: false,
1193-
hide_closure_initialization_hints: false,
1194-
hide_closure_parameter_hints: false,
1195-
closure_style: hir::ClosureStyle::ImplFn,
1196-
max_length: Some(25),
1197-
closing_brace_hints_min_lines: Some(20),
1198-
fields_to_resolve: InlayFieldsToResolve::empty(),
1199-
range_exclusive_hints: true,
1185+
lifetime_hints: true,
1186+
const_hints: true,
12001187
},
1201-
analysis.editioned_file_id_to_vfs(file_id),
1202-
None,
1203-
);
1188+
chaining_hints: true,
1189+
adjustment_hints: ide::AdjustmentHints::Always,
1190+
adjustment_hints_disable_reborrows: true,
1191+
adjustment_hints_mode: ide::AdjustmentHintsMode::Postfix,
1192+
adjustment_hints_hide_outside_unsafe: false,
1193+
closure_return_type_hints: ide::ClosureReturnTypeHints::Always,
1194+
closure_capture_hints: true,
1195+
binding_mode_hints: true,
1196+
implicit_drop_hints: true,
1197+
lifetime_elision_hints: ide::LifetimeElisionHints::Always,
1198+
param_names_for_lifetime_elision_hints: true,
1199+
hide_named_constructor_hints: false,
1200+
hide_closure_initialization_hints: false,
1201+
hide_closure_parameter_hints: false,
1202+
closure_style: hir::ClosureStyle::ImplFn,
1203+
max_length: Some(25),
1204+
closing_brace_hints_min_lines: Some(20),
1205+
fields_to_resolve: InlayFieldsToResolve::empty(),
1206+
range_exclusive_hints: true,
1207+
};
1208+
let file_id = analysis.editioned_file_id_to_vfs(file_id);
1209+
1210+
_ = Cancelled::catch(|| Analysis::inlay_hints_preattached(db, file_id, None, &config));
12041211
bar.inc(1);
12051212
}
12061213
bar.finish_and_clear();
@@ -1209,24 +1216,25 @@ impl flags::AnalysisStats {
12091216
for &file_id in &file_ids {
12101217
let msg = format!("annotations: {}", vfs.file_path(file_id.file_id(db)));
12111218
bar.set_message(move || msg.clone());
1212-
analysis
1213-
.annotations(
1214-
&AnnotationConfig {
1215-
binary_target: true,
1216-
annotate_runnables: true,
1217-
annotate_impls: true,
1218-
annotate_references: false,
1219-
annotate_method_references: false,
1220-
annotate_enum_variant_references: false,
1221-
location: ide::AnnotationLocation::AboveName,
1222-
},
1223-
analysis.editioned_file_id_to_vfs(file_id),
1224-
)
1225-
.unwrap()
1226-
.into_iter()
1227-
.for_each(|annotation| {
1228-
_ = analysis.resolve_annotation(annotation);
1229-
});
1219+
let config = AnnotationConfig {
1220+
binary_target: true,
1221+
annotate_runnables: true,
1222+
annotate_impls: true,
1223+
annotate_references: false,
1224+
annotate_method_references: false,
1225+
annotate_enum_variant_references: false,
1226+
location: ide::AnnotationLocation::AboveName,
1227+
};
1228+
1229+
Analysis::annotations_preattached(
1230+
db,
1231+
&config,
1232+
analysis.editioned_file_id_to_vfs(file_id),
1233+
)
1234+
.into_iter()
1235+
.for_each(|annotation| {
1236+
_ = Analysis::resolve_annotation_preattached(db, annotation);
1237+
});
12301238
bar.inc(1);
12311239
}
12321240
bar.finish_and_clear();

crates/stdx/src/thread.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl<T> Drop for JoinHandle<T> {
101101
}
102102
}
103103

104-
#[expect(clippy::min_ident_chars, reason = "trait impl")]
105104
impl<T> fmt::Debug for JoinHandle<T> {
106105
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107106
f.pad("JoinHandle { .. }")

0 commit comments

Comments
 (0)