|
11 | 11 | //! which you can use to paste the command in terminal and add `--release` manually. |
12 | 12 |
|
13 | 13 | use hir::ChangeWithProcMacros; |
14 | | -use ide::{AnalysisHost, CallableSnippets, CompletionConfig, FilePosition, TextSize}; |
| 14 | +use ide::{ |
| 15 | + AnalysisHost, CallableSnippets, CompletionConfig, DiagnosticsConfig, FilePosition, TextSize, |
| 16 | +}; |
15 | 17 | use ide_db::{ |
16 | 18 | imports::insert_use::{ImportGranularity, InsertUseConfig}, |
17 | 19 | SnippetCap, |
@@ -157,7 +159,7 @@ fn integrated_completion_benchmark() { |
157 | 159 | analysis.completions(&config, position, None).unwrap(); |
158 | 160 | } |
159 | 161 |
|
160 | | - crate::tracing::hprof::init("*>5"); |
| 162 | + let _g = crate::tracing::hprof::init("*"); |
161 | 163 |
|
162 | 164 | let completion_offset = { |
163 | 165 | let _it = stdx::timeit("change"); |
@@ -244,6 +246,80 @@ fn integrated_completion_benchmark() { |
244 | 246 | } |
245 | 247 | } |
246 | 248 |
|
| 249 | +#[test] |
| 250 | +fn integrated_diagnostics_benchmark() { |
| 251 | + if std::env::var("RUN_SLOW_BENCHES").is_err() { |
| 252 | + return; |
| 253 | + } |
| 254 | + |
| 255 | + // Load rust-analyzer itself. |
| 256 | + let workspace_to_load = project_root(); |
| 257 | + let file = "./crates/hir/src/lib.rs"; |
| 258 | + |
| 259 | + let cargo_config = CargoConfig { |
| 260 | + sysroot: Some(project_model::RustLibSource::Discover), |
| 261 | + ..CargoConfig::default() |
| 262 | + }; |
| 263 | + let load_cargo_config = LoadCargoConfig { |
| 264 | + load_out_dirs_from_check: true, |
| 265 | + with_proc_macro_server: ProcMacroServerChoice::None, |
| 266 | + prefill_caches: true, |
| 267 | + }; |
| 268 | + |
| 269 | + let (db, vfs, _proc_macro) = { |
| 270 | + let _it = stdx::timeit("workspace loading"); |
| 271 | + load_workspace_at(&workspace_to_load, &cargo_config, &load_cargo_config, &|_| {}).unwrap() |
| 272 | + }; |
| 273 | + let mut host = AnalysisHost::with_database(db); |
| 274 | + |
| 275 | + let file_id = { |
| 276 | + let file = workspace_to_load.join(file); |
| 277 | + let path = VfsPath::from(AbsPathBuf::assert(file)); |
| 278 | + vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {path}")) |
| 279 | + }; |
| 280 | + |
| 281 | + let diagnostics_config = DiagnosticsConfig { |
| 282 | + enabled: false, |
| 283 | + proc_macros_enabled: true, |
| 284 | + proc_attr_macros_enabled: true, |
| 285 | + disable_experimental: true, |
| 286 | + disabled: Default::default(), |
| 287 | + expr_fill_default: Default::default(), |
| 288 | + style_lints: false, |
| 289 | + insert_use: InsertUseConfig { |
| 290 | + granularity: ImportGranularity::Crate, |
| 291 | + enforce_granularity: false, |
| 292 | + prefix_kind: hir::PrefixKind::ByCrate, |
| 293 | + group: true, |
| 294 | + skip_glob_imports: true, |
| 295 | + }, |
| 296 | + prefer_no_std: false, |
| 297 | + prefer_prelude: false, |
| 298 | + }; |
| 299 | + host.analysis() |
| 300 | + .diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id) |
| 301 | + .unwrap(); |
| 302 | + |
| 303 | + let _g = crate::tracing::hprof::init("*>1"); |
| 304 | + |
| 305 | + { |
| 306 | + let _it = stdx::timeit("change"); |
| 307 | + let mut text = host.analysis().file_text(file_id).unwrap().to_string(); |
| 308 | + patch(&mut text, "db.struct_data(self.id)", "();\ndb.struct_data(self.id)"); |
| 309 | + let mut change = ChangeWithProcMacros::new(); |
| 310 | + change.change_file(file_id, Some(Arc::from(text))); |
| 311 | + host.apply_change(change); |
| 312 | + }; |
| 313 | + |
| 314 | + { |
| 315 | + let _p = tracing::span!(tracing::Level::INFO, "diagnostics").entered(); |
| 316 | + let _span = profile::cpu_span(); |
| 317 | + host.analysis() |
| 318 | + .diagnostics(&diagnostics_config, ide::AssistResolveStrategy::None, file_id) |
| 319 | + .unwrap(); |
| 320 | + } |
| 321 | +} |
| 322 | + |
247 | 323 | fn patch(what: &mut String, from: &str, to: &str) -> usize { |
248 | 324 | let idx = what.find(from).unwrap(); |
249 | 325 | *what = what.replacen(from, to, 1); |
|
0 commit comments