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 revamp #12010

Merged
merged 11 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/hir-expand/src/builtin_fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn env_expand(
// unnecessary diagnostics for eg. `CARGO_PKG_NAME`.
if key == "OUT_DIR" {
err = Some(ExpandError::Other(
r#"`OUT_DIR` not set, enable "run build scripts" to fix"#.into(),
r#"`OUT_DIR` not set, enable "build scripts" to fix"#.into(),
));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ide-diagnostics/src/handlers/macro_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ macro_rules! env { () => {} }
macro_rules! concat { () => {} }

include!(concat!(env!("OUT_DIR"), "/out.rs"));
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix
"#,
);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ fn main() {
//^^^^^^^^^^^^^ error: could not convert tokens

env!("OUT_DIR");
//^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "run build scripts" to fix
//^^^^^^^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix

compile_error!("compile_error works");
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error works
Expand Down
624 changes: 412 additions & 212 deletions crates/rust-analyzer/src/config.rs

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions crates/rust-analyzer/src/config/patch_old_style.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//! See [`patch_json_for_outdated_configs`]
use serde_json::{json, Value};

/// This function patches the json config to the new expected keys.
/// That is we try to load old known config keys here and convert them to the new ones.
/// See https://github.com/rust-lang/rust-analyzer/pull/12010
pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
let copy = json.clone();

macro_rules! patch {
($(
$($src:ident).+ -> $($dst:ident).+ ;
)+) => { $(
if let Some(it) = copy.pointer(concat!($("/", stringify!($src)),+)).cloned() {
let mut last = it;
for segment in [$(stringify!($dst)),+].into_iter().rev() {
last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_string(), last))));
}

merge(json, last);
}
)+ };
}

patch! {
assist.allowMergingIntoGlobImports -> imports.merge.glob;
assist.exprFillDefault -> assist.expressionFillDefault;
assist.importEnforceGranularity -> imports.granularity.enforce;
assist.importGranularity -> imports.granularity.group;
assist.importMergeBehavior -> imports.granularity.group;
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.runBuildScripts.overrideCommand;
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 -> hover.links.enable;
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;
}

// callInfo_full -> signatureInfo_detail, signatureInfo_documentation_enable
if let Some(Value::Bool(b)) = copy.pointer("/callInfo/full") {
let sig_info = match b {
true => json!({ "signatureInfo": {
"documentation": {"enable": true}},
"detail": "full"
}),
false => json!({ "signatureInfo": {
"documentation": {"enable": false}},
"detail": "parameters"
}),
};
merge(json, sig_info);
}

// cargo_allFeatures, cargo_features -> cargo_features
if let Some(Value::Bool(true)) = copy.pointer("/cargo/allFeatures") {
merge(json, json!({ "cargo": { "features": "all" } }));
}

// checkOnSave_allFeatures, checkOnSave_features -> checkOnSave_features
if let Some(Value::Bool(true)) = copy.pointer("/checkOnSave/allFeatures") {
merge(json, json!({ "checkOnSave": { "features": "all" } }));
}

// completion_addCallArgumentSnippets completion_addCallParenthesis -> completion_callable_snippets
let res = match (
copy.pointer("/completion/addCallArgumentSnippets"),
copy.pointer("/completion/addCallParenthesis"),
) {
(Some(Value::Bool(true)), Some(Value::Bool(true))) => json!("fill_arguments"),
(Some(Value::Bool(true)), _) => json!("add_parentheses"),
(_, _) => json!(null),
};
merge(json, json!({ "completion": { "callable": {"snippets": res }} }));
}

fn merge(dst: &mut Value, src: Value) {
match (dst, src) {
(Value::Object(dst), Value::Object(src)) => {
for (k, v) in src {
merge(dst.entry(k).or_insert(v.clone()), v)
}
}
(dst, src) => *dst = src,
}
}
6 changes: 3 additions & 3 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ pub(crate) fn handle_signature_help(
Some(it) => it,
None => return Ok(None),
};
let concise = !snap.config.call_info_full();
let res = to_proto::signature_help(help, concise, snap.config.signature_help_label_offsets());
let config = snap.config.call_info();
let res = to_proto::signature_help(help, config, snap.config.signature_help_label_offsets());
Ok(Some(res))
}

Expand Down Expand Up @@ -1215,7 +1215,7 @@ pub(crate) fn handle_code_lens(
.unwrap_or(false),
annotate_runnables: lens_config.runnable(),
annotate_impls: lens_config.implementations,
annotate_references: lens_config.refs,
annotate_references: lens_config.refs_adt,
annotate_method_references: lens_config.method_refs,
annotate_enum_variant_references: lens_config.enum_variant_refs,
},
Expand Down
22 changes: 9 additions & 13 deletions crates/rust-analyzer/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use vfs::AbsPath;

use crate::{
cargo_target_spec::CargoTargetSpec,
config::Config,
config::{CallInfoConfig, Config},
global_state::GlobalStateSnapshot,
line_index::{LineEndings, LineIndex, OffsetEncoding},
lsp_ext,
Expand Down Expand Up @@ -338,11 +338,11 @@ fn completion_item(

pub(crate) fn signature_help(
call_info: SignatureHelp,
concise: bool,
config: CallInfoConfig,
label_offsets: bool,
) -> lsp_types::SignatureHelp {
let (label, parameters) = match (concise, label_offsets) {
(_, false) => {
let (label, parameters) = match (!config.params_only, label_offsets) {
(concise, false) => {
let params = call_info
.parameter_labels()
.map(|label| lsp_types::ParameterInformation {
Expand Down Expand Up @@ -388,16 +388,12 @@ pub(crate) fn signature_help(
}
};

let documentation = if concise {
None
} else {
call_info.doc.map(|doc| {
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: doc,
})
let documentation = call_info.doc.filter(|_| config.docs).map(|doc| {
lsp_types::Documentation::MarkupContent(lsp_types::MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: doc,
})
};
});

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

Expand Down
10 changes: 7 additions & 3 deletions crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ version = \"0.0.0\"
#[test]
fn out_dirs_check() {
if skip_slow_tests() {
return;
// return;
}

let server = Project::with_fixture(
Expand Down Expand Up @@ -737,7 +737,9 @@ fn main() {
)
.with_config(serde_json::json!({
"cargo": {
"loadOutDirsFromCheck": true,
"buildScripts": {
"enable": true
},
"noSysroot": true,
}
}))
Expand Down Expand Up @@ -890,7 +892,9 @@ pub fn foo(_input: TokenStream) -> TokenStream {
)
.with_config(serde_json::json!({
"cargo": {
"loadOutDirsFromCheck": true,
"buildScripts": {
"enable": true
},
"noSysroot": true,
},
"procMacro": {
Expand Down
6 changes: 4 additions & 2 deletions crates/rust-analyzer/tests/slow-tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ impl<'a> Project<'a> {
// Loading standard library is costly, let's ignore it by default
"noSysroot": true,
// Can't use test binary as rustc wrapper.
"useRustcWrapperForBuildScripts": false,
"buildScripts": {
"useRustcWrapper": false
},
}
}),
}
Expand Down Expand Up @@ -137,7 +139,7 @@ impl<'a> Project<'a> {
},
);
config.discovered_projects = Some(discovered_projects);
let _ = config.update(self.config);
config.update(self.config).expect("invalid config");

Server::new(tmp_dir, config)
}
Expand Down
Loading