Skip to content

fix: Fix completion_snippets_custom config always erroring #19636

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

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ impl Config {
if !(json.is_null() || json.as_object().is_some_and(|it| it.is_empty())) {
let detached_files = get_field_json::<Vec<Utf8PathBuf>>(
&mut json,
// Do not record errors here; it is not an error if a field is missing here.
&mut Vec::new(),
"detachedFiles",
None,
Expand All @@ -935,19 +934,20 @@ impl Config {

patch_old_style::patch_json_for_outdated_configs(&mut json);

let snips = get_field_json::<FxIndexMap<String, SnippetDef>>(
&mut json,
// Do not record errors here; it is not an error if a field is missing here.
&mut Vec::new(),
"completion_snippets_custom",
None,
)
.unwrap_or(self.completion_snippets_custom().to_owned());

let mut json_errors = vec![];

let input = FullConfigInput::from_json(json, &mut json_errors);

// IMPORTANT : This holds as long as ` completion_snippets_custom` is declared `client`.
config.snippets.clear();

let snips = input
.global
.completion_snippets_custom
.as_ref()
.unwrap_or(&self.default_config.global.completion_snippets_custom);
#[allow(dead_code)]
let _ = Self::completion_snippets_custom;
for (name, def) in snips.iter() {
if def.prefix.is_empty() && def.postfix.is_empty() {
continue;
Expand All @@ -974,8 +974,9 @@ impl Config {
)),
}
}

config.client_config = (
FullConfigInput::from_json(json, &mut json_errors),
input,
ConfigErrors(
json_errors
.into_iter()
Expand Down