mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Auto merge of #16639 - alibektas:13529/config_restruct, r=Veykril
internal : redesign rust-analyzer::config This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( #13529 ) issue. This means, that 1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only. 2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until #13529 got merged. Once again many thanks to `@cormacrelf` for doing all the serde work.
This commit is contained in:
commit
1179c3ee83
15 changed files with 1404 additions and 945 deletions
|
@ -39,11 +39,13 @@ tracing.workspace = true
|
|||
tracing-subscriber.workspace = true
|
||||
tracing-tree.workspace = true
|
||||
triomphe.workspace = true
|
||||
toml = "0.8.8"
|
||||
nohash-hasher.workspace = true
|
||||
always-assert = "0.2.0"
|
||||
walkdir = "2.3.2"
|
||||
semver.workspace = true
|
||||
memchr = "2.7.1"
|
||||
indexmap = { workspace = true, features = ["serde"] }
|
||||
|
||||
cfg.workspace = true
|
||||
flycheck.workspace = true
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -154,10 +154,12 @@ pub(crate) fn fetch_native_diagnostics(
|
|||
.copied()
|
||||
.filter_map(|file_id| {
|
||||
let line_index = snapshot.file_line_index(file_id).ok()?;
|
||||
let source_root = snapshot.analysis.source_root(file_id).ok()?;
|
||||
|
||||
let diagnostics = snapshot
|
||||
.analysis
|
||||
.diagnostics(
|
||||
&snapshot.config.diagnostics(),
|
||||
&snapshot.config.diagnostics(Some(source_root)),
|
||||
ide::AssistResolveStrategy::None,
|
||||
file_id,
|
||||
)
|
||||
|
|
|
@ -189,7 +189,7 @@ impl GlobalState {
|
|||
};
|
||||
|
||||
let mut analysis_host = AnalysisHost::new(config.lru_parse_query_capacity());
|
||||
if let Some(capacities) = config.lru_query_capacities() {
|
||||
if let Some(capacities) = config.lru_query_capacities_config() {
|
||||
analysis_host.update_lru_capacities(capacities);
|
||||
}
|
||||
let (flycheck_sender, flycheck_receiver) = unbounded();
|
||||
|
|
|
@ -369,8 +369,9 @@ pub(crate) fn handle_join_lines(
|
|||
) -> anyhow::Result<Vec<lsp_types::TextEdit>> {
|
||||
let _p = tracing::span!(tracing::Level::INFO, "handle_join_lines").entered();
|
||||
|
||||
let config = snap.config.join_lines();
|
||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
let config = snap.config.join_lines(Some(source_root));
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
|
||||
let mut res = TextEdit::default();
|
||||
|
@ -937,7 +938,8 @@ pub(crate) fn handle_completion(
|
|||
let completion_trigger_character =
|
||||
params.context.and_then(|ctx| ctx.trigger_character).and_then(|s| s.chars().next());
|
||||
|
||||
let completion_config = &snap.config.completion();
|
||||
let source_root = snap.analysis.source_root(position.file_id)?;
|
||||
let completion_config = &snap.config.completion(Some(source_root));
|
||||
let items = match snap.analysis.completions(
|
||||
completion_config,
|
||||
position,
|
||||
|
@ -978,11 +980,12 @@ pub(crate) fn handle_completion_resolve(
|
|||
let file_id = from_proto::file_id(&snap, &resolve_data.position.text_document.uri)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let offset = from_proto::offset(&line_index, resolve_data.position.position)?;
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let additional_edits = snap
|
||||
.analysis
|
||||
.resolve_completion_edits(
|
||||
&snap.config.completion(),
|
||||
&snap.config.completion(Some(source_root)),
|
||||
FilePosition { file_id, offset },
|
||||
resolve_data
|
||||
.imports
|
||||
|
@ -1052,16 +1055,17 @@ pub(crate) fn handle_hover(
|
|||
PositionOrRange::Position(position) => Range::new(position, position),
|
||||
PositionOrRange::Range(range) => range,
|
||||
};
|
||||
|
||||
let file_range = from_proto::file_range(&snap, ¶ms.text_document, range)?;
|
||||
let info = match snap.analysis.hover(&snap.config.hover(), file_range)? {
|
||||
|
||||
let hover = snap.config.hover();
|
||||
let info = match snap.analysis.hover(&hover, file_range)? {
|
||||
None => return Ok(None),
|
||||
Some(info) => info,
|
||||
};
|
||||
|
||||
let line_index = snap.file_line_index(file_range.file_id)?;
|
||||
let range = to_proto::range(&line_index, info.range);
|
||||
let markup_kind = snap.config.hover().format;
|
||||
let markup_kind = hover.format;
|
||||
let hover = lsp_ext::Hover {
|
||||
hover: lsp_types::Hover {
|
||||
contents: HoverContents::Markup(to_proto::markup_content(
|
||||
|
@ -1205,11 +1209,12 @@ pub(crate) fn handle_code_action(
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
let line_index =
|
||||
snap.file_line_index(from_proto::file_id(&snap, ¶ms.text_document.uri)?)?;
|
||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let frange = from_proto::file_range(&snap, ¶ms.text_document, params.range)?;
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let mut assists_config = snap.config.assist();
|
||||
let mut assists_config = snap.config.assist(Some(source_root));
|
||||
assists_config.allowed = params
|
||||
.context
|
||||
.only
|
||||
|
@ -1226,7 +1231,7 @@ pub(crate) fn handle_code_action(
|
|||
};
|
||||
let assists = snap.analysis.assists_with_fixes(
|
||||
&assists_config,
|
||||
&snap.config.diagnostics(),
|
||||
&snap.config.diagnostics(Some(source_root)),
|
||||
resolve,
|
||||
frange,
|
||||
)?;
|
||||
|
@ -1280,8 +1285,9 @@ pub(crate) fn handle_code_action_resolve(
|
|||
let line_index = snap.file_line_index(file_id)?;
|
||||
let range = from_proto::text_range(&line_index, params.code_action_params.range)?;
|
||||
let frange = FileRange { file_id, range };
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let mut assists_config = snap.config.assist();
|
||||
let mut assists_config = snap.config.assist(Some(source_root));
|
||||
assists_config.allowed = params
|
||||
.code_action_params
|
||||
.context
|
||||
|
@ -1304,7 +1310,7 @@ pub(crate) fn handle_code_action_resolve(
|
|||
|
||||
let assists = snap.analysis.assists_with_fixes(
|
||||
&assists_config,
|
||||
&snap.config.diagnostics(),
|
||||
&snap.config.diagnostics(Some(source_root)),
|
||||
AssistResolveStrategy::Single(assist_resolve),
|
||||
frange,
|
||||
)?;
|
||||
|
@ -1433,8 +1439,12 @@ pub(crate) fn handle_document_highlight(
|
|||
let _p = tracing::span!(tracing::Level::INFO, "handle_document_highlight").entered();
|
||||
let position = from_proto::file_position(&snap, params.text_document_position_params)?;
|
||||
let line_index = snap.file_line_index(position.file_id)?;
|
||||
let source_root = snap.analysis.source_root(position.file_id)?;
|
||||
|
||||
let refs = match snap.analysis.highlight_related(snap.config.highlight_related(), position)? {
|
||||
let refs = match snap
|
||||
.analysis
|
||||
.highlight_related(snap.config.highlight_related(Some(source_root)), position)?
|
||||
{
|
||||
None => return Ok(None),
|
||||
Some(refs) => refs,
|
||||
};
|
||||
|
@ -1480,7 +1490,9 @@ pub(crate) fn handle_inlay_hints(
|
|||
params.range,
|
||||
)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let inlay_hints_config = snap.config.inlay_hints();
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let inlay_hints_config = snap.config.inlay_hints(Some(source_root));
|
||||
Ok(Some(
|
||||
snap.analysis
|
||||
.inlay_hints(&inlay_hints_config, file_id, Some(range))?
|
||||
|
@ -1512,7 +1524,9 @@ pub(crate) fn handle_inlay_hints_resolve(
|
|||
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let hint_position = from_proto::offset(&line_index, original_hint.position)?;
|
||||
let mut forced_resolve_inlay_hints_config = snap.config.inlay_hints();
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let mut forced_resolve_inlay_hints_config = snap.config.inlay_hints(Some(source_root));
|
||||
forced_resolve_inlay_hints_config.fields_to_resolve = InlayFieldsToResolve::empty();
|
||||
let resolve_hints = snap.analysis.inlay_hints_resolve(
|
||||
&forced_resolve_inlay_hints_config,
|
||||
|
@ -1644,8 +1658,9 @@ pub(crate) fn handle_semantic_tokens_full(
|
|||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let text = snap.analysis.file_text(file_id)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let mut highlight_config = snap.config.highlighting_config();
|
||||
let mut highlight_config = snap.config.highlighting_config(Some(source_root));
|
||||
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
|
||||
highlight_config.syntactic_name_ref_highlighting =
|
||||
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
|
||||
|
@ -1656,7 +1671,7 @@ pub(crate) fn handle_semantic_tokens_full(
|
|||
&line_index,
|
||||
highlights,
|
||||
snap.config.semantics_tokens_augments_syntax_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(Some(source_root)),
|
||||
);
|
||||
|
||||
// Unconditionally cache the tokens
|
||||
|
@ -1674,8 +1689,9 @@ pub(crate) fn handle_semantic_tokens_full_delta(
|
|||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let text = snap.analysis.file_text(file_id)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let source_root = snap.analysis.source_root(file_id)?;
|
||||
|
||||
let mut highlight_config = snap.config.highlighting_config();
|
||||
let mut highlight_config = snap.config.highlighting_config(Some(source_root));
|
||||
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
|
||||
highlight_config.syntactic_name_ref_highlighting =
|
||||
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
|
||||
|
@ -1686,7 +1702,7 @@ pub(crate) fn handle_semantic_tokens_full_delta(
|
|||
&line_index,
|
||||
highlights,
|
||||
snap.config.semantics_tokens_augments_syntax_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(Some(source_root)),
|
||||
);
|
||||
|
||||
let cached_tokens = snap.semantic_tokens_cache.lock().remove(¶ms.text_document.uri);
|
||||
|
@ -1717,8 +1733,9 @@ pub(crate) fn handle_semantic_tokens_range(
|
|||
let frange = from_proto::file_range(&snap, ¶ms.text_document, params.range)?;
|
||||
let text = snap.analysis.file_text(frange.file_id)?;
|
||||
let line_index = snap.file_line_index(frange.file_id)?;
|
||||
let source_root = snap.analysis.source_root(frange.file_id)?;
|
||||
|
||||
let mut highlight_config = snap.config.highlighting_config();
|
||||
let mut highlight_config = snap.config.highlighting_config(Some(source_root));
|
||||
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
|
||||
highlight_config.syntactic_name_ref_highlighting =
|
||||
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
|
||||
|
@ -1729,7 +1746,7 @@ pub(crate) fn handle_semantic_tokens_range(
|
|||
&line_index,
|
||||
highlights,
|
||||
snap.config.semantics_tokens_augments_syntax_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(),
|
||||
snap.config.highlighting_non_standard_tokens(Some(source_root)),
|
||||
);
|
||||
Ok(Some(semantic_tokens.into()))
|
||||
}
|
||||
|
@ -1942,8 +1959,8 @@ fn goto_type_action_links(
|
|||
snap: &GlobalStateSnapshot,
|
||||
nav_targets: &[HoverGotoTypeData],
|
||||
) -> Option<lsp_ext::CommandLinkGroup> {
|
||||
if !snap.config.hover_actions().goto_type_def
|
||||
|| nav_targets.is_empty()
|
||||
if nav_targets.is_empty()
|
||||
|| !snap.config.hover_actions().goto_type_def
|
||||
|| !snap.config.client_commands().goto_location
|
||||
{
|
||||
return None;
|
||||
|
|
|
@ -233,7 +233,7 @@ pub(crate) fn completion_items(
|
|||
completion_item(&mut res, config, line_index, &tdpp, max_relevance, item);
|
||||
}
|
||||
|
||||
if let Some(limit) = config.completion().limit {
|
||||
if let Some(limit) = config.completion(None).limit {
|
||||
res.sort_by(|item1, item2| item1.sort_text.cmp(&item2.sort_text));
|
||||
res.truncate(limit);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ fn completion_item(
|
|||
|
||||
set_score(&mut lsp_item, max_relevance, item.relevance);
|
||||
|
||||
if config.completion().enable_imports_on_the_fly && !item.import_to_add.is_empty() {
|
||||
if config.completion(None).enable_imports_on_the_fly && !item.import_to_add.is_empty() {
|
||||
let imports = item
|
||||
.import_to_add
|
||||
.into_iter()
|
||||
|
|
|
@ -428,7 +428,7 @@ impl GlobalState {
|
|||
}
|
||||
}
|
||||
|
||||
if self.config.cargo_autoreload() {
|
||||
if self.config.cargo_autoreload_config() {
|
||||
if let Some((cause, force_crate_graph_reload)) =
|
||||
self.fetch_workspaces_queue.should_start_op()
|
||||
{
|
||||
|
|
|
@ -76,9 +76,9 @@ impl GlobalState {
|
|||
if self.config.lru_parse_query_capacity() != old_config.lru_parse_query_capacity() {
|
||||
self.analysis_host.update_lru_capacity(self.config.lru_parse_query_capacity());
|
||||
}
|
||||
if self.config.lru_query_capacities() != old_config.lru_query_capacities() {
|
||||
if self.config.lru_query_capacities_config() != old_config.lru_query_capacities_config() {
|
||||
self.analysis_host.update_lru_capacities(
|
||||
&self.config.lru_query_capacities().cloned().unwrap_or_default(),
|
||||
&self.config.lru_query_capacities_config().cloned().unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue