Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Add Configuration for Progress Reporting Verbosity #16700

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Copy link
Member

@lnicola lnicola Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit confusing (I'd expect [] to mean that nothing is reported, with null being the default).

But I also don't see what makes it behave like the docs say (that is, report the directories when this is set to []).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah crud, I think I got the options here flipped. Lemme fix that.

--
[[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