Skip to content

Commit 460e389

Browse files
committed
Auto merge of rust-lang#12010 - Veykril:r-a-config, r=Veykril
Config revamp Fixes rust-lang/rust-analyzer#11790 Fixes rust-lang/rust-analyzer#12115 This PR changes a lot of config names, and a few ones are being merged or split apart. The reason for this is that our configuration names currently are rather inconsistent and some where poorly chosen in regards to extensability. This PR plans to fix that. We still allow the old config names by patching them to the new ones before deserializing to keep backwards compatability with other clients (the VSCode client will auto update the config) but ideally we will get rid of that layer in the future. Here is a list of the changes: These are simple renames `old_name | alias1 | alias2 ... -> new_name` (the vscode client will fix these up automagically): ``` assist_allowMergingIntoGlobImports -> imports_merge_glob assist_exprFillDefault -> assist_expressionFillDefault assist_importEnforceGranularity -> imports_granularity_enforce assist_importGranularity | assist_importMergeBehavior | assist_importMergeBehaviour -> imports_granularity_group assist_importGroup -> imports_group_enable assist_importPrefix -> imports_prefix cache_warmup -> primeCaches_enable cargo_loadOutDirsFromCheck -> cargo_buildScripts_enable cargo_runBuildScripts | cargo_runBuildScriptsCommand -> cargo_runBuildScripts_overrideCommand cargo_useRustcWrapperForBuildScripts -> cargo_runBuildScripts_useRustcWrapper completion_snippets -> completion_snippets_custom diagnostics_enableExperimental -> diagnostics_experimental_enable experimental_procAttrMacros -> procMacro_attributes_enable highlighting_strings -> semanticHighlighting_strings_enable highlightRelated_breakPoints -> semanticHighlighting_breakPoints_enable highlightRelated_exitPoints -> semanticHighlighting_exitPoints_enable highlightRelated_yieldPoints -> semanticHighlighting_yieldPoints_enable highlightRelated_references -> semanticHighlighting_references_enable hover_documentation -> hover_documentation_enable hover_linksInHover | hoverActions_linksInHover -> hover_links_enable hoverActions_debug -> hoverActions_debug_enable hoverActions_enable -> hoverActions_enable_enable hoverActions_gotoTypeDef -> hoverActions_gotoTypeDef_enable hoverActions_implementations -> hoverActions_implementations_enable hoverActions_references -> hoverActions_references_enable hoverActions_run -> hoverActions_run_enable inlayHints_chainingHints -> inlayHints_chainingHints_enable inlayHints_closureReturnTypeHints -> inlayHints_closureReturnTypeHints_enable inlayHints_hideNamedConstructorHints -> inlayHints_typeHints_hideNamedConstructorHints inlayHints_parameterHints -> inlayHints_parameterHints_enable inlayHints_reborrowHints -> inlayHints_reborrowHints_enable inlayHints_typeHints -> inlayHints_typeHints_enable lruCapacity -> lru_capacity runnables_cargoExtraArgs -> runnables_extraArgs runnables_overrideCargo -> runnables_command rustcSource -> rustc_source rustfmt_enableRangeFormatting -> rustfmt_rangeFormatting_enable ``` These are configs that have been merged or split apart, which have to be manually updated by the user: ``` callInfo_full -> signatureInfo_detail, signatureInfo_documentation_enable cargo_allFeatures, cargo_features -> cargo_features checkOnSave_allFeatures, checkOnSave_features -> checkOnSave_features completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets ```
2 parents cf152e8 + 73df43f commit 460e389

File tree

13 files changed

+1134
-694
lines changed

13 files changed

+1134
-694
lines changed

crates/hir-expand/src/builtin_fn_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn env_expand(
635635
// unnecessary diagnostics for eg. `CARGO_PKG_NAME`.
636636
if key == "OUT_DIR" {
637637
err = Some(ExpandError::Other(
638-
r#"`OUT_DIR` not set, enable "run build scripts" to fix"#.into(),
638+
r#"`OUT_DIR` not set, enable "build scripts" to fix"#.into(),
639639
));
640640
}
641641

crates/ide-diagnostics/src/handlers/macro_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! env { () => {} }
111111
macro_rules! concat { () => {} }
112112
113113
include!(concat!(env!("OUT_DIR"), "/out.rs"));
114-
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
114+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
115115
"#,
116116
);
117117
}
@@ -161,7 +161,7 @@ fn main() {
161161
//^^^^^^^^^^^^^ error: could not convert tokens
162162
163163
env!("OUT_DIR");
164-
//^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
164+
//^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
165165
166166
compile_error!("compile_error works");
167167
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error works

crates/rust-analyzer/src/config.rs

+412-212
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//! See [`patch_json_for_outdated_configs`]
2+
use serde_json::{json, Value};
3+
4+
/// This function patches the json config to the new expected keys.
5+
/// That is we try to load old known config keys here and convert them to the new ones.
6+
/// See https://github.com/rust-lang/rust-analyzer/pull/12010
7+
pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
8+
let copy = json.clone();
9+
10+
macro_rules! patch {
11+
($(
12+
$($src:ident).+ -> $($dst:ident).+ ;
13+
)+) => { $(
14+
if let Some(it) = copy.pointer(concat!($("/", stringify!($src)),+)).cloned() {
15+
let mut last = it;
16+
for segment in [$(stringify!($dst)),+].into_iter().rev() {
17+
last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_string(), last))));
18+
}
19+
20+
merge(json, last);
21+
}
22+
)+ };
23+
}
24+
25+
patch! {
26+
assist.allowMergingIntoGlobImports -> imports.merge.glob;
27+
assist.exprFillDefault -> assist.expressionFillDefault;
28+
assist.importEnforceGranularity -> imports.granularity.enforce;
29+
assist.importGranularity -> imports.granularity.group;
30+
assist.importMergeBehavior -> imports.granularity.group;
31+
assist.importMergeBehaviour -> imports.granularity.group;
32+
assist.importGroup -> imports.group.enable;
33+
assist.importPrefix -> imports.prefix;
34+
cache.warmup -> primeCaches.enable;
35+
cargo.loadOutDirsFromCheck -> cargo.buildScripts.enable;
36+
cargo.runBuildScripts -> cargo.runBuildScripts.overrideCommand;
37+
cargo.runBuildScriptsCommand -> cargo.runBuildScripts.overrideCommand;
38+
cargo.useRustcWrapperForBuildScripts -> cargo.runBuildScripts.useRustcWrapper;
39+
completion.snippets -> completion.snippets.custom;
40+
diagnostics.enableExperimental -> diagnostics.experimental.enable;
41+
experimental.procAttrMacros -> procMacro.attributes.enable;
42+
highlighting.strings -> semanticHighlighting.strings.enable;
43+
highlightRelated.breakPoints -> semanticHighlighting.breakPoints.enable;
44+
highlightRelated.exitPoints -> semanticHighlighting.exitPoints.enable;
45+
highlightRelated.yieldPoints -> semanticHighlighting.yieldPoints.enable;
46+
highlightRelated.references -> semanticHighlighting.references.enable;
47+
hover.documentation -> hover.documentation.enable;
48+
hover.linksInHover -> hover.links.enable;
49+
hoverActions.linksInHover -> hover.links.enable;
50+
hoverActions.debug -> hoverActions.debug.enable;
51+
hoverActions.enable -> hoverActions.enable.enable;
52+
hoverActions.gotoTypeDef -> hoverActions.gotoTypeDef.enable;
53+
hoverActions.implementations -> hoverActions.implementations.enable;
54+
hoverActions.references -> hoverActions.references.enable;
55+
hoverActions.run -> hoverActions.run.enable;
56+
inlayHints.chainingHints -> inlayHints.chainingHints.enable;
57+
inlayHints.closureReturnTypeHints -> inlayHints.closureReturnTypeHints.enable;
58+
inlayHints.hideNamedConstructorHints -> inlayHints.typeHints.hideNamedConstructorHints;
59+
inlayHints.parameterHints -> inlayHints.parameterHints.enable;
60+
inlayHints.reborrowHints -> inlayHints.reborrowHints.enable;
61+
inlayHints.typeHints -> inlayHints.typeHints.enable;
62+
lruCapacity -> lru.capacity;
63+
runnables.cargoExtraArgs -> runnables.extraArgs ;
64+
runnables.overrideCargo -> runnables.command ;
65+
rustcSource -> rustc.source;
66+
rustfmt.enableRangeFormatting -> rustfmt.rangeFormatting.enable;
67+
}
68+
69+
// callInfo_full -> signatureInfo_detail, signatureInfo_documentation_enable
70+
if let Some(Value::Bool(b)) = copy.pointer("/callInfo/full") {
71+
let sig_info = match b {
72+
true => json!({ "signatureInfo": {
73+
"documentation": {"enable": true}},
74+
"detail": "full"
75+
}),
76+
false => json!({ "signatureInfo": {
77+
"documentation": {"enable": false}},
78+
"detail": "parameters"
79+
}),
80+
};
81+
merge(json, sig_info);
82+
}
83+
84+
// cargo_allFeatures, cargo_features -> cargo_features
85+
if let Some(Value::Bool(true)) = copy.pointer("/cargo/allFeatures") {
86+
merge(json, json!({ "cargo": { "features": "all" } }));
87+
}
88+
89+
// checkOnSave_allFeatures, checkOnSave_features -> checkOnSave_features
90+
if let Some(Value::Bool(true)) = copy.pointer("/checkOnSave/allFeatures") {
91+
merge(json, json!({ "checkOnSave": { "features": "all" } }));
92+
}
93+
94+
// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
95+
let res = match (
96+
copy.pointer("/completion/addCallArgumentSnippets"),
97+
copy.pointer("/completion/addCallParenthesis"),
98+
) {
99+
(Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"),
100+
(Some(Value::Bool(true)), _) => json!("add_parentheses"),
101+
(_, _) => json!(null),
102+
};
103+
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
104+
}
105+
106+
fn merge(dst: &mut Value, src: Value) {
107+
match (dst, src) {
108+
(Value::Object(dst), Value::Object(src)) => {
109+
for (k, v) in src {
110+
merge(dst.entry(k).or_insert(v.clone()), v)
111+
}
112+
}
113+
(dst, src) => *dst = src,
114+
}
115+
}

crates/rust-analyzer/src/handlers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@ pub(crate) fn handle_signature_help(
911911
Some(it) => it,
912912
None => return Ok(None),
913913
};
914-
let concise = !snap.config.call_info_full();
915-
let res = to_proto::signature_help(help, concise, snap.config.signature_help_label_offsets());
914+
let config = snap.config.call_info();
915+
let res = to_proto::signature_help(help, config, snap.config.signature_help_label_offsets());
916916
Ok(Some(res))
917917
}
918918

@@ -1215,7 +1215,7 @@ pub(crate) fn handle_code_lens(
12151215
.unwrap_or(false),
12161216
annotate_runnables: lens_config.runnable(),
12171217
annotate_impls: lens_config.implementations,
1218-
annotate_references: lens_config.refs,
1218+
annotate_references: lens_config.refs_adt,
12191219
annotate_method_references: lens_config.method_refs,
12201220
annotate_enum_variant_references: lens_config.enum_variant_refs,
12211221
},

crates/rust-analyzer/src/to_proto.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use vfs::AbsPath;
1818

1919
use crate::{
2020
cargo_target_spec::CargoTargetSpec,
21-
config::Config,
21+
config::{CallInfoConfig, Config},
2222
global_state::GlobalStateSnapshot,
2323
line_index::{LineEndings, LineIndex, OffsetEncoding},
2424
lsp_ext,
@@ -338,11 +338,11 @@ fn completion_item(
338338

339339
pub(crate) fn signature_help(
340340
call_info: SignatureHelp,
341-
concise: bool,
341+
config: CallInfoConfig,
342342
label_offsets: bool,
343343
) -> lsp_types::SignatureHelp {
344-
let (label, parameters) = match (concise, label_offsets) {
345-
(_, false) => {
344+
let (label, parameters) = match (!config.params_only, label_offsets) {
345+
(concise, false) => {
346346
let params = call_info
347347
.parameter_labels()
348348
.map(|label| lsp_types::ParameterInformation {
@@ -388,16 +388,12 @@ pub(crate) fn signature_help(
388388
}
389389
};
390390

391-
let documentation = if concise {
392-
None
393-
} else {
394-
call_info.doc.map(|doc| {
395-
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
396-
kind: lsp_types::MarkupKind::Markdown,
397-
value: doc,
398-
})
391+
let documentation = call_info.doc.filter(|_| config.docs).map(|doc| {
392+
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
393+
kind: lsp_types::MarkupKind::Markdown,
394+
value: doc,
399395
})
400-
};
396+
});
401397

402398
let active_parameter = call_info.active_parameter.map(|it| it as u32);
403399

crates/rust-analyzer/tests/slow-tests/main.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ version = \"0.0.0\"
685685
#[test]
686686
fn out_dirs_check() {
687687
if skip_slow_tests() {
688-
return;
688+
// return;
689689
}
690690

691691
let server = Project::with_fixture(
@@ -737,7 +737,9 @@ fn main() {
737737
)
738738
.with_config(serde_json::json!({
739739
"cargo": {
740-
"loadOutDirsFromCheck": true,
740+
"buildScripts": {
741+
"enable": true
742+
},
741743
"noSysroot": true,
742744
}
743745
}))
@@ -890,7 +892,9 @@ pub fn foo(_input: TokenStream) -> TokenStream {
890892
)
891893
.with_config(serde_json::json!({
892894
"cargo": {
893-
"loadOutDirsFromCheck": true,
895+
"buildScripts": {
896+
"enable": true
897+
},
894898
"noSysroot": true,
895899
},
896900
"procMacro": {

crates/rust-analyzer/tests/slow-tests/support.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ impl<'a> Project<'a> {
3636
// Loading standard library is costly, let's ignore it by default
3737
"noSysroot": true,
3838
// Can't use test binary as rustc wrapper.
39-
"useRustcWrapperForBuildScripts": false,
39+
"buildScripts": {
40+
"useRustcWrapper": false
41+
},
4042
}
4143
}),
4244
}
@@ -137,7 +139,7 @@ impl<'a> Project<'a> {
137139
},
138140
);
139141
config.discovered_projects = Some(discovered_projects);
140-
let _ = config.update(self.config);
142+
config.update(self.config).expect("invalid config");
141143

142144
Server::new(tmp_dir, config)
143145
}

0 commit comments

Comments
 (0)