Skip to content

Commit

Permalink
config: add toggle to reduce progress reporting verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbarsky committed Feb 27, 2024
1 parent 0ac05c0 commit b03093e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
25 changes: 25 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ config_data! {
/// Internal config, path to proc-macro server executable.
procMacro_server: Option<PathBuf> = "null",

/// Configures the level of detail rust-analyzer will report while scanning files.
///
/// If not set, this will default to including parent directories while scanning.
progressReporting_verbosity: Vec<ProgressReportingConfig> = "[]",

/// Exclude imports from find-all-references.
references_excludeImports: bool = "false",

Expand Down Expand Up @@ -1237,6 +1242,10 @@ impl Config {
}
}

pub fn progress_reporting(&self) -> &[ProgressReportingConfig] {
&self.data.progressReporting_verbosity
}

pub fn cargo_autoreload(&self) -> bool {
self.data.cargo_autoreload
}
Expand Down Expand Up @@ -1882,6 +1891,7 @@ mod de_unit_v {
named_unit_variant!(decimal);
named_unit_variant!(hexadecimal);
named_unit_variant!(both);
named_unit_variant!(include_directory);
}

#[derive(Deserialize, Debug, Clone, Copy)]
Expand Down Expand Up @@ -2121,6 +2131,14 @@ pub enum MemoryLayoutHoverRenderKindDef {
Both,
}

#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
#[serde(untagged)]
pub enum ProgressReportingConfig {
#[serde(deserialize_with = "de_unit_v::include_directory")]
IncludeDirectory,
}

#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
#[serde(untagged)]
Expand Down Expand Up @@ -2571,6 +2589,13 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
},
],
},
"Vec<ProgressReportingConfig>" => set! {
"type": "string",
"enum": ["include_directory", ],
"enumDescriptions": [
"`include_directory`: Include the directory of the files being indexed",
]
},
_ => panic!("missing entry for {ty}: {default}"),
}

Expand Down
24 changes: 15 additions & 9 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The main loop of `rust-analyzer` responsible for dispatching LSP
//! requests/replies and notifications back to the client.
use crate::lsp::ext;
use crate::{config::ProgressReportingConfig, lsp::ext};
use std::{
fmt,
time::{Duration, Instant},
Expand Down Expand Up @@ -633,14 +633,20 @@ impl GlobalState {

let mut message = format!("{n_done}/{n_total}");
if let Some(dir) = dir {
message += &format!(
": {}",
match dir.strip_prefix(self.config.root_path()) {
Some(relative_path) => relative_path.as_ref(),
None => dir.as_ref(),
}
.display()
);
if self
.config
.progress_reporting()
.contains(&ProgressReportingConfig::IncludeDirectory)
{
message += &format!(
": {}",
match dir.strip_prefix(self.config.root_path()) {
Some(relative_path) => relative_path.as_ref(),
None => dir.as_ref(),
}
.display()
);
}
}

self.report_progress(
Expand Down
7 changes: 7 additions & 0 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,13 @@ This config takes a map of crate names with the exported proc-macro names to ign
--
Internal config, path to proc-macro server executable.
--
[[rust-analyzer.progressReporting.verbosity]]rust-analyzer.progressReporting.verbosity (default: `[]`)::
+
--
Configures the level of detail rust-analyzer will report while scanning files.

If not set, this will default to including parent directories while scanning.
--
[[rust-analyzer.references.excludeImports]]rust-analyzer.references.excludeImports (default: `false`)::
+
--
Expand Down
11 changes: 11 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,17 @@
"string"
]
},
"rust-analyzer.progressReporting.verbosity": {
"markdownDescription": "Configures the level of detail rust-analyzer will report while scanning files.\n\nIf not set, this will default to including parent directories while scanning.",
"default": [],
"type": "string",
"enum": [
"include_directory"
],
"enumDescriptions": [
"`include_directory`: Include the directory of the files being indexed"
]
},
"rust-analyzer.references.excludeImports": {
"markdownDescription": "Exclude imports from find-all-references.",
"default": false,
Expand Down

0 comments on commit b03093e

Please sign in to comment.