diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs index 8d2352f06ede..aa09912f302d 100644 --- a/crates/hir-expand/src/builtin_fn_macro.rs +++ b/crates/hir-expand/src/builtin_fn_macro.rs @@ -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(), )); } diff --git a/crates/ide-diagnostics/src/handlers/macro_error.rs b/crates/ide-diagnostics/src/handlers/macro_error.rs index a5bfb302d5eb..53d0131e02da 100644 --- a/crates/ide-diagnostics/src/handlers/macro_error.rs +++ b/crates/ide-diagnostics/src/handlers/macro_error.rs @@ -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 "#, ); } @@ -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 diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index ad1f9c40e2b3..4d7db826c544 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -35,6 +35,15 @@ use crate::{ lsp_ext::{self, supports_utf8, WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope}, }; +mod patch_old_style; + +// Conventions for configuration keys to preserve maximal extendability without breakage: +// - Toggles (be it binary true/false or with more options in-between) should almost always suffix as `_enable` +// This has the benefit of namespaces being extensible, and if the suffix doesn't fit later it can be changed without breakage. +// - In general be wary of using the namespace of something verbatim, it prevents us from adding subkeys in the future +// - Don't use abbreviations unless really necessary +// - foo_command = overrides the subcommand, foo_overrideCommand allows full overwriting, extra args only applies for foo_command + // Defines the server-side configuration of the rust-analyzer. We generate // *parts* of VS Code's `package.json` config from this. // @@ -45,85 +54,89 @@ use crate::{ // parsing the old name. config_data! { struct ConfigData { - /// Placeholder for missing expressions in assists. - assist_exprFillDefault: ExprFillDefaultDef = "\"todo\"", - /// How imports should be grouped into use statements. - assist_importGranularity | - assist_importMergeBehavior | - assist_importMergeBehaviour: ImportGranularityDef = "\"crate\"", - /// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file. - assist_importEnforceGranularity: bool = "false", - /// The path structure for newly inserted paths to use. - assist_importPrefix: ImportPrefixDef = "\"plain\"", - /// Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines. - assist_importGroup: bool = "true", - /// Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`. - assist_allowMergingIntoGlobImports: bool = "true", - - /// Warm up caches on project load. - cache_warmup: bool = "true", - - /// Show function name and docs in parameter hints. - callInfo_full: bool = "true", + /// Placeholder expression to use for missing expressions in assists. + assist_expressionFillDefault: ExprFillDefaultDef = "\"todo\"", /// Automatically refresh project info via `cargo metadata` on /// `Cargo.toml` changes. cargo_autoreload: bool = "true", - /// Activate all available features (`--all-features`). - cargo_allFeatures: bool = "false", - /// Unsets `#[cfg(test)]` for the specified crates. - cargo_unsetTest: Vec = "[\"core\"]", - /// List of features to activate. - cargo_features: Vec = "[]", /// Run build scripts (`build.rs`) for more precise code analysis. - cargo_runBuildScripts | - cargo_loadOutDirsFromCheck: bool = "true", - /// Advanced option, fully override the command rust-analyzer uses to - /// run build scripts and build procedural macros. The command should - /// include `--message-format=json` or a similar option. - cargo_runBuildScriptsCommand: Option> = "null", + cargo_buildScripts_enable: bool = "true", + /// Override the command rust-analyzer uses to run build scripts and + /// build procedural macros. The command is required to output json + /// and should therefor include `--message-format=json` or a similar + /// option. + /// + /// By default, a cargo invocation will be constructed for the configured + /// targets and features, with the following base command line: + /// + /// ```bash + /// cargo check --quiet --workspace --message-format=json --all-targets + /// ``` + /// . + cargo_buildScripts_overrideCommand: Option> = "null", /// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to /// avoid compiling unnecessary things. - cargo_useRustcWrapperForBuildScripts: bool = "true", - /// Do not activate the `default` feature. + cargo_buildScripts_useRustcWrapper: bool = "true", + /// List of features to activate. + /// + /// Set this to `"all"` to pass `--all-features` to cargo. + cargo_features: CargoFeatures = "[]", + /// Whether to pass `--no-default-features` to cargo. cargo_noDefaultFeatures: bool = "false", - /// Compilation target (target triple). - cargo_target: Option = "null", /// Internal config for debugging, disables loading of sysroot crates. cargo_noSysroot: bool = "false", + /// Compilation target override (target triple). + cargo_target: Option = "null", + /// Unsets `#[cfg(test)]` for the specified crates. + cargo_unsetTest: Vec = "[\"core\"]", - /// Run specified `cargo check` command for diagnostics on save. - checkOnSave_enable: bool = "true", - /// Check with all features (`--all-features`). - /// Defaults to `#rust-analyzer.cargo.allFeatures#`. - checkOnSave_allFeatures: Option = "null", /// Check all targets and tests (`--all-targets`). checkOnSave_allTargets: bool = "true", /// Cargo command to use for `cargo check`. checkOnSave_command: String = "\"check\"", - /// Do not activate the `default` feature. - checkOnSave_noDefaultFeatures: Option = "null", - /// Check for a specific target. Defaults to - /// `#rust-analyzer.cargo.target#`. - checkOnSave_target: Option = "null", + /// Run specified `cargo check` command for diagnostics on save. + checkOnSave_enable: bool = "true", /// Extra arguments for `cargo check`. checkOnSave_extraArgs: Vec = "[]", /// List of features to activate. Defaults to /// `#rust-analyzer.cargo.features#`. - checkOnSave_features: Option> = "null", - /// Advanced option, fully override the command rust-analyzer uses for - /// checking. The command should include `--message-format=json` or - /// similar option. + /// + /// Set to `"all"` to pass `--all-features` to cargo. + checkOnSave_features: Option = "null", + /// Do not activate the `default` feature. + checkOnSave_noDefaultFeatures: Option = "null", + /// Override the command rust-analyzer uses to run build scripts and + /// build procedural macros. The command is required to output json + /// and should therefor include `--message-format=json` or a similar + /// option. + /// + /// An example command would be: + /// + /// ```bash + /// cargo check --workspace --message-format=json --all-targets + /// ``` + /// . checkOnSave_overrideCommand: Option> = "null", + /// Check for a specific target. Defaults to + /// `#rust-analyzer.cargo.target#`. + checkOnSave_target: Option = "null", - /// Whether to add argument snippets when completing functions. - /// Only applies when `#rust-analyzer.completion.addCallParenthesis#` is set. - completion_addCallArgumentSnippets: bool = "true", - /// Whether to add parenthesis when completing functions. - completion_addCallParenthesis: bool = "true", + /// Toggles the additional completions that automatically add imports when completed. + /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. + completion_autoimport_enable: bool = "true", + /// Toggles the additional completions that automatically show method calls and field accesses + /// with `self` prefixed to them when inside a method. + completion_autoself_enable: bool = "true", + /// Whether to add parenthesis and argument snippets when completing function. + completion_callable_snippets: Option = "\"fill_arguments\"", + /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc. + completion_postfix_enable: bool = "true", + /// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position. + completion_privateEditable_enable: bool = "false", /// Custom completion snippets. // NOTE: Keep this list in sync with the feature docs of user snippets. - completion_snippets: FxHashMap = r#"{ + completion_snippets_custom: FxHashMap = r#"{ "Arc::new": { "postfix": "arc", "body": "Arc::new(${receiver})", @@ -164,24 +177,14 @@ config_data! { "scope": "expr" } }"#, - /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc. - completion_postfix_enable: bool = "true", - /// Toggles the additional completions that automatically add imports when completed. - /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. - completion_autoimport_enable: bool = "true", - /// Toggles the additional completions that automatically show method calls and field accesses - /// with `self` prefixed to them when inside a method. - completion_autoself_enable: bool = "true", - /// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position. - completion_privateEditable_enable: bool = "false", + /// List of rust-analyzer diagnostics to disable. + diagnostics_disabled: FxHashSet = "[]", /// Whether to show native rust-analyzer diagnostics. diagnostics_enable: bool = "true", /// Whether to show experimental rust-analyzer diagnostics that might /// have more false positives than usual. - diagnostics_enableExperimental: bool = "false", - /// List of rust-analyzer diagnostics to disable. - diagnostics_disabled: FxHashSet = "[]", + diagnostics_experimental_enable: bool = "false", /// Map of prefixes to be substituted when parsing diagnostic file paths. /// This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`. diagnostics_remapPrefix: FxHashMap = "{}", @@ -196,110 +199,113 @@ config_data! { /// and a blue icon in the `Problems Panel`. diagnostics_warningsAsInfo: Vec = "[]", - /// Expand attribute macros. - experimental_procAttrMacros: bool = "true", - - /// Controls file watching implementation. - files_watcher: String = "\"client\"", /// These directories will be ignored by rust-analyzer. They are /// relative to the workspace root, and globs are not supported. You may /// also need to add the folders to Code's `files.watcherExclude`. files_excludeDirs: Vec = "[]", + /// Controls file watching implementation. + files_watcher: String = "\"client\"", - /// Enables highlighting of related references while hovering your mouse above any identifier. - highlightRelated_references: bool = "true", - /// Enables highlighting of all exit points while hovering your mouse above any `return`, `?`, or return type arrow (`->`). - highlightRelated_exitPoints: bool = "true", - /// Enables highlighting of related references while hovering your mouse `break`, `loop`, `while`, or `for` keywords. - highlightRelated_breakPoints: bool = "true", - /// Enables highlighting of all break points for a loop or block context while hovering your mouse above any `async` or `await` keywords. - highlightRelated_yieldPoints: bool = "true", - - /// Use semantic tokens for strings. - /// - /// In some editors (e.g. vscode) semantic tokens override other highlighting grammars. - /// By disabling semantic tokens for strings, other grammars can be used to highlight - /// their contents. - highlighting_strings: bool = "true", - - /// Whether to show documentation on hover. - hover_documentation: bool = "true", - /// Use markdown syntax for links in hover. - hover_linksInHover | - hoverActions_linksInHover: bool = "true", + /// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords. + highlightRelated_breakPoints_enable: bool = "true", + /// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`). + highlightRelated_exitPoints_enable: bool = "true", + /// Enables highlighting of related references while the cursor is on any identifier. + highlightRelated_references_enable: bool = "true", + /// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords. + highlightRelated_yieldPoints_enable: bool = "true", /// Whether to show `Debug` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. - hoverActions_debug: bool = "true", + hover_actions_debug_enable: bool = "true", /// Whether to show HoverActions in Rust files. - hoverActions_enable: bool = "true", + hover_actions_enable: bool = "true", /// Whether to show `Go to Type Definition` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. - hoverActions_gotoTypeDef: bool = "true", + hover_actions_gotoTypeDef_enable: bool = "true", /// Whether to show `Implementations` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. - hoverActions_implementations: bool = "true", + hover_actions_implementations_enable: bool = "true", /// Whether to show `References` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. - hoverActions_references: bool = "false", + hover_actions_references_enable: bool = "false", /// Whether to show `Run` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. - hoverActions_run: bool = "true", + hover_actions_run_enable: bool = "true", + + /// Whether to show documentation on hover. + hover_documentation_enable: bool = "true", + /// Use markdown syntax for links in hover. + hover_links_enable: bool = "true", + + /// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file. + imports_granularity_enforce: bool = "false", + /// How imports should be grouped into use statements. + imports_granularity_group: ImportGranularityDef = "\"crate\"", + /// Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines. + imports_group_enable: bool = "true", + /// Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`. + imports_merge_glob: bool = "true", + /// The path structure for newly inserted paths to use. + imports_prefix: ImportPrefixDef = "\"plain\"", - /// Whether to render trailing colons for parameter hints, and trailing colons for parameter hints. - inlayHints_renderColons: bool = "true", - /// Maximum length for inlay hints. Set to null to have an unlimited length. - inlayHints_maxLength: Option = "25", - /// Whether to show function parameter name inlay hints at the call - /// site. - inlayHints_parameterHints: bool = "true", - /// Whether to show inlay type hints for variables. - inlayHints_typeHints: bool = "true", /// Whether to show inlay type hints for method chains. - inlayHints_chainingHints: bool = "true", + inlayHints_chainingHints_enable: bool = "true", /// Whether to show inlay type hints for return types of closures with blocks. - inlayHints_closureReturnTypeHints: bool = "false", - /// Whether to show inlay type hints for compiler inserted reborrows. - inlayHints_reborrowHints: bool = "false", + inlayHints_closureReturnTypeHints_enable: bool = "false", /// Whether to show inlay type hints for elided lifetimes in function signatures. inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = "\"never\"", /// Whether to prefer using parameter names as the name for elided lifetime hints if possible. - inlayHints_lifetimeElisionHints_useParameterNames: bool = "false", - /// Whether to hide inlay hints for constructors. - inlayHints_hideNamedConstructorHints: bool = "false", + inlayHints_lifetimeElisionHints_useParameterNames: bool = "false", + /// Maximum length for inlay hints. Set to null to have an unlimited length. + inlayHints_maxLength: Option = "25", + /// Whether to show function parameter name inlay hints at the call + /// site. + inlayHints_parameterHints_enable: bool = "true", + /// Whether to show inlay type hints for compiler inserted reborrows. + inlayHints_reborrowHints_enable: bool = "false", + /// Whether to render trailing colons for parameter hints, and trailing colons for parameter hints. + inlayHints_renderColons: bool = "true", + /// Whether to show inlay type hints for variables. + inlayHints_typeHints_enable: bool = "true", + /// Whether to hide inlay type hints for constructors. + inlayHints_typeHints_hideNamedConstructor: bool = "false", + /// Join lines merges consecutive declaration and initialization of an assignment. + joinLines_joinAssignments: bool = "true", /// Join lines inserts else between consecutive ifs. joinLines_joinElseIf: bool = "true", /// Join lines removes trailing commas. joinLines_removeTrailingComma: bool = "true", /// Join lines unwraps trivial blocks. joinLines_unwrapTrivialBlock: bool = "true", - /// Join lines merges consecutive declaration and initialization of an assignment. - joinLines_joinAssignments: bool = "true", /// Whether to show `Debug` lens. Only applies when /// `#rust-analyzer.lens.enable#` is set. - lens_debug: bool = "true", + lens_debug_enable: bool = "true", /// Whether to show CodeLens in Rust files. lens_enable: bool = "true", + /// Internal config: use custom client-side commands even when the + /// client doesn't set the corresponding capability. + lens_forceCustomCommands: bool = "true", /// Whether to show `Implementations` lens. Only applies when /// `#rust-analyzer.lens.enable#` is set. - lens_implementations: bool = "true", - /// Whether to show `Run` lens. Only applies when - /// `#rust-analyzer.lens.enable#` is set. - lens_run: bool = "true", - /// Whether to show `Method References` lens. Only applies when - /// `#rust-analyzer.lens.enable#` is set. - lens_methodReferences: bool = "false", - /// Whether to show `References` lens for Struct, Enum, Union and Trait. + lens_implementations_enable: bool = "true", + /// Whether to show `References` lens for Struct, Enum, and Union. /// Only applies when `#rust-analyzer.lens.enable#` is set. - lens_references: bool = "false", + lens_references_adt_enable: bool = "false", /// Whether to show `References` lens for Enum Variants. /// Only applies when `#rust-analyzer.lens.enable#` is set. - lens_enumVariantReferences: bool = "false", - /// Internal config: use custom client-side commands even when the - /// client doesn't set the corresponding capability. - lens_forceCustomCommands: bool = "true", + lens_references_enumVariant_enable: bool = "false", + /// Whether to show `Method References` lens. Only applies when + /// `#rust-analyzer.lens.enable#` is set. + lens_references_method_enable: bool = "false", + /// Whether to show `References` lens for Trait. + /// Only applies when `#rust-analyzer.lens.enable#` is set. + lens_references_trait_enable: bool = "false", + /// Whether to show `Run` lens. Only applies when + /// `#rust-analyzer.lens.enable#` is set. + lens_run_enable: bool = "true", /// Disable project auto-discovery in favor of explicitly specified set /// of projects. @@ -309,29 +315,33 @@ config_data! { linkedProjects: Vec = "[]", /// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. - lruCapacity: Option = "null", + lru_capacity: Option = "null", /// Whether to show `can't find Cargo.toml` error message. notifications_cargoTomlNotFound: bool = "true", + /// Warm up caches on project load. + primeCaches_enable: bool = "true", /// How many worker threads to to handle priming caches. The default `0` means to pick automatically. primeCaches_numThreads: ParallelPrimeCachesNumThreads = "0", - /// Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. + /// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set. + procMacro_attributes_enable: bool = "true", + /// Enable support for procedural macros, implies `#rust-analyzer.cargo.buildScripts.enable#`. procMacro_enable: bool = "true", - /// Internal config, path to proc-macro server executable (typically, - /// this is rust-analyzer itself, but we override this in tests). - procMacro_server: Option = "null", /// These proc-macros will be ignored when trying to expand them. /// /// This config takes a map of crate names with the exported proc-macro names to ignore as values. procMacro_ignored: FxHashMap, Box<[Box]>> = "{}", + /// Internal config, path to proc-macro server executable (typically, + /// this is rust-analyzer itself, but we override this in tests). + procMacro_server: Option = "null", /// Command to be executed instead of 'cargo' for runnables. - runnables_overrideCargo: Option = "null", + runnables_command: Option = "null", /// Additional arguments to be passed to cargo for runnables such as /// tests or binaries. For example, it may be `--release`. - runnables_cargoExtraArgs: Vec = "[]", + runnables_extraArgs: Vec = "[]", /// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private /// projects, or "discover" to try to automatically find it if the `rustc-dev` component @@ -341,7 +351,7 @@ config_data! { /// crates must set `[package.metadata.rust-analyzer] rustc_private=true` to use it. /// /// This option does not take effect until rust-analyzer is restarted. - rustcSource: Option = "null", + rustc_source: Option = "null", /// Additional arguments to `rustfmt`. rustfmt_extraArgs: Vec = "[]", @@ -351,16 +361,28 @@ config_data! { /// Enables the use of rustfmt's unstable range formatting command for the /// `textDocument/rangeFormatting` request. The rustfmt option is unstable and only /// available on a nightly build. - rustfmt_enableRangeFormatting: bool = "false", + rustfmt_rangeFormatting_enable: bool = "false", + + /// Use semantic tokens for strings. + /// + /// In some editors (e.g. vscode) semantic tokens override other highlighting grammars. + /// By disabling semantic tokens for strings, other grammars can be used to highlight + /// their contents. + semanticHighlighting_strings_enable: bool = "true", + + /// Show full signature of the callable. Only shows parameters if disabled. + signatureInfo_detail: SignatureDetail = "\"full\"", + /// Show documentation. + signatureInfo_documentation_enable: bool = "true", - /// Workspace symbol search scope. - workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"", /// Workspace symbol search kind. workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"", /// Limits the number of items returned from a workspace symbol search (Defaults to 128). /// Some clients like vs-code issue new searches on result filtering and don't require all results to be returned in the initial search. /// Other clients requires all results upfront and might require a higher limit. workspace_symbol_search_limit: usize = "128", + /// Workspace symbol search scope. + workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"", } } @@ -400,6 +422,11 @@ impl From for LinkedProject { } } +pub struct CallInfoConfig { + pub params_only: bool, + pub docs: bool, +} + #[derive(Clone, Debug, PartialEq, Eq)] pub struct LensConfig { // runnables @@ -411,7 +438,8 @@ pub struct LensConfig { // references pub method_refs: bool, - pub refs: bool, // for Struct, Enum, Union and Trait + pub refs_adt: bool, // for Struct, Enum, Union and Trait + pub refs_trait: bool, // for Struct, Enum, Union and Trait pub enum_variant_refs: bool, } @@ -421,7 +449,8 @@ impl LensConfig { || self.debug || self.implementations || self.method_refs - || self.refs + || self.refs_adt + || self.refs_trait || self.enum_variant_refs } @@ -434,7 +463,7 @@ impl LensConfig { } pub fn references(&self) -> bool { - self.method_refs || self.refs || self.enum_variant_refs + self.method_refs || self.refs_adt || self.refs_trait || self.enum_variant_refs } } @@ -520,6 +549,7 @@ pub struct ClientCommandsConfig { pub trigger_parameter_hints: bool, } +#[derive(Debug)] pub struct ConfigUpdateError { errors: Vec<(String, serde_json::Error)>, } @@ -564,9 +594,10 @@ impl Config { .into_iter() .map(AbsPathBuf::assert) .collect(); + patch_old_style::patch_json_for_outdated_configs(&mut json); self.data = ConfigData::from_json(json, &mut errors); self.snippets.clear(); - for (name, def) in self.data.completion_snippets.iter() { + for (name, def) in self.data.completion_snippets_custom.iter() { if def.prefix.is_empty() && def.postfix.is_empty() { continue; } @@ -685,7 +716,7 @@ impl Config { } pub fn prefill_caches(&self) -> bool { - self.data.cache_warmup + self.data.primeCaches_enable } pub fn location_link(&self) -> bool { @@ -795,9 +826,9 @@ impl Config { pub fn diagnostics(&self) -> DiagnosticsConfig { DiagnosticsConfig { - disable_experimental: !self.data.diagnostics_enableExperimental, + disable_experimental: !self.data.diagnostics_experimental_enable, disabled: self.data.diagnostics_disabled.clone(), - expr_fill_default: match self.data.assist_exprFillDefault { + expr_fill_default: match self.data.assist_expressionFillDefault { ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo, ExprFillDefaultDef::Default => ExprFillDefaultMode::Default, }, @@ -813,7 +844,7 @@ impl Config { } pub fn lru_capacity(&self) -> Option { - self.data.lruCapacity + self.data.lru_capacity } pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec)> { @@ -832,7 +863,7 @@ impl Config { } pub fn expand_proc_attr_macros(&self) -> bool { - self.data.experimental_procAttrMacros + self.data.procMacro_attributes_enable } pub fn files(&self) -> FilesConfig { @@ -857,11 +888,11 @@ impl Config { } pub fn run_build_scripts(&self) -> bool { - self.data.cargo_runBuildScripts || self.data.procMacro_enable + self.data.cargo_buildScripts_enable || self.data.procMacro_enable } pub fn cargo(&self) -> CargoConfig { - let rustc_source = self.data.rustcSource.as_ref().map(|rustc_src| { + let rustc_source = self.data.rustc_source.as_ref().map(|rustc_src| { if rustc_src == "discover" { RustcSource::Discover } else { @@ -871,14 +902,17 @@ impl Config { CargoConfig { no_default_features: self.data.cargo_noDefaultFeatures, - all_features: self.data.cargo_allFeatures, - features: self.data.cargo_features.clone(), + all_features: matches!(self.data.cargo_features, CargoFeatures::All), + features: match &self.data.cargo_features { + CargoFeatures::All => vec![], + CargoFeatures::Listed(it) => it.clone(), + }, target: self.data.cargo_target.clone(), no_sysroot: self.data.cargo_noSysroot, rustc_source, unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()), - wrap_rustc_in_build_scripts: self.data.cargo_useRustcWrapperForBuildScripts, - run_build_script_command: self.data.cargo_runBuildScriptsCommand.clone(), + wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper, + run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(), } } @@ -891,7 +925,7 @@ impl Config { } Some(_) | None => RustfmtConfig::Rustfmt { extra_args: self.data.rustfmt_extraArgs.clone(), - enable_range_formatting: self.data.rustfmt_enableRangeFormatting, + enable_range_formatting: self.data.rustfmt_rangeFormatting_enable, }, } } @@ -918,15 +952,19 @@ impl Config { .data .checkOnSave_noDefaultFeatures .unwrap_or(self.data.cargo_noDefaultFeatures), - all_features: self - .data - .checkOnSave_allFeatures - .unwrap_or(self.data.cargo_allFeatures), - features: self + all_features: matches!( + self.data.checkOnSave_features.as_ref().unwrap_or(&self.data.cargo_features), + CargoFeatures::All + ), + features: match self .data .checkOnSave_features .clone() - .unwrap_or_else(|| self.data.cargo_features.clone()), + .unwrap_or_else(|| self.data.cargo_features.clone()) + { + CargoFeatures::All => vec![], + CargoFeatures::Listed(it) => it, + }, extra_args: self.data.checkOnSave_extraArgs.clone(), }, }; @@ -935,25 +973,25 @@ impl Config { pub fn runnables(&self) -> RunnablesConfig { RunnablesConfig { - override_cargo: self.data.runnables_overrideCargo.clone(), - cargo_extra_args: self.data.runnables_cargoExtraArgs.clone(), + override_cargo: self.data.runnables_command.clone(), + cargo_extra_args: self.data.runnables_extraArgs.clone(), } } pub fn inlay_hints(&self) -> InlayHintsConfig { InlayHintsConfig { render_colons: self.data.inlayHints_renderColons, - type_hints: self.data.inlayHints_typeHints, - parameter_hints: self.data.inlayHints_parameterHints, - chaining_hints: self.data.inlayHints_chainingHints, - closure_return_type_hints: self.data.inlayHints_closureReturnTypeHints, + type_hints: self.data.inlayHints_typeHints_enable, + parameter_hints: self.data.inlayHints_parameterHints_enable, + chaining_hints: self.data.inlayHints_chainingHints_enable, + closure_return_type_hints: self.data.inlayHints_closureReturnTypeHints_enable, lifetime_elision_hints: match self.data.inlayHints_lifetimeElisionHints_enable { LifetimeElisionDef::Always => LifetimeElisionHints::Always, LifetimeElisionDef::Never => LifetimeElisionHints::Never, LifetimeElisionDef::SkipTrivial => LifetimeElisionHints::SkipTrivial, }, - hide_named_constructor_hints: self.data.inlayHints_hideNamedConstructorHints, - reborrow_hints: self.data.inlayHints_reborrowHints, + hide_named_constructor_hints: self.data.inlayHints_typeHints_hideNamedConstructor, + reborrow_hints: self.data.inlayHints_reborrowHints_enable, param_names_for_lifetime_elision_hints: self .data .inlayHints_lifetimeElisionHints_useParameterNames, @@ -963,20 +1001,20 @@ impl Config { fn insert_use_config(&self) -> InsertUseConfig { InsertUseConfig { - granularity: match self.data.assist_importGranularity { + granularity: match self.data.imports_granularity_group { ImportGranularityDef::Preserve => ImportGranularity::Preserve, ImportGranularityDef::Item => ImportGranularity::Item, ImportGranularityDef::Crate => ImportGranularity::Crate, ImportGranularityDef::Module => ImportGranularity::Module, }, - enforce_granularity: self.data.assist_importEnforceGranularity, - prefix_kind: match self.data.assist_importPrefix { + enforce_granularity: self.data.imports_granularity_enforce, + prefix_kind: match self.data.imports_prefix { ImportPrefixDef::Plain => PrefixKind::Plain, ImportPrefixDef::ByCrate => PrefixKind::ByCrate, ImportPrefixDef::BySelf => PrefixKind::BySelf, }, - group: self.data.assist_importGroup, - skip_glob_imports: !self.data.assist_allowMergingIntoGlobImports, + group: self.data.imports_group_enable, + skip_glob_imports: !self.data.imports_merge_glob, } } @@ -987,8 +1025,14 @@ impl Config { && completion_item_edit_resolve(&self.caps), enable_self_on_the_fly: self.data.completion_autoself_enable, enable_private_editable: self.data.completion_privateEditable_enable, - add_call_parenthesis: self.data.completion_addCallParenthesis, - add_call_argument_snippets: self.data.completion_addCallArgumentSnippets, + add_call_parenthesis: matches!( + self.data.completion_callable_snippets, + Some(CallableCompletionDef::AddParentheses) + ), + add_call_argument_snippets: matches!( + self.data.completion_callable_snippets, + Some(CallableCompletionDef::FillArguments) + ), insert_use: self.insert_use_config(), snippet_cap: SnippetCap::new(try_or_def!( self.caps @@ -1021,40 +1065,45 @@ impl Config { } } - pub fn call_info_full(&self) -> bool { - self.data.callInfo_full + pub fn call_info(&self) -> CallInfoConfig { + CallInfoConfig { + params_only: matches!(self.data.signatureInfo_detail, SignatureDetail::Parameters), + docs: self.data.signatureInfo_documentation_enable, + } } pub fn lens(&self) -> LensConfig { LensConfig { - run: self.data.lens_enable && self.data.lens_run, - debug: self.data.lens_enable && self.data.lens_debug, - implementations: self.data.lens_enable && self.data.lens_implementations, - method_refs: self.data.lens_enable && self.data.lens_methodReferences, - refs: self.data.lens_enable && self.data.lens_references, - enum_variant_refs: self.data.lens_enable && self.data.lens_enumVariantReferences, + run: self.data.lens_enable && self.data.lens_run_enable, + debug: self.data.lens_enable && self.data.lens_debug_enable, + implementations: self.data.lens_enable && self.data.lens_implementations_enable, + method_refs: self.data.lens_enable && self.data.lens_references_method_enable, + refs_adt: self.data.lens_enable && self.data.lens_references_adt_enable, + refs_trait: self.data.lens_enable && self.data.lens_references_trait_enable, + enum_variant_refs: self.data.lens_enable + && self.data.lens_references_enumVariant_enable, } } pub fn hover_actions(&self) -> HoverActionsConfig { - let enable = self.experimental("hoverActions") && self.data.hoverActions_enable; + let enable = self.experimental("hoverActions") && self.data.hover_actions_enable; HoverActionsConfig { - implementations: enable && self.data.hoverActions_implementations, - references: enable && self.data.hoverActions_references, - run: enable && self.data.hoverActions_run, - debug: enable && self.data.hoverActions_debug, - goto_type_def: enable && self.data.hoverActions_gotoTypeDef, + implementations: enable && self.data.hover_actions_implementations_enable, + references: enable && self.data.hover_actions_references_enable, + run: enable && self.data.hover_actions_run_enable, + debug: enable && self.data.hover_actions_debug_enable, + goto_type_def: enable && self.data.hover_actions_gotoTypeDef_enable, } } pub fn highlighting_strings(&self) -> bool { - self.data.highlighting_strings + self.data.semanticHighlighting_strings_enable } pub fn hover(&self) -> HoverConfig { HoverConfig { - links_in_hover: self.data.hover_linksInHover, - documentation: self.data.hover_documentation.then(|| { + links_in_hover: self.data.hover_links_enable, + documentation: self.data.hover_documentation_enable.then(|| { let is_markdown = try_or_def!(self .caps .text_document @@ -1132,10 +1181,10 @@ impl Config { pub fn highlight_related(&self) -> HighlightRelatedConfig { HighlightRelatedConfig { - references: self.data.highlightRelated_references, - break_points: self.data.highlightRelated_breakPoints, - exit_points: self.data.highlightRelated_exitPoints, - yield_points: self.data.highlightRelated_yieldPoints, + references: self.data.highlightRelated_references_enable, + break_points: self.data.highlightRelated_breakPoints_enable, + exit_points: self.data.highlightRelated_exitPoints_enable, + yield_points: self.data.highlightRelated_yieldPoints_enable, } } @@ -1146,9 +1195,106 @@ impl Config { } } } - // Deserialization definitions +macro_rules! create_bool_or_string_de { + ($ident:ident<$bool:literal, $string:literal>) => { + fn $ident<'de, D>(d: D) -> Result<(), D::Error> + where + D: serde::Deserializer<'de>, + { + struct V; + impl<'de> serde::de::Visitor<'de> for V { + type Value = (); + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str(concat!( + stringify!($bool), + " or \"", + stringify!($string), + "\"" + )) + } + + fn visit_bool(self, v: bool) -> Result + where + E: serde::de::Error, + { + match v { + $bool => Ok(()), + _ => Err(serde::de::Error::invalid_value( + serde::de::Unexpected::Bool(v), + &self, + )), + } + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + match v { + $string => Ok(()), + _ => Err(serde::de::Error::invalid_value( + serde::de::Unexpected::Str(v), + &self, + )), + } + } + + fn visit_enum(self, a: A) -> Result + where + A: serde::de::EnumAccess<'de>, + { + use serde::de::VariantAccess; + let (variant, va) = a.variant::<&'de str>()?; + va.unit_variant()?; + match variant { + $string => Ok(()), + _ => Err(serde::de::Error::invalid_value( + serde::de::Unexpected::Str(variant), + &self, + )), + } + } + } + d.deserialize_any(V) + } + }; +} +create_bool_or_string_de!(true_or_always); +create_bool_or_string_de!(false_or_never); + +macro_rules! named_unit_variant { + ($variant:ident) => { + pub(super) fn $variant<'de, D>(deserializer: D) -> Result<(), D::Error> + where + D: serde::Deserializer<'de>, + { + struct V; + impl<'de> serde::de::Visitor<'de> for V { + type Value = (); + fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str(concat!("\"", stringify!($variant), "\"")) + } + fn visit_str(self, value: &str) -> Result { + if value == stringify!($variant) { + Ok(()) + } else { + Err(E::invalid_value(serde::de::Unexpected::Str(value), &self)) + } + } + } + deserializer.deserialize_str(V) + } + }; +} + +mod de_unit_v { + named_unit_variant!(all); + named_unit_variant!(skip_trivial); +} + #[derive(Deserialize, Debug, Clone, Copy)] #[serde(rename_all = "snake_case")] enum SnippetScopeDef { @@ -1219,9 +1365,7 @@ enum ManifestOrProjectJson { #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "snake_case")] pub enum ExprFillDefaultDef { - #[serde(alias = "todo")] Todo, - #[serde(alias = "default")] Default, } @@ -1229,21 +1373,34 @@ pub enum ExprFillDefaultDef { #[serde(rename_all = "snake_case")] enum ImportGranularityDef { Preserve, - #[serde(alias = "none")] Item, - #[serde(alias = "full")] Crate, - #[serde(alias = "last")] Module, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "snake_case")] +enum CallableCompletionDef { + FillArguments, + AddParentheses, +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(untagged)] +enum CargoFeatures { + #[serde(deserialize_with = "de_unit_v::all")] + All, + Listed(Vec), +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(untagged)] enum LifetimeElisionDef { - #[serde(alias = "true")] + #[serde(deserialize_with = "true_or_always")] Always, - #[serde(alias = "false")] + #[serde(deserialize_with = "false_or_never")] Never, + #[serde(deserialize_with = "de_unit_v::skip_trivial")] SkipTrivial, } @@ -1264,6 +1421,13 @@ enum WorkspaceSymbolSearchScopeDef { WorkspaceAndDependencies, } +#[derive(Deserialize, Debug, Clone)] +#[serde(rename_all = "snake_case")] +enum SignatureDetail { + Full, + Parameters, +} + #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "snake_case")] enum WorkspaceSymbolSearchKindDef { @@ -1317,6 +1481,11 @@ macro_rules! _config_data { ]) } } + + #[test] + fn fields_are_sorted() { + [$(stringify!($field)),*].windows(2).for_each(|w| assert!(w[0] <= w[1], "{} <= {} does not hold", w[0], w[1])); + } }; } use _config_data as config_data; @@ -1329,7 +1498,6 @@ fn get_field( default: &str, ) -> T { let default = serde_json::from_str(default).unwrap(); - // XXX: check alias first, to work-around the VS Code where it pre-fills the // defaults instead of sending an empty object. alias @@ -1499,7 +1667,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json "maximum": 255 }, "LifetimeElisionDef" => set! { - "type": "string", + "type": ["string", "boolean"], "enum": ["always", "never", "skip_trivial"], "enumDescriptions": [ "Always show lifetime elision hints.", @@ -1507,6 +1675,38 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json "Only show lifetime elision hints if a return type is involved." ], }, + "CargoFeatures" => set! { + "type": ["string", "array"], + "items": { "type": "string" }, + "enum": ["all"], + "enumDescriptions": [ + "Pass `--all-features` to cargo", + ], + }, + "Option" => set! { + "type": ["string", "array", "null"], + "items": { "type": "string" }, + "enum": ["all"], + "enumDescriptions": [ + "Pass `--all-features` to cargo", + ], + }, + "Option" => set! { + "type": ["string", "null"], + "enum": ["fill_arguments", "add_parentheses"], + "enumDescriptions": [ + "Add call parentheses and pre-fill arguments", + "Add call parentheses", + ], + }, + "SignatureDetail" => set! { + "type": "string", + "enum": ["full", "parameters"], + "enumDescriptions": [ + "Show the entire signature.", + "Show only the parameters." + ], + }, _ => panic!("missing entry for {}: {}", ty, default), } diff --git a/crates/rust-analyzer/src/config/patch_old_style.rs b/crates/rust-analyzer/src/config/patch_old_style.rs new file mode 100644 index 000000000000..277364cefa0c --- /dev/null +++ b/crates/rust-analyzer/src/config/patch_old_style.rs @@ -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, + } +} diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index d005cdb98528..ec897ec9d955 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -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)) } @@ -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, }, diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 57b0e93765e8..ffcea078ce7e 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -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, @@ -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 { @@ -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); diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 147e8c141a20..143b63e11c59 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs @@ -685,7 +685,7 @@ version = \"0.0.0\" #[test] fn out_dirs_check() { if skip_slow_tests() { - return; + // return; } let server = Project::with_fixture( @@ -737,7 +737,9 @@ fn main() { ) .with_config(serde_json::json!({ "cargo": { - "loadOutDirsFromCheck": true, + "buildScripts": { + "enable": true + }, "noSysroot": true, } })) @@ -890,7 +892,9 @@ pub fn foo(_input: TokenStream) -> TokenStream { ) .with_config(serde_json::json!({ "cargo": { - "loadOutDirsFromCheck": true, + "buildScripts": { + "enable": true + }, "noSysroot": true, }, "procMacro": { diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 515cdfdc7c6a..36bffe3210e8 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs @@ -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 + }, } }), } @@ -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) } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index ace74f8e08af..c3fc4096a264 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -1,42 +1,7 @@ -[[rust-analyzer.assist.exprFillDefault]]rust-analyzer.assist.exprFillDefault (default: `"todo"`):: +[[rust-analyzer.assist.expressionFillDefault]]rust-analyzer.assist.expressionFillDefault (default: `"todo"`):: + -- -Placeholder for missing expressions in assists. --- -[[rust-analyzer.assist.importGranularity]]rust-analyzer.assist.importGranularity (default: `"crate"`):: -+ --- -How imports should be grouped into use statements. --- -[[rust-analyzer.assist.importEnforceGranularity]]rust-analyzer.assist.importEnforceGranularity (default: `false`):: -+ --- -Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file. --- -[[rust-analyzer.assist.importPrefix]]rust-analyzer.assist.importPrefix (default: `"plain"`):: -+ --- -The path structure for newly inserted paths to use. --- -[[rust-analyzer.assist.importGroup]]rust-analyzer.assist.importGroup (default: `true`):: -+ --- -Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines. --- -[[rust-analyzer.assist.allowMergingIntoGlobImports]]rust-analyzer.assist.allowMergingIntoGlobImports (default: `true`):: -+ --- -Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`. --- -[[rust-analyzer.cache.warmup]]rust-analyzer.cache.warmup (default: `true`):: -+ --- -Warm up caches on project load. --- -[[rust-analyzer.callInfo.full]]rust-analyzer.callInfo.full (default: `true`):: -+ --- -Show function name and docs in parameter hints. +Placeholder expression to use for missing expressions in assists. -- [[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`):: + @@ -44,79 +9,107 @@ Show function name and docs in parameter hints. Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes. -- -[[rust-analyzer.cargo.allFeatures]]rust-analyzer.cargo.allFeatures (default: `false`):: +[[rust-analyzer.cargo.buildScripts.enable]]rust-analyzer.cargo.buildScripts.enable (default: `true`):: + -- -Activate all available features (`--all-features`). +Run build scripts (`build.rs`) for more precise code analysis. -- -[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`):: +[[rust-analyzer.cargo.buildScripts.overrideCommand]]rust-analyzer.cargo.buildScripts.overrideCommand (default: `null`):: + -- -Unsets `#[cfg(test)]` for the specified crates. +Override the command rust-analyzer uses to run build scripts and +build procedural macros. The command is required to output json +and should therefor include `--message-format=json` or a similar +option. + +By default, a cargo invocation will be constructed for the configured +targets and features, with the following base command line: + +```bash +cargo check --quiet --workspace --message-format=json --all-targets +``` +. +-- +[[rust-analyzer.cargo.buildScripts.useRustcWrapper]]rust-analyzer.cargo.buildScripts.useRustcWrapper (default: `true`):: ++ +-- +Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to +avoid compiling unnecessary things. -- [[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`):: + -- List of features to activate. + +Set this to `"all"` to pass `--all-features` to cargo. -- -[[rust-analyzer.cargo.runBuildScripts]]rust-analyzer.cargo.runBuildScripts (default: `true`):: +[[rust-analyzer.cargo.noDefaultFeatures]]rust-analyzer.cargo.noDefaultFeatures (default: `false`):: + -- -Run build scripts (`build.rs`) for more precise code analysis. +Whether to pass `--no-default-features` to cargo. -- -[[rust-analyzer.cargo.runBuildScriptsCommand]]rust-analyzer.cargo.runBuildScriptsCommand (default: `null`):: +[[rust-analyzer.cargo.noSysroot]]rust-analyzer.cargo.noSysroot (default: `false`):: + -- -Advanced option, fully override the command rust-analyzer uses to -run build scripts and build procedural macros. The command should -include `--message-format=json` or a similar option. +Internal config for debugging, disables loading of sysroot crates. -- -[[rust-analyzer.cargo.useRustcWrapperForBuildScripts]]rust-analyzer.cargo.useRustcWrapperForBuildScripts (default: `true`):: +[[rust-analyzer.cargo.target]]rust-analyzer.cargo.target (default: `null`):: + -- -Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to -avoid compiling unnecessary things. +Compilation target override (target triple). -- -[[rust-analyzer.cargo.noDefaultFeatures]]rust-analyzer.cargo.noDefaultFeatures (default: `false`):: +[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`):: + -- -Do not activate the `default` feature. +Unsets `#[cfg(test)]` for the specified crates. -- -[[rust-analyzer.cargo.target]]rust-analyzer.cargo.target (default: `null`):: +[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: + -- -Compilation target (target triple). +Check all targets and tests (`--all-targets`). -- -[[rust-analyzer.cargo.noSysroot]]rust-analyzer.cargo.noSysroot (default: `false`):: +[[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`):: + -- -Internal config for debugging, disables loading of sysroot crates. +Cargo command to use for `cargo check`. -- [[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`):: + -- Run specified `cargo check` command for diagnostics on save. -- -[[rust-analyzer.checkOnSave.allFeatures]]rust-analyzer.checkOnSave.allFeatures (default: `null`):: +[[rust-analyzer.checkOnSave.extraArgs]]rust-analyzer.checkOnSave.extraArgs (default: `[]`):: + -- -Check with all features (`--all-features`). -Defaults to `#rust-analyzer.cargo.allFeatures#`. +Extra arguments for `cargo check`. -- -[[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: +[[rust-analyzer.checkOnSave.features]]rust-analyzer.checkOnSave.features (default: `null`):: + -- -Check all targets and tests (`--all-targets`). +List of features to activate. Defaults to +`#rust-analyzer.cargo.features#`. + +Set to `"all"` to pass `--all-features` to cargo. -- -[[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`):: +[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: + -- -Cargo command to use for `cargo check`. +Do not activate the `default` feature. -- -[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: +[[rust-analyzer.checkOnSave.overrideCommand]]rust-analyzer.checkOnSave.overrideCommand (default: `null`):: + -- -Do not activate the `default` feature. +Override the command rust-analyzer uses to run build scripts and +build procedural macros. The command is required to output json +and should therefor include `--message-format=json` or a similar +option. + +An example command would be: + +```bash +cargo check --workspace --message-format=json --all-targets +``` +. -- [[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `null`):: + @@ -124,36 +117,34 @@ Do not activate the `default` feature. Check for a specific target. Defaults to `#rust-analyzer.cargo.target#`. -- -[[rust-analyzer.checkOnSave.extraArgs]]rust-analyzer.checkOnSave.extraArgs (default: `[]`):: +[[rust-analyzer.completion.autoimport.enable]]rust-analyzer.completion.autoimport.enable (default: `true`):: + -- -Extra arguments for `cargo check`. +Toggles the additional completions that automatically add imports when completed. +Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. -- -[[rust-analyzer.checkOnSave.features]]rust-analyzer.checkOnSave.features (default: `null`):: +[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`):: + -- -List of features to activate. Defaults to -`#rust-analyzer.cargo.features#`. +Toggles the additional completions that automatically show method calls and field accesses +with `self` prefixed to them when inside a method. -- -[[rust-analyzer.checkOnSave.overrideCommand]]rust-analyzer.checkOnSave.overrideCommand (default: `null`):: +[[rust-analyzer.completion.callable.snippets]]rust-analyzer.completion.callable.snippets (default: `"fill_arguments"`):: + -- -Advanced option, fully override the command rust-analyzer uses for -checking. The command should include `--message-format=json` or -similar option. +Whether to add parenthesis and argument snippets when completing function. -- -[[rust-analyzer.completion.addCallArgumentSnippets]]rust-analyzer.completion.addCallArgumentSnippets (default: `true`):: +[[rust-analyzer.completion.postfix.enable]]rust-analyzer.completion.postfix.enable (default: `true`):: + -- -Whether to add argument snippets when completing functions. -Only applies when `#rust-analyzer.completion.addCallParenthesis#` is set. +Whether to show postfix snippets like `dbg`, `if`, `not`, etc. -- -[[rust-analyzer.completion.addCallParenthesis]]rust-analyzer.completion.addCallParenthesis (default: `true`):: +[[rust-analyzer.completion.privateEditable.enable]]rust-analyzer.completion.privateEditable.enable (default: `false`):: + -- -Whether to add parenthesis when completing functions. +Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position. -- -[[rust-analyzer.completion.snippets]]rust-analyzer.completion.snippets:: +[[rust-analyzer.completion.snippets.custom]]rust-analyzer.completion.snippets.custom:: + -- Default: @@ -203,44 +194,22 @@ Default: Custom completion snippets. -- -[[rust-analyzer.completion.postfix.enable]]rust-analyzer.completion.postfix.enable (default: `true`):: -+ --- -Whether to show postfix snippets like `dbg`, `if`, `not`, etc. --- -[[rust-analyzer.completion.autoimport.enable]]rust-analyzer.completion.autoimport.enable (default: `true`):: -+ --- -Toggles the additional completions that automatically add imports when completed. -Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. --- -[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`):: -+ --- -Toggles the additional completions that automatically show method calls and field accesses -with `self` prefixed to them when inside a method. --- -[[rust-analyzer.completion.privateEditable.enable]]rust-analyzer.completion.privateEditable.enable (default: `false`):: +[[rust-analyzer.diagnostics.disabled]]rust-analyzer.diagnostics.disabled (default: `[]`):: + -- -Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position. +List of rust-analyzer diagnostics to disable. -- [[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`):: + -- Whether to show native rust-analyzer diagnostics. -- -[[rust-analyzer.diagnostics.enableExperimental]]rust-analyzer.diagnostics.enableExperimental (default: `false`):: +[[rust-analyzer.diagnostics.experimental.enable]]rust-analyzer.diagnostics.experimental.enable (default: `false`):: + -- Whether to show experimental rust-analyzer diagnostics that might have more false positives than usual. -- -[[rust-analyzer.diagnostics.disabled]]rust-analyzer.diagnostics.disabled (default: `[]`):: -+ --- -List of rust-analyzer diagnostics to disable. --- [[rust-analyzer.diagnostics.remapPrefix]]rust-analyzer.diagnostics.remapPrefix (default: `{}`):: + -- @@ -263,16 +232,6 @@ List of warnings that should be displayed with info severity. The warnings will be indicated by a blue squiggly underline in code and a blue icon in the `Problems Panel`. -- -[[rust-analyzer.experimental.procAttrMacros]]rust-analyzer.experimental.procAttrMacros (default: `true`):: -+ --- -Expand attribute macros. --- -[[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`):: -+ --- -Controls file watching implementation. --- [[rust-analyzer.files.excludeDirs]]rust-analyzer.files.excludeDirs (default: `[]`):: + -- @@ -280,115 +239,110 @@ These directories will be ignored by rust-analyzer. They are relative to the workspace root, and globs are not supported. You may also need to add the folders to Code's `files.watcherExclude`. -- -[[rust-analyzer.highlightRelated.references]]rust-analyzer.highlightRelated.references (default: `true`):: -+ --- -Enables highlighting of related references while hovering your mouse above any identifier. --- -[[rust-analyzer.highlightRelated.exitPoints]]rust-analyzer.highlightRelated.exitPoints (default: `true`):: -+ --- -Enables highlighting of all exit points while hovering your mouse above any `return`, `?`, or return type arrow (`->`). --- -[[rust-analyzer.highlightRelated.breakPoints]]rust-analyzer.highlightRelated.breakPoints (default: `true`):: +[[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`):: + -- -Enables highlighting of related references while hovering your mouse `break`, `loop`, `while`, or `for` keywords. +Controls file watching implementation. -- -[[rust-analyzer.highlightRelated.yieldPoints]]rust-analyzer.highlightRelated.yieldPoints (default: `true`):: +[[rust-analyzer.highlightRelated.breakPoints.enable]]rust-analyzer.highlightRelated.breakPoints.enable (default: `true`):: + -- -Enables highlighting of all break points for a loop or block context while hovering your mouse above any `async` or `await` keywords. +Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords. -- -[[rust-analyzer.highlighting.strings]]rust-analyzer.highlighting.strings (default: `true`):: +[[rust-analyzer.highlightRelated.exitPoints.enable]]rust-analyzer.highlightRelated.exitPoints.enable (default: `true`):: + -- -Use semantic tokens for strings. - -In some editors (e.g. vscode) semantic tokens override other highlighting grammars. -By disabling semantic tokens for strings, other grammars can be used to highlight -their contents. +Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`). -- -[[rust-analyzer.hover.documentation]]rust-analyzer.hover.documentation (default: `true`):: +[[rust-analyzer.highlightRelated.references.enable]]rust-analyzer.highlightRelated.references.enable (default: `true`):: + -- -Whether to show documentation on hover. +Enables highlighting of related references while the cursor is on any identifier. -- -[[rust-analyzer.hover.linksInHover]]rust-analyzer.hover.linksInHover (default: `true`):: +[[rust-analyzer.highlightRelated.yieldPoints.enable]]rust-analyzer.highlightRelated.yieldPoints.enable (default: `true`):: + -- -Use markdown syntax for links in hover. +Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords. -- -[[rust-analyzer.hoverActions.debug]]rust-analyzer.hoverActions.debug (default: `true`):: +[[rust-analyzer.hover.actions.debug.enable]]rust-analyzer.hover.actions.debug.enable (default: `true`):: + -- Whether to show `Debug` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. -- -[[rust-analyzer.hoverActions.enable]]rust-analyzer.hoverActions.enable (default: `true`):: +[[rust-analyzer.hover.actions.enable]]rust-analyzer.hover.actions.enable (default: `true`):: + -- Whether to show HoverActions in Rust files. -- -[[rust-analyzer.hoverActions.gotoTypeDef]]rust-analyzer.hoverActions.gotoTypeDef (default: `true`):: +[[rust-analyzer.hover.actions.gotoTypeDef.enable]]rust-analyzer.hover.actions.gotoTypeDef.enable (default: `true`):: + -- Whether to show `Go to Type Definition` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. -- -[[rust-analyzer.hoverActions.implementations]]rust-analyzer.hoverActions.implementations (default: `true`):: +[[rust-analyzer.hover.actions.implementations.enable]]rust-analyzer.hover.actions.implementations.enable (default: `true`):: + -- Whether to show `Implementations` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. -- -[[rust-analyzer.hoverActions.references]]rust-analyzer.hoverActions.references (default: `false`):: +[[rust-analyzer.hover.actions.references.enable]]rust-analyzer.hover.actions.references.enable (default: `false`):: + -- Whether to show `References` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. -- -[[rust-analyzer.hoverActions.run]]rust-analyzer.hoverActions.run (default: `true`):: +[[rust-analyzer.hover.actions.run.enable]]rust-analyzer.hover.actions.run.enable (default: `true`):: + -- Whether to show `Run` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. -- -[[rust-analyzer.inlayHints.renderColons]]rust-analyzer.inlayHints.renderColons (default: `true`):: +[[rust-analyzer.hover.documentation.enable]]rust-analyzer.hover.documentation.enable (default: `true`):: + -- -Whether to render trailing colons for parameter hints, and trailing colons for parameter hints. +Whether to show documentation on hover. -- -[[rust-analyzer.inlayHints.maxLength]]rust-analyzer.inlayHints.maxLength (default: `25`):: +[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`):: + -- -Maximum length for inlay hints. Set to null to have an unlimited length. +Use markdown syntax for links in hover. -- -[[rust-analyzer.inlayHints.parameterHints]]rust-analyzer.inlayHints.parameterHints (default: `true`):: +[[rust-analyzer.imports.granularity.enforce]]rust-analyzer.imports.granularity.enforce (default: `false`):: + -- -Whether to show function parameter name inlay hints at the call -site. +Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file. -- -[[rust-analyzer.inlayHints.typeHints]]rust-analyzer.inlayHints.typeHints (default: `true`):: +[[rust-analyzer.imports.granularity.group]]rust-analyzer.imports.granularity.group (default: `"crate"`):: + -- -Whether to show inlay type hints for variables. +How imports should be grouped into use statements. -- -[[rust-analyzer.inlayHints.chainingHints]]rust-analyzer.inlayHints.chainingHints (default: `true`):: +[[rust-analyzer.imports.group.enable]]rust-analyzer.imports.group.enable (default: `true`):: + -- -Whether to show inlay type hints for method chains. +Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-import[following order]. Groups are separated by newlines. -- -[[rust-analyzer.inlayHints.closureReturnTypeHints]]rust-analyzer.inlayHints.closureReturnTypeHints (default: `false`):: +[[rust-analyzer.imports.merge.glob]]rust-analyzer.imports.merge.glob (default: `true`):: + -- -Whether to show inlay type hints for return types of closures with blocks. +Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`. -- -[[rust-analyzer.inlayHints.reborrowHints]]rust-analyzer.inlayHints.reborrowHints (default: `false`):: +[[rust-analyzer.imports.prefix]]rust-analyzer.imports.prefix (default: `"plain"`):: + -- -Whether to show inlay type hints for compiler inserted reborrows. +The path structure for newly inserted paths to use. +-- +[[rust-analyzer.inlayHints.chainingHints.enable]]rust-analyzer.inlayHints.chainingHints.enable (default: `true`):: ++ +-- +Whether to show inlay type hints for method chains. +-- +[[rust-analyzer.inlayHints.closureReturnTypeHints.enable]]rust-analyzer.inlayHints.closureReturnTypeHints.enable (default: `false`):: ++ +-- +Whether to show inlay type hints for return types of closures with blocks. -- [[rust-analyzer.inlayHints.lifetimeElisionHints.enable]]rust-analyzer.inlayHints.lifetimeElisionHints.enable (default: `"never"`):: + @@ -400,10 +354,41 @@ Whether to show inlay type hints for elided lifetimes in function signatures. -- Whether to prefer using parameter names as the name for elided lifetime hints if possible. -- -[[rust-analyzer.inlayHints.hideNamedConstructorHints]]rust-analyzer.inlayHints.hideNamedConstructorHints (default: `false`):: +[[rust-analyzer.inlayHints.maxLength]]rust-analyzer.inlayHints.maxLength (default: `25`):: ++ +-- +Maximum length for inlay hints. Set to null to have an unlimited length. +-- +[[rust-analyzer.inlayHints.parameterHints.enable]]rust-analyzer.inlayHints.parameterHints.enable (default: `true`):: ++ +-- +Whether to show function parameter name inlay hints at the call +site. +-- +[[rust-analyzer.inlayHints.reborrowHints.enable]]rust-analyzer.inlayHints.reborrowHints.enable (default: `false`):: ++ +-- +Whether to show inlay type hints for compiler inserted reborrows. +-- +[[rust-analyzer.inlayHints.renderColons]]rust-analyzer.inlayHints.renderColons (default: `true`):: ++ +-- +Whether to render trailing colons for parameter hints, and trailing colons for parameter hints. +-- +[[rust-analyzer.inlayHints.typeHints.enable]]rust-analyzer.inlayHints.typeHints.enable (default: `true`):: ++ +-- +Whether to show inlay type hints for variables. +-- +[[rust-analyzer.inlayHints.typeHints.hideNamedConstructor]]rust-analyzer.inlayHints.typeHints.hideNamedConstructor (default: `false`):: ++ +-- +Whether to hide inlay type hints for constructors. +-- +[[rust-analyzer.joinLines.joinAssignments]]rust-analyzer.joinLines.joinAssignments (default: `true`):: + -- -Whether to hide inlay hints for constructors. +Join lines merges consecutive declaration and initialization of an assignment. -- [[rust-analyzer.joinLines.joinElseIf]]rust-analyzer.joinLines.joinElseIf (default: `true`):: + @@ -420,12 +405,7 @@ Join lines removes trailing commas. -- Join lines unwraps trivial blocks. -- -[[rust-analyzer.joinLines.joinAssignments]]rust-analyzer.joinLines.joinAssignments (default: `true`):: -+ --- -Join lines merges consecutive declaration and initialization of an assignment. --- -[[rust-analyzer.lens.debug]]rust-analyzer.lens.debug (default: `true`):: +[[rust-analyzer.lens.debug.enable]]rust-analyzer.lens.debug.enable (default: `true`):: + -- Whether to show `Debug` lens. Only applies when @@ -436,41 +416,47 @@ Whether to show `Debug` lens. Only applies when -- Whether to show CodeLens in Rust files. -- -[[rust-analyzer.lens.implementations]]rust-analyzer.lens.implementations (default: `true`):: +[[rust-analyzer.lens.forceCustomCommands]]rust-analyzer.lens.forceCustomCommands (default: `true`):: + -- -Whether to show `Implementations` lens. Only applies when -`#rust-analyzer.lens.enable#` is set. +Internal config: use custom client-side commands even when the +client doesn't set the corresponding capability. -- -[[rust-analyzer.lens.run]]rust-analyzer.lens.run (default: `true`):: +[[rust-analyzer.lens.implementations.enable]]rust-analyzer.lens.implementations.enable (default: `true`):: + -- -Whether to show `Run` lens. Only applies when +Whether to show `Implementations` lens. Only applies when `#rust-analyzer.lens.enable#` is set. -- -[[rust-analyzer.lens.methodReferences]]rust-analyzer.lens.methodReferences (default: `false`):: +[[rust-analyzer.lens.references.adt.enable]]rust-analyzer.lens.references.adt.enable (default: `false`):: + -- -Whether to show `Method References` lens. Only applies when -`#rust-analyzer.lens.enable#` is set. +Whether to show `References` lens for Struct, Enum, and Union. +Only applies when `#rust-analyzer.lens.enable#` is set. -- -[[rust-analyzer.lens.references]]rust-analyzer.lens.references (default: `false`):: +[[rust-analyzer.lens.references.enumVariant.enable]]rust-analyzer.lens.references.enumVariant.enable (default: `false`):: + -- -Whether to show `References` lens for Struct, Enum, Union and Trait. +Whether to show `References` lens for Enum Variants. Only applies when `#rust-analyzer.lens.enable#` is set. -- -[[rust-analyzer.lens.enumVariantReferences]]rust-analyzer.lens.enumVariantReferences (default: `false`):: +[[rust-analyzer.lens.references.method.enable]]rust-analyzer.lens.references.method.enable (default: `false`):: + -- -Whether to show `References` lens for Enum Variants. +Whether to show `Method References` lens. Only applies when +`#rust-analyzer.lens.enable#` is set. +-- +[[rust-analyzer.lens.references.trait.enable]]rust-analyzer.lens.references.trait.enable (default: `false`):: ++ +-- +Whether to show `References` lens for Trait. Only applies when `#rust-analyzer.lens.enable#` is set. -- -[[rust-analyzer.lens.forceCustomCommands]]rust-analyzer.lens.forceCustomCommands (default: `true`):: +[[rust-analyzer.lens.run.enable]]rust-analyzer.lens.run.enable (default: `true`):: + -- -Internal config: use custom client-side commands even when the -client doesn't set the corresponding capability. +Whether to show `Run` lens. Only applies when +`#rust-analyzer.lens.enable#` is set. -- [[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`):: + @@ -481,7 +467,7 @@ of projects. Elements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format. -- -[[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`):: +[[rust-analyzer.lru.capacity]]rust-analyzer.lru.capacity (default: `null`):: + -- Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. @@ -491,21 +477,25 @@ Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. -- Whether to show `can't find Cargo.toml` error message. -- +[[rust-analyzer.primeCaches.enable]]rust-analyzer.primeCaches.enable (default: `true`):: ++ +-- +Warm up caches on project load. +-- [[rust-analyzer.primeCaches.numThreads]]rust-analyzer.primeCaches.numThreads (default: `0`):: + -- How many worker threads to to handle priming caches. The default `0` means to pick automatically. -- -[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `true`):: +[[rust-analyzer.procMacro.attributes.enable]]rust-analyzer.procMacro.attributes.enable (default: `true`):: + -- -Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. +Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set. -- -[[rust-analyzer.procMacro.server]]rust-analyzer.procMacro.server (default: `null`):: +[[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `true`):: + -- -Internal config, path to proc-macro server executable (typically, -this is rust-analyzer itself, but we override this in tests). +Enable support for procedural macros, implies `#rust-analyzer.cargo.buildScripts.enable#`. -- [[rust-analyzer.procMacro.ignored]]rust-analyzer.procMacro.ignored (default: `{}`):: + @@ -514,18 +504,24 @@ These proc-macros will be ignored when trying to expand them. This config takes a map of crate names with the exported proc-macro names to ignore as values. -- -[[rust-analyzer.runnables.overrideCargo]]rust-analyzer.runnables.overrideCargo (default: `null`):: +[[rust-analyzer.procMacro.server]]rust-analyzer.procMacro.server (default: `null`):: ++ +-- +Internal config, path to proc-macro server executable (typically, +this is rust-analyzer itself, but we override this in tests). +-- +[[rust-analyzer.runnables.command]]rust-analyzer.runnables.command (default: `null`):: + -- Command to be executed instead of 'cargo' for runnables. -- -[[rust-analyzer.runnables.cargoExtraArgs]]rust-analyzer.runnables.cargoExtraArgs (default: `[]`):: +[[rust-analyzer.runnables.extraArgs]]rust-analyzer.runnables.extraArgs (default: `[]`):: + -- Additional arguments to be passed to cargo for runnables such as tests or binaries. For example, it may be `--release`. -- -[[rust-analyzer.rustcSource]]rust-analyzer.rustcSource (default: `null`):: +[[rust-analyzer.rustc.source]]rust-analyzer.rustc.source (default: `null`):: + -- Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private @@ -548,17 +544,31 @@ Additional arguments to `rustfmt`. Advanced option, fully override the command rust-analyzer uses for formatting. -- -[[rust-analyzer.rustfmt.enableRangeFormatting]]rust-analyzer.rustfmt.enableRangeFormatting (default: `false`):: +[[rust-analyzer.rustfmt.rangeFormatting.enable]]rust-analyzer.rustfmt.rangeFormatting.enable (default: `false`):: + -- Enables the use of rustfmt's unstable range formatting command for the `textDocument/rangeFormatting` request. The rustfmt option is unstable and only available on a nightly build. -- -[[rust-analyzer.workspace.symbol.search.scope]]rust-analyzer.workspace.symbol.search.scope (default: `"workspace"`):: +[[rust-analyzer.semanticHighlighting.strings.enable]]rust-analyzer.semanticHighlighting.strings.enable (default: `true`):: + -- -Workspace symbol search scope. +Use semantic tokens for strings. + +In some editors (e.g. vscode) semantic tokens override other highlighting grammars. +By disabling semantic tokens for strings, other grammars can be used to highlight +their contents. +-- +[[rust-analyzer.signatureInfo.detail]]rust-analyzer.signatureInfo.detail (default: `"full"`):: ++ +-- +Show full signature of the callable. Only shows parameters if disabled. +-- +[[rust-analyzer.signatureInfo.documentation.enable]]rust-analyzer.signatureInfo.documentation.enable (default: `true`):: ++ +-- +Show documentation. -- [[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`):: + @@ -572,3 +582,8 @@ Limits the number of items returned from a workspace symbol search (Defaults to Some clients like vs-code issue new searches on result filtering and don't require all results to be returned in the initial search. Other clients requires all results upfront and might require a higher limit. -- +[[rust-analyzer.workspace.symbol.search.scope]]rust-analyzer.workspace.symbol.search.scope (default: `"workspace"`):: ++ +-- +Workspace symbol search scope. +-- diff --git a/editors/code/package.json b/editors/code/package.json index cd0ad92d9a51..4931ad963400 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -368,8 +368,8 @@ "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" }, "$generated-start": {}, - "rust-analyzer.assist.exprFillDefault": { - "markdownDescription": "Placeholder for missing expressions in assists.", + "rust-analyzer.assist.expressionFillDefault": { + "markdownDescription": "Placeholder expression to use for missing expressions in assists.", "default": "todo", "type": "string", "enum": [ @@ -381,98 +381,18 @@ "Fill missing expressions with reasonable defaults, `new` or `default` constructors." ] }, - "rust-analyzer.assist.importGranularity": { - "markdownDescription": "How imports should be grouped into use statements.", - "default": "crate", - "type": "string", - "enum": [ - "preserve", - "crate", - "module", - "item" - ], - "enumDescriptions": [ - "Do not change the granularity of any imports and preserve the original structure written by the developer.", - "Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.", - "Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.", - "Flatten imports so that each has its own use statement." - ] - }, - "rust-analyzer.assist.importEnforceGranularity": { - "markdownDescription": "Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.", - "default": false, - "type": "boolean" - }, - "rust-analyzer.assist.importPrefix": { - "markdownDescription": "The path structure for newly inserted paths to use.", - "default": "plain", - "type": "string", - "enum": [ - "plain", - "self", - "crate" - ], - "enumDescriptions": [ - "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.", - "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item. Prefixes `self` in front of the path if it starts with a module.", - "Force import paths to be absolute by always starting them with `crate` or the extern crate name they come from." - ] - }, - "rust-analyzer.assist.importGroup": { - "markdownDescription": "Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.assist.allowMergingIntoGlobImports": { - "markdownDescription": "Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.cache.warmup": { - "markdownDescription": "Warm up caches on project load.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.callInfo.full": { - "markdownDescription": "Show function name and docs in parameter hints.", - "default": true, - "type": "boolean" - }, "rust-analyzer.cargo.autoreload": { "markdownDescription": "Automatically refresh project info via `cargo metadata` on\n`Cargo.toml` changes.", "default": true, "type": "boolean" }, - "rust-analyzer.cargo.allFeatures": { - "markdownDescription": "Activate all available features (`--all-features`).", - "default": false, - "type": "boolean" - }, - "rust-analyzer.cargo.unsetTest": { - "markdownDescription": "Unsets `#[cfg(test)]` for the specified crates.", - "default": [ - "core" - ], - "type": "array", - "items": { - "type": "string" - } - }, - "rust-analyzer.cargo.features": { - "markdownDescription": "List of features to activate.", - "default": [], - "type": "array", - "items": { - "type": "string" - } - }, - "rust-analyzer.cargo.runBuildScripts": { + "rust-analyzer.cargo.buildScripts.enable": { "markdownDescription": "Run build scripts (`build.rs`) for more precise code analysis.", "default": true, "type": "boolean" }, - "rust-analyzer.cargo.runBuildScriptsCommand": { - "markdownDescription": "Advanced option, fully override the command rust-analyzer uses to\nrun build scripts and build procedural macros. The command should\ninclude `--message-format=json` or a similar option.", + "rust-analyzer.cargo.buildScripts.overrideCommand": { + "markdownDescription": "Override the command rust-analyzer uses to run build scripts and\nbuild procedural macros. The command is required to output json\nand should therefor include `--message-format=json` or a similar\noption.\n\nBy default, a cargo invocation will be constructed for the configured\ntargets and features, with the following base command line:\n\n```bash\ncargo check --quiet --workspace --message-format=json --all-targets\n```\n.", "default": null, "type": [ "null", @@ -482,42 +402,56 @@ "type": "string" } }, - "rust-analyzer.cargo.useRustcWrapperForBuildScripts": { + "rust-analyzer.cargo.buildScripts.useRustcWrapper": { "markdownDescription": "Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to\navoid compiling unnecessary things.", "default": true, "type": "boolean" }, + "rust-analyzer.cargo.features": { + "markdownDescription": "List of features to activate.\n\nSet this to `\"all\"` to pass `--all-features` to cargo.", + "default": [], + "type": [ + "string", + "array" + ], + "items": { + "type": "string" + }, + "enum": [ + "all" + ], + "enumDescriptions": [ + "Pass `--all-features` to cargo" + ] + }, "rust-analyzer.cargo.noDefaultFeatures": { - "markdownDescription": "Do not activate the `default` feature.", + "markdownDescription": "Whether to pass `--no-default-features` to cargo.", "default": false, "type": "boolean" }, - "rust-analyzer.cargo.target": { - "markdownDescription": "Compilation target (target triple).", - "default": null, - "type": [ - "null", - "string" - ] - }, "rust-analyzer.cargo.noSysroot": { "markdownDescription": "Internal config for debugging, disables loading of sysroot crates.", "default": false, "type": "boolean" }, - "rust-analyzer.checkOnSave.enable": { - "markdownDescription": "Run specified `cargo check` command for diagnostics on save.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.checkOnSave.allFeatures": { - "markdownDescription": "Check with all features (`--all-features`).\nDefaults to `#rust-analyzer.cargo.allFeatures#`.", + "rust-analyzer.cargo.target": { + "markdownDescription": "Compilation target override (target triple).", "default": null, "type": [ "null", - "boolean" + "string" ] }, + "rust-analyzer.cargo.unsetTest": { + "markdownDescription": "Unsets `#[cfg(test)]` for the specified crates.", + "default": [ + "core" + ], + "type": "array", + "items": { + "type": "string" + } + }, "rust-analyzer.checkOnSave.allTargets": { "markdownDescription": "Check all targets and tests (`--all-targets`).", "default": true, @@ -528,21 +462,10 @@ "default": "check", "type": "string" }, - "rust-analyzer.checkOnSave.noDefaultFeatures": { - "markdownDescription": "Do not activate the `default` feature.", - "default": null, - "type": [ - "null", - "boolean" - ] - }, - "rust-analyzer.checkOnSave.target": { - "markdownDescription": "Check for a specific target. Defaults to\n`#rust-analyzer.cargo.target#`.", - "default": null, - "type": [ - "null", - "string" - ] + "rust-analyzer.checkOnSave.enable": { + "markdownDescription": "Run specified `cargo check` command for diagnostics on save.", + "default": true, + "type": "boolean" }, "rust-analyzer.checkOnSave.extraArgs": { "markdownDescription": "Extra arguments for `cargo check`.", @@ -553,18 +476,33 @@ } }, "rust-analyzer.checkOnSave.features": { - "markdownDescription": "List of features to activate. Defaults to\n`#rust-analyzer.cargo.features#`.", + "markdownDescription": "List of features to activate. Defaults to\n`#rust-analyzer.cargo.features#`.\n\nSet to `\"all\"` to pass `--all-features` to cargo.", "default": null, "type": [ - "null", - "array" + "string", + "array", + "null" ], "items": { "type": "string" - } + }, + "enum": [ + "all" + ], + "enumDescriptions": [ + "Pass `--all-features` to cargo" + ] + }, + "rust-analyzer.checkOnSave.noDefaultFeatures": { + "markdownDescription": "Do not activate the `default` feature.", + "default": null, + "type": [ + "null", + "boolean" + ] }, "rust-analyzer.checkOnSave.overrideCommand": { - "markdownDescription": "Advanced option, fully override the command rust-analyzer uses for\nchecking. The command should include `--message-format=json` or\nsimilar option.", + "markdownDescription": "Override the command rust-analyzer uses to run build scripts and\nbuild procedural macros. The command is required to output json\nand should therefor include `--message-format=json` or a similar\noption.\n\nAn example command would be:\n\n```bash\ncargo check --workspace --message-format=json --all-targets\n```\n.", "default": null, "type": [ "null", @@ -574,17 +512,51 @@ "type": "string" } }, - "rust-analyzer.completion.addCallArgumentSnippets": { - "markdownDescription": "Whether to add argument snippets when completing functions.\nOnly applies when `#rust-analyzer.completion.addCallParenthesis#` is set.", + "rust-analyzer.checkOnSave.target": { + "markdownDescription": "Check for a specific target. Defaults to\n`#rust-analyzer.cargo.target#`.", + "default": null, + "type": [ + "null", + "string" + ] + }, + "rust-analyzer.completion.autoimport.enable": { + "markdownDescription": "Toggles the additional completions that automatically add imports when completed.\nNote that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.completion.autoself.enable": { + "markdownDescription": "Toggles the additional completions that automatically show method calls and field accesses\nwith `self` prefixed to them when inside a method.", "default": true, "type": "boolean" }, - "rust-analyzer.completion.addCallParenthesis": { - "markdownDescription": "Whether to add parenthesis when completing functions.", + "rust-analyzer.completion.callable.snippets": { + "markdownDescription": "Whether to add parenthesis and argument snippets when completing function.", + "default": "fill_arguments", + "type": [ + "string", + "null" + ], + "enum": [ + "fill_arguments", + "add_parentheses" + ], + "enumDescriptions": [ + "Add call parentheses and pre-fill arguments", + "Add call parentheses" + ] + }, + "rust-analyzer.completion.postfix.enable": { + "markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc.", "default": true, "type": "boolean" }, - "rust-analyzer.completion.snippets": { + "rust-analyzer.completion.privateEditable.enable": { + "markdownDescription": "Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.", + "default": false, + "type": "boolean" + }, + "rust-analyzer.completion.snippets.custom": { "markdownDescription": "Custom completion snippets.", "default": { "Arc::new": { @@ -629,45 +601,25 @@ }, "type": "object" }, - "rust-analyzer.completion.postfix.enable": { - "markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.completion.autoimport.enable": { - "markdownDescription": "Toggles the additional completions that automatically add imports when completed.\nNote that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.completion.autoself.enable": { - "markdownDescription": "Toggles the additional completions that automatically show method calls and field accesses\nwith `self` prefixed to them when inside a method.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.completion.privateEditable.enable": { - "markdownDescription": "Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.", - "default": false, - "type": "boolean" + "rust-analyzer.diagnostics.disabled": { + "markdownDescription": "List of rust-analyzer diagnostics to disable.", + "default": [], + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true }, "rust-analyzer.diagnostics.enable": { "markdownDescription": "Whether to show native rust-analyzer diagnostics.", "default": true, "type": "boolean" }, - "rust-analyzer.diagnostics.enableExperimental": { + "rust-analyzer.diagnostics.experimental.enable": { "markdownDescription": "Whether to show experimental rust-analyzer diagnostics that might\nhave more false positives than usual.", "default": false, "type": "boolean" }, - "rust-analyzer.diagnostics.disabled": { - "markdownDescription": "List of rust-analyzer diagnostics to disable.", - "default": [], - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true - }, "rust-analyzer.diagnostics.remapPrefix": { "markdownDescription": "Map of prefixes to be substituted when parsing diagnostic file paths.\nThis should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.", "default": {}, @@ -689,16 +641,6 @@ "type": "string" } }, - "rust-analyzer.experimental.procAttrMacros": { - "markdownDescription": "Expand attribute macros.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.files.watcher": { - "markdownDescription": "Controls file watching implementation.", - "default": "client", - "type": "string" - }, "rust-analyzer.files.excludeDirs": { "markdownDescription": "These directories will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.", "default": [], @@ -707,114 +649,135 @@ "type": "string" } }, - "rust-analyzer.highlightRelated.references": { - "markdownDescription": "Enables highlighting of related references while hovering your mouse above any identifier.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.highlightRelated.exitPoints": { - "markdownDescription": "Enables highlighting of all exit points while hovering your mouse above any `return`, `?`, or return type arrow (`->`).", - "default": true, - "type": "boolean" - }, - "rust-analyzer.highlightRelated.breakPoints": { - "markdownDescription": "Enables highlighting of related references while hovering your mouse `break`, `loop`, `while`, or `for` keywords.", - "default": true, - "type": "boolean" + "rust-analyzer.files.watcher": { + "markdownDescription": "Controls file watching implementation.", + "default": "client", + "type": "string" }, - "rust-analyzer.highlightRelated.yieldPoints": { - "markdownDescription": "Enables highlighting of all break points for a loop or block context while hovering your mouse above any `async` or `await` keywords.", + "rust-analyzer.highlightRelated.breakPoints.enable": { + "markdownDescription": "Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.", "default": true, "type": "boolean" }, - "rust-analyzer.highlighting.strings": { - "markdownDescription": "Use semantic tokens for strings.\n\nIn some editors (e.g. vscode) semantic tokens override other highlighting grammars.\nBy disabling semantic tokens for strings, other grammars can be used to highlight\ntheir contents.", + "rust-analyzer.highlightRelated.exitPoints.enable": { + "markdownDescription": "Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).", "default": true, "type": "boolean" }, - "rust-analyzer.hover.documentation": { - "markdownDescription": "Whether to show documentation on hover.", + "rust-analyzer.highlightRelated.references.enable": { + "markdownDescription": "Enables highlighting of related references while the cursor is on any identifier.", "default": true, "type": "boolean" }, - "rust-analyzer.hover.linksInHover": { - "markdownDescription": "Use markdown syntax for links in hover.", + "rust-analyzer.highlightRelated.yieldPoints.enable": { + "markdownDescription": "Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.", "default": true, "type": "boolean" }, - "rust-analyzer.hoverActions.debug": { + "rust-analyzer.hover.actions.debug.enable": { "markdownDescription": "Whether to show `Debug` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", "default": true, "type": "boolean" }, - "rust-analyzer.hoverActions.enable": { + "rust-analyzer.hover.actions.enable": { "markdownDescription": "Whether to show HoverActions in Rust files.", "default": true, "type": "boolean" }, - "rust-analyzer.hoverActions.gotoTypeDef": { + "rust-analyzer.hover.actions.gotoTypeDef.enable": { "markdownDescription": "Whether to show `Go to Type Definition` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", "default": true, "type": "boolean" }, - "rust-analyzer.hoverActions.implementations": { + "rust-analyzer.hover.actions.implementations.enable": { "markdownDescription": "Whether to show `Implementations` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", "default": true, "type": "boolean" }, - "rust-analyzer.hoverActions.references": { + "rust-analyzer.hover.actions.references.enable": { "markdownDescription": "Whether to show `References` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", "default": false, "type": "boolean" }, - "rust-analyzer.hoverActions.run": { + "rust-analyzer.hover.actions.run.enable": { "markdownDescription": "Whether to show `Run` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", "default": true, "type": "boolean" }, - "rust-analyzer.inlayHints.renderColons": { - "markdownDescription": "Whether to render trailing colons for parameter hints, and trailing colons for parameter hints.", + "rust-analyzer.hover.documentation.enable": { + "markdownDescription": "Whether to show documentation on hover.", "default": true, "type": "boolean" }, - "rust-analyzer.inlayHints.maxLength": { - "markdownDescription": "Maximum length for inlay hints. Set to null to have an unlimited length.", - "default": 25, - "type": [ - "null", - "integer" + "rust-analyzer.hover.links.enable": { + "markdownDescription": "Use markdown syntax for links in hover.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.imports.granularity.enforce": { + "markdownDescription": "Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.", + "default": false, + "type": "boolean" + }, + "rust-analyzer.imports.granularity.group": { + "markdownDescription": "How imports should be grouped into use statements.", + "default": "crate", + "type": "string", + "enum": [ + "preserve", + "crate", + "module", + "item" ], - "minimum": 0 + "enumDescriptions": [ + "Do not change the granularity of any imports and preserve the original structure written by the developer.", + "Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.", + "Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.", + "Flatten imports so that each has its own use statement." + ] }, - "rust-analyzer.inlayHints.parameterHints": { - "markdownDescription": "Whether to show function parameter name inlay hints at the call\nsite.", + "rust-analyzer.imports.group.enable": { + "markdownDescription": "Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines.", "default": true, "type": "boolean" }, - "rust-analyzer.inlayHints.typeHints": { - "markdownDescription": "Whether to show inlay type hints for variables.", + "rust-analyzer.imports.merge.glob": { + "markdownDescription": "Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.", "default": true, "type": "boolean" }, - "rust-analyzer.inlayHints.chainingHints": { + "rust-analyzer.imports.prefix": { + "markdownDescription": "The path structure for newly inserted paths to use.", + "default": "plain", + "type": "string", + "enum": [ + "plain", + "self", + "crate" + ], + "enumDescriptions": [ + "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.", + "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item. Prefixes `self` in front of the path if it starts with a module.", + "Force import paths to be absolute by always starting them with `crate` or the extern crate name they come from." + ] + }, + "rust-analyzer.inlayHints.chainingHints.enable": { "markdownDescription": "Whether to show inlay type hints for method chains.", "default": true, "type": "boolean" }, - "rust-analyzer.inlayHints.closureReturnTypeHints": { + "rust-analyzer.inlayHints.closureReturnTypeHints.enable": { "markdownDescription": "Whether to show inlay type hints for return types of closures with blocks.", "default": false, "type": "boolean" }, - "rust-analyzer.inlayHints.reborrowHints": { - "markdownDescription": "Whether to show inlay type hints for compiler inserted reborrows.", - "default": false, - "type": "boolean" - }, "rust-analyzer.inlayHints.lifetimeElisionHints.enable": { "markdownDescription": "Whether to show inlay type hints for elided lifetimes in function signatures.", "default": "never", - "type": "string", + "type": [ + "string", + "boolean" + ], "enum": [ "always", "never", @@ -831,11 +794,45 @@ "default": false, "type": "boolean" }, - "rust-analyzer.inlayHints.hideNamedConstructorHints": { - "markdownDescription": "Whether to hide inlay hints for constructors.", + "rust-analyzer.inlayHints.maxLength": { + "markdownDescription": "Maximum length for inlay hints. Set to null to have an unlimited length.", + "default": 25, + "type": [ + "null", + "integer" + ], + "minimum": 0 + }, + "rust-analyzer.inlayHints.parameterHints.enable": { + "markdownDescription": "Whether to show function parameter name inlay hints at the call\nsite.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.inlayHints.reborrowHints.enable": { + "markdownDescription": "Whether to show inlay type hints for compiler inserted reborrows.", + "default": false, + "type": "boolean" + }, + "rust-analyzer.inlayHints.renderColons": { + "markdownDescription": "Whether to render trailing colons for parameter hints, and trailing colons for parameter hints.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.inlayHints.typeHints.enable": { + "markdownDescription": "Whether to show inlay type hints for variables.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.inlayHints.typeHints.hideNamedConstructor": { + "markdownDescription": "Whether to hide inlay type hints for constructors.", "default": false, "type": "boolean" }, + "rust-analyzer.joinLines.joinAssignments": { + "markdownDescription": "Join lines merges consecutive declaration and initialization of an assignment.", + "default": true, + "type": "boolean" + }, "rust-analyzer.joinLines.joinElseIf": { "markdownDescription": "Join lines inserts else between consecutive ifs.", "default": true, @@ -851,12 +848,7 @@ "default": true, "type": "boolean" }, - "rust-analyzer.joinLines.joinAssignments": { - "markdownDescription": "Join lines merges consecutive declaration and initialization of an assignment.", - "default": true, - "type": "boolean" - }, - "rust-analyzer.lens.debug": { + "rust-analyzer.lens.debug.enable": { "markdownDescription": "Whether to show `Debug` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", "default": true, "type": "boolean" @@ -866,33 +858,38 @@ "default": true, "type": "boolean" }, - "rust-analyzer.lens.implementations": { - "markdownDescription": "Whether to show `Implementations` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", + "rust-analyzer.lens.forceCustomCommands": { + "markdownDescription": "Internal config: use custom client-side commands even when the\nclient doesn't set the corresponding capability.", "default": true, "type": "boolean" }, - "rust-analyzer.lens.run": { - "markdownDescription": "Whether to show `Run` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", + "rust-analyzer.lens.implementations.enable": { + "markdownDescription": "Whether to show `Implementations` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", "default": true, "type": "boolean" }, - "rust-analyzer.lens.methodReferences": { - "markdownDescription": "Whether to show `Method References` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", + "rust-analyzer.lens.references.adt.enable": { + "markdownDescription": "Whether to show `References` lens for Struct, Enum, and Union.\nOnly applies when `#rust-analyzer.lens.enable#` is set.", "default": false, "type": "boolean" }, - "rust-analyzer.lens.references": { - "markdownDescription": "Whether to show `References` lens for Struct, Enum, Union and Trait.\nOnly applies when `#rust-analyzer.lens.enable#` is set.", + "rust-analyzer.lens.references.enumVariant.enable": { + "markdownDescription": "Whether to show `References` lens for Enum Variants.\nOnly applies when `#rust-analyzer.lens.enable#` is set.", "default": false, "type": "boolean" }, - "rust-analyzer.lens.enumVariantReferences": { - "markdownDescription": "Whether to show `References` lens for Enum Variants.\nOnly applies when `#rust-analyzer.lens.enable#` is set.", + "rust-analyzer.lens.references.method.enable": { + "markdownDescription": "Whether to show `Method References` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", "default": false, "type": "boolean" }, - "rust-analyzer.lens.forceCustomCommands": { - "markdownDescription": "Internal config: use custom client-side commands even when the\nclient doesn't set the corresponding capability.", + "rust-analyzer.lens.references.trait.enable": { + "markdownDescription": "Whether to show `References` lens for Trait.\nOnly applies when `#rust-analyzer.lens.enable#` is set.", + "default": false, + "type": "boolean" + }, + "rust-analyzer.lens.run.enable": { + "markdownDescription": "Whether to show `Run` lens. Only applies when\n`#rust-analyzer.lens.enable#` is set.", "default": true, "type": "boolean" }, @@ -907,7 +904,7 @@ ] } }, - "rust-analyzer.lruCapacity": { + "rust-analyzer.lru.capacity": { "markdownDescription": "Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.", "default": null, "type": [ @@ -921,6 +918,11 @@ "default": true, "type": "boolean" }, + "rust-analyzer.primeCaches.enable": { + "markdownDescription": "Warm up caches on project load.", + "default": true, + "type": "boolean" + }, "rust-analyzer.primeCaches.numThreads": { "markdownDescription": "How many worker threads to to handle priming caches. The default `0` means to pick automatically.", "default": 0, @@ -928,11 +930,21 @@ "minimum": 0, "maximum": 255 }, + "rust-analyzer.procMacro.attributes.enable": { + "markdownDescription": "Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.", + "default": true, + "type": "boolean" + }, "rust-analyzer.procMacro.enable": { - "markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.", + "markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.buildScripts.enable#`.", "default": true, "type": "boolean" }, + "rust-analyzer.procMacro.ignored": { + "markdownDescription": "These proc-macros will be ignored when trying to expand them.\n\nThis config takes a map of crate names with the exported proc-macro names to ignore as values.", + "default": {}, + "type": "object" + }, "rust-analyzer.procMacro.server": { "markdownDescription": "Internal config, path to proc-macro server executable (typically,\nthis is rust-analyzer itself, but we override this in tests).", "default": null, @@ -941,12 +953,7 @@ "string" ] }, - "rust-analyzer.procMacro.ignored": { - "markdownDescription": "These proc-macros will be ignored when trying to expand them.\n\nThis config takes a map of crate names with the exported proc-macro names to ignore as values.", - "default": {}, - "type": "object" - }, - "rust-analyzer.runnables.overrideCargo": { + "rust-analyzer.runnables.command": { "markdownDescription": "Command to be executed instead of 'cargo' for runnables.", "default": null, "type": [ @@ -954,7 +961,7 @@ "string" ] }, - "rust-analyzer.runnables.cargoExtraArgs": { + "rust-analyzer.runnables.extraArgs": { "markdownDescription": "Additional arguments to be passed to cargo for runnables such as\ntests or binaries. For example, it may be `--release`.", "default": [], "type": "array", @@ -962,7 +969,7 @@ "type": "string" } }, - "rust-analyzer.rustcSource": { + "rust-analyzer.rustc.source": { "markdownDescription": "Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private\nprojects, or \"discover\" to try to automatically find it if the `rustc-dev` component\nis installed.\n\nAny project which uses rust-analyzer with the rustcPrivate\ncrates must set `[package.metadata.rust-analyzer] rustc_private=true` to use it.\n\nThis option does not take effect until rust-analyzer is restarted.", "default": null, "type": [ @@ -989,24 +996,34 @@ "type": "string" } }, - "rust-analyzer.rustfmt.enableRangeFormatting": { + "rust-analyzer.rustfmt.rangeFormatting.enable": { "markdownDescription": "Enables the use of rustfmt's unstable range formatting command for the\n`textDocument/rangeFormatting` request. The rustfmt option is unstable and only\navailable on a nightly build.", "default": false, "type": "boolean" }, - "rust-analyzer.workspace.symbol.search.scope": { - "markdownDescription": "Workspace symbol search scope.", - "default": "workspace", + "rust-analyzer.semanticHighlighting.strings.enable": { + "markdownDescription": "Use semantic tokens for strings.\n\nIn some editors (e.g. vscode) semantic tokens override other highlighting grammars.\nBy disabling semantic tokens for strings, other grammars can be used to highlight\ntheir contents.", + "default": true, + "type": "boolean" + }, + "rust-analyzer.signatureInfo.detail": { + "markdownDescription": "Show full signature of the callable. Only shows parameters if disabled.", + "default": "full", "type": "string", "enum": [ - "workspace", - "workspace_and_dependencies" + "full", + "parameters" ], "enumDescriptions": [ - "Search in current workspace only", - "Search in current workspace and dependencies" + "Show the entire signature.", + "Show only the parameters." ] }, + "rust-analyzer.signatureInfo.documentation.enable": { + "markdownDescription": "Show documentation.", + "default": true, + "type": "boolean" + }, "rust-analyzer.workspace.symbol.search.kind": { "markdownDescription": "Workspace symbol search kind.", "default": "only_types", @@ -1026,6 +1043,19 @@ "type": "integer", "minimum": 0 }, + "rust-analyzer.workspace.symbol.search.scope": { + "markdownDescription": "Workspace symbol search scope.", + "default": "workspace", + "type": "string", + "enum": [ + "workspace", + "workspace_and_dependencies" + ], + "enumDescriptions": [ + "Search in current workspace only", + "Search in current workspace and dependencies" + ] + }, "$generated-end": {} } }, diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index f7520f6c4361..99b72635d18e 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -5,6 +5,7 @@ import * as Is from 'vscode-languageclient/lib/common/utils/is'; import { assert } from './util'; import { WorkspaceEdit } from 'vscode'; import { Workspace } from './ctx'; +import { updateConfig } from './config'; export interface Env { [name: string]: string; @@ -24,7 +25,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri return result; } -export function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): lc.LanguageClient { +export async function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): Promise { // '.' Is the fallback if no folder is open // TODO?: Workspace folders support Uri's (eg: file://test.txt). // It might be a good idea to test if the uri points to a file. @@ -45,6 +46,10 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv: ); let initializationOptions = vscode.workspace.getConfiguration("rust-analyzer"); + + // Update outdated user configs + await updateConfig(initializationOptions); + if (workspace.kind === "Detached Files") { initializationOptions = { "detachedFiles": workspace.files.map(file => file.uri.fsPath), ...initializationOptions }; } diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 183521c10c5f..5b650e1420ae 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -18,7 +18,6 @@ export class Config { "cargo", "procMacro", "files", - "highlighting", "lens", // works as lens.* ] .map(opt => `${this.rootSection}.${opt}`); @@ -79,7 +78,7 @@ export class Config { * const nullableNum = vscode * .workspace * .getConfiguration - * .getConfiguration("rust-analyer") + * .getConfiguration("rust-analyzer") * .get(path)!; * * // What happens is that type of `nullableNum` is `number` but not `null | number`: @@ -124,11 +123,11 @@ export class Config { get hoverActions() { return { enable: this.get("hoverActions.enable"), - implementations: this.get("hoverActions.implementations"), - references: this.get("hoverActions.references"), - run: this.get("hoverActions.run"), - debug: this.get("hoverActions.debug"), - gotoTypeDef: this.get("hoverActions.gotoTypeDef"), + implementations: this.get("hoverActions.implementations.enable"), + references: this.get("hoverActions.references.enable"), + run: this.get("hoverActions.run.enable"), + debug: this.get("hoverActions.debug.enable"), + gotoTypeDef: this.get("hoverActions.gotoTypeDef.enable"), }; } @@ -136,3 +135,77 @@ export class Config { return this.package.releaseTag === NIGHTLY_TAG; } } + +export async function updateConfig(config: vscode.WorkspaceConfiguration) { + const renames = [ + ["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", "highlightRelated.breakPoints.enable",], + ["highlightRelated.exitPoints", "highlightRelated.exitPoints.enable",], + ["highlightRelated.yieldPoints", "highlightRelated.yieldPoints.enable",], + ["highlightRelated.references", "highlightRelated.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"] + ]; + + for (const [oldKey, newKey] of renames) { + const inspect = config.inspect(oldKey); + if (inspect !== undefined) { + const valMatrix = [ + { val: inspect.globalValue, langVal: inspect.globalLanguageValue, target: vscode.ConfigurationTarget.Global }, + { val: inspect.workspaceFolderValue, langVal: inspect.workspaceFolderLanguageValue, target: vscode.ConfigurationTarget.WorkspaceFolder }, + { val: inspect.workspaceValue, langVal: inspect.workspaceLanguageValue, target: vscode.ConfigurationTarget.Workspace } + ]; + for (const { val, langVal, target } of valMatrix) { + const pred = (val: unknown) => { + // some of the updates we do only append "enable" or "custom" + // that means on the next run we would find these again, but as objects with + // these properties causing us to destroy the config + // so filter those already updated ones out + return val !== undefined && !(typeof val === "object" && val !== null && (val.hasOwnProperty("enable") || val.hasOwnProperty("custom"))); + }; + if (pred(val)) { + await config.update(newKey, val, target, false); + await config.update(oldKey, undefined, target, false); + } + if (pred(langVal)) { + await config.update(newKey, langVal, target, true); + await config.update(oldKey, undefined, target, true); + } + } + } + } +} diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 666a4b6972bb..0c3e6810e999 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -33,7 +33,7 @@ export class Ctx { serverPath: string, workspace: Workspace, ): Promise { - const client = createClient(serverPath, workspace, config.serverExtraEnv); + const client = await createClient(serverPath, workspace, config.serverExtraEnv); const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); extCtx.subscriptions.push(statusBar);