2019-10-25 09:00:30 +03:00
|
|
|
//! Config used by the language server.
|
|
|
|
//!
|
|
|
|
//! We currently get this config from `initialize` LSP request, which is not the
|
|
|
|
//! best way to do it, but was the simplest thing we could implement.
|
|
|
|
//!
|
|
|
|
//! Of particular interest is the `feature_flags` hash map: while other fields
|
|
|
|
//! configure the server itself, feature flags are passed into analysis, and
|
|
|
|
//! tweak things like automatic insertion of `()` in completions.
|
2019-09-30 11:58:53 +03:00
|
|
|
|
2020-11-10 21:50:05 +01:00
|
|
|
use std::{convert::TryFrom, ffi::OsString, path::PathBuf};
|
2020-04-23 18:50:25 +02:00
|
|
|
|
2020-06-25 09:13:46 +02:00
|
|
|
use flycheck::FlycheckConfig;
|
2020-10-05 17:41:49 +02:00
|
|
|
use hir::PrefixKind;
|
2020-11-24 23:25:13 +02:00
|
|
|
use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig};
|
2020-12-10 17:41:57 +03:00
|
|
|
use ide_db::helpers::insert_use::MergeBehavior;
|
2020-12-02 17:31:24 +03:00
|
|
|
use itertools::Itertools;
|
2020-10-05 19:27:29 +02:00
|
|
|
use lsp_types::{ClientCapabilities, MarkupKind};
|
2020-08-13 12:05:30 +02:00
|
|
|
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
|
2020-08-18 16:03:15 +02:00
|
|
|
use rustc_hash::FxHashSet;
|
2020-12-02 17:31:24 +03:00
|
|
|
use serde::{de::DeserializeOwned, Deserialize};
|
2020-07-08 18:22:57 +02:00
|
|
|
use vfs::AbsPathBuf;
|
2019-03-07 21:06:25 +01:00
|
|
|
|
2020-12-03 00:13:32 +02:00
|
|
|
use crate::{caps::enabled_completions_resolve_capabilities, diagnostics::DiagnosticsMapConfig};
|
2020-07-03 17:19:00 +02:00
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
config_data! {
|
|
|
|
struct ConfigData {
|
|
|
|
/// The strategy to use when inserting new imports or merging imports.
|
2020-12-10 17:41:57 +03:00
|
|
|
assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"",
|
2020-12-02 17:31:24 +03:00
|
|
|
/// The path structure for newly inserted paths to use.
|
|
|
|
assist_importPrefix: ImportPrefixDef = "\"plain\"",
|
|
|
|
|
|
|
|
/// Show function name and docs in parameter hints.
|
|
|
|
callInfo_full: bool = "true",
|
|
|
|
|
|
|
|
/// Automatically refresh project info via `cargo metadata` on
|
2020-12-22 01:15:50 +01:00
|
|
|
/// `Cargo.toml` changes.
|
2020-12-02 17:31:24 +03:00
|
|
|
cargo_autoreload: bool = "true",
|
|
|
|
/// Activate all available features.
|
|
|
|
cargo_allFeatures: bool = "false",
|
|
|
|
/// List of features to activate.
|
|
|
|
cargo_features: Vec<String> = "[]",
|
|
|
|
/// Run `cargo check` on startup to get the correct value for package
|
|
|
|
/// OUT_DIRs.
|
|
|
|
cargo_loadOutDirsFromCheck: bool = "false",
|
|
|
|
/// Do not activate the `default` feature.
|
|
|
|
cargo_noDefaultFeatures: bool = "false",
|
|
|
|
/// Compilation target (target triple).
|
|
|
|
cargo_target: Option<String> = "null",
|
|
|
|
/// Internal config for debugging, disables loading of sysroot crates.
|
|
|
|
cargo_noSysroot: bool = "false",
|
|
|
|
|
|
|
|
/// Run specified `cargo check` command for diagnostics on save.
|
|
|
|
checkOnSave_enable: bool = "true",
|
|
|
|
/// Check with all features (will be passed as `--all-features`).
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Defaults to `#rust-analyzer.cargo.allFeatures#`.
|
2020-12-02 17:31:24 +03:00
|
|
|
checkOnSave_allFeatures: Option<bool> = "null",
|
|
|
|
/// Check all targets and tests (will be passed as `--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<bool> = "null",
|
|
|
|
/// Check for a specific target. Defaults to
|
2020-12-22 01:15:50 +01:00
|
|
|
/// `#rust-analyzer.cargo.target#`.
|
2020-12-02 17:31:24 +03:00
|
|
|
checkOnSave_target: Option<String> = "null",
|
|
|
|
/// Extra arguments for `cargo check`.
|
|
|
|
checkOnSave_extraArgs: Vec<String> = "[]",
|
|
|
|
/// List of features to activate. Defaults to
|
2020-12-22 01:15:50 +01:00
|
|
|
/// `#rust-analyzer.cargo.features#`.
|
2020-12-02 17:31:24 +03:00
|
|
|
checkOnSave_features: Option<Vec<String>> = "null",
|
|
|
|
/// Advanced option, fully override the command rust-analyzer uses for
|
|
|
|
/// checking. The command should include `--message-format=json` or
|
|
|
|
/// similar option.
|
|
|
|
checkOnSave_overrideCommand: Option<Vec<String>> = "null",
|
|
|
|
|
|
|
|
/// Whether to add argument snippets when completing functions.
|
|
|
|
completion_addCallArgumentSnippets: bool = "true",
|
|
|
|
/// Whether to add parenthesis when completing functions.
|
|
|
|
completion_addCallParenthesis: bool = "true",
|
|
|
|
/// 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.
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
|
2020-12-02 17:31:24 +03:00
|
|
|
completion_autoimport_enable: bool = "true",
|
|
|
|
|
|
|
|
/// 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 = "true",
|
|
|
|
/// List of rust-analyzer diagnostics to disable.
|
|
|
|
diagnostics_disabled: FxHashSet<String> = "[]",
|
2020-12-22 01:15:50 +01:00
|
|
|
/// List of warnings that should be displayed with info severity.\n\nThe
|
2020-12-02 17:31:24 +03:00
|
|
|
/// warnings will be indicated by a blue squiggly underline in code and
|
2020-12-22 01:15:50 +01:00
|
|
|
/// a blue icon in the `Problems Panel`.
|
2020-12-02 17:31:24 +03:00
|
|
|
diagnostics_warningsAsHint: Vec<String> = "[]",
|
2020-12-22 01:15:50 +01:00
|
|
|
/// List of warnings that should be displayed with hint severity.\n\nThe
|
2020-12-02 17:31:24 +03:00
|
|
|
/// warnings will be indicated by faded text or three dots in code and
|
2020-12-22 01:15:50 +01:00
|
|
|
/// will not show up in the `Problems Panel`.
|
2020-12-02 17:31:24 +03:00
|
|
|
diagnostics_warningsAsInfo: Vec<String> = "[]",
|
|
|
|
|
|
|
|
/// Controls file watching implementation.
|
|
|
|
files_watcher: String = "\"client\"",
|
|
|
|
|
|
|
|
/// Whether to show `Debug` action. Only applies when
|
|
|
|
/// `#rust-analyzer.hoverActions.enable#` is set.
|
|
|
|
hoverActions_debug: bool = "true",
|
|
|
|
/// Whether to show HoverActions in Rust files.
|
|
|
|
hoverActions_enable: bool = "true",
|
|
|
|
/// Whether to show `Go to Type Definition` action. Only applies when
|
|
|
|
/// `#rust-analyzer.hoverActions.enable#` is set.
|
|
|
|
hoverActions_gotoTypeDef: bool = "true",
|
|
|
|
/// Whether to show `Implementations` action. Only applies when
|
|
|
|
/// `#rust-analyzer.hoverActions.enable#` is set.
|
|
|
|
hoverActions_implementations: bool = "true",
|
|
|
|
/// Whether to show `Run` action. Only applies when
|
|
|
|
/// `#rust-analyzer.hoverActions.enable#` is set.
|
|
|
|
hoverActions_run: bool = "true",
|
|
|
|
/// Use markdown syntax for links in hover.
|
|
|
|
hoverActions_linksInHover: bool = "true",
|
|
|
|
|
|
|
|
/// Whether to show inlay type hints for method chains.
|
|
|
|
inlayHints_chainingHints: bool = "true",
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Maximum length for inlay hints. Default is unlimited.
|
2020-12-02 17:31:24 +03:00
|
|
|
inlayHints_maxLength: Option<usize> = "null",
|
|
|
|
/// 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 `Debug` lens. Only applies when
|
|
|
|
/// `#rust-analyzer.lens.enable#` is set.
|
|
|
|
lens_debug: bool = "true",
|
|
|
|
/// Whether to show CodeLens in Rust files.
|
|
|
|
lens_enable: 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",
|
|
|
|
|
|
|
|
/// Disable project auto-discovery in favor of explicitly specified set
|
2020-12-22 01:15:50 +01:00
|
|
|
/// of projects.\n\nElements must be paths pointing to `Cargo.toml`,
|
|
|
|
/// `rust-project.json`, or JSON objects in `rust-project.json` format.
|
2020-12-02 17:31:24 +03:00
|
|
|
linkedProjects: Vec<ManifestOrProjectJson> = "[]",
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
|
2020-12-02 17:31:24 +03:00
|
|
|
lruCapacity: Option<usize> = "null",
|
|
|
|
/// Whether to show `can't find Cargo.toml` error message.
|
|
|
|
notifications_cargoTomlNotFound: bool = "true",
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Enable Proc macro support, `#rust-analyzer.cargo.loadOutDirsFromCheck#` must be
|
2020-12-02 17:31:24 +03:00
|
|
|
/// enabled.
|
|
|
|
procMacro_enable: bool = "false",
|
|
|
|
|
|
|
|
/// Command to be executed instead of 'cargo' for runnables.
|
|
|
|
runnables_overrideCargo: Option<String> = "null",
|
|
|
|
/// Additional arguments to be passed to cargo for runnables such as
|
2020-12-22 01:15:50 +01:00
|
|
|
/// tests or binaries.\nFor example, it may be `--release`.
|
2020-12-02 17:31:24 +03:00
|
|
|
runnables_cargoExtraArgs: Vec<String> = "[]",
|
|
|
|
|
|
|
|
/// Path to the rust compiler sources, for usage in rustc_private projects.
|
|
|
|
rustcSource : Option<String> = "null",
|
|
|
|
|
2020-12-22 01:15:50 +01:00
|
|
|
/// Additional arguments to `rustfmt`.
|
2020-12-02 17:31:24 +03:00
|
|
|
rustfmt_extraArgs: Vec<String> = "[]",
|
|
|
|
/// Advanced option, fully override the command rust-analyzer uses for
|
|
|
|
/// formatting.
|
|
|
|
rustfmt_overrideCommand: Option<Vec<String>> = "null",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 14:32:04 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Config {
|
2020-04-01 18:46:26 +02:00
|
|
|
pub client_caps: ClientCapsConfig,
|
2020-04-02 11:33:49 +02:00
|
|
|
|
2020-04-01 17:00:37 +02:00
|
|
|
pub publish_diagnostics: bool,
|
2020-06-16 22:26:33 +02:00
|
|
|
pub diagnostics: DiagnosticsConfig,
|
2020-08-18 16:03:15 +02:00
|
|
|
pub diagnostics_map: DiagnosticsMapConfig,
|
2020-04-01 17:22:56 +02:00
|
|
|
pub lru_capacity: Option<usize>,
|
2020-04-23 18:50:25 +02:00
|
|
|
pub proc_macro_srv: Option<(PathBuf, Vec<OsString>)>,
|
2020-04-02 11:55:04 +02:00
|
|
|
pub files: FilesConfig,
|
2020-04-02 11:33:49 +02:00
|
|
|
pub notifications: NotificationsConfig,
|
|
|
|
|
2020-07-10 15:27:34 +02:00
|
|
|
pub cargo_autoreload: bool,
|
2020-04-01 18:51:16 +02:00
|
|
|
pub cargo: CargoConfig,
|
2020-04-02 11:33:49 +02:00
|
|
|
pub rustfmt: RustfmtConfig,
|
2020-06-25 23:44:58 +02:00
|
|
|
pub flycheck: Option<FlycheckConfig>,
|
2020-09-05 12:52:27 +03:00
|
|
|
pub runnables: RunnablesConfig,
|
2020-04-02 11:33:49 +02:00
|
|
|
|
|
|
|
pub inlay_hints: InlayHintsConfig,
|
|
|
|
pub completion: CompletionConfig,
|
2020-05-17 12:09:53 +02:00
|
|
|
pub assist: AssistConfig,
|
2020-04-02 11:33:49 +02:00
|
|
|
pub call_info_full: bool,
|
2020-05-17 19:51:44 +03:00
|
|
|
pub lens: LensConfig,
|
2020-06-03 14:15:54 +03:00
|
|
|
pub hover: HoverConfig,
|
2020-10-23 17:36:22 -04:00
|
|
|
pub semantic_tokens_refresh: bool,
|
2020-12-09 14:36:47 -05:00
|
|
|
pub code_lens_refresh: bool,
|
2020-06-03 12:22:01 +02:00
|
|
|
|
|
|
|
pub linked_projects: Vec<LinkedProject>,
|
2020-06-24 13:34:24 +02:00
|
|
|
pub root_path: AbsPathBuf,
|
2020-08-18 13:35:36 +03:00
|
|
|
}
|
|
|
|
|
2020-07-01 16:42:14 +02:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-06-03 12:22:01 +02:00
|
|
|
pub enum LinkedProject {
|
|
|
|
ProjectManifest(ProjectManifest),
|
2020-06-24 14:57:37 +02:00
|
|
|
InlineJsonProject(ProjectJson),
|
2020-06-03 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ProjectManifest> for LinkedProject {
|
|
|
|
fn from(v: ProjectManifest) -> Self {
|
|
|
|
LinkedProject::ProjectManifest(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 14:57:37 +02:00
|
|
|
impl From<ProjectJson> for LinkedProject {
|
|
|
|
fn from(v: ProjectJson) -> Self {
|
2020-06-09 21:26:42 +02:00
|
|
|
LinkedProject::InlineJsonProject(v)
|
2020-06-03 12:22:01 +02:00
|
|
|
}
|
2020-05-17 19:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub struct LensConfig {
|
|
|
|
pub run: bool,
|
|
|
|
pub debug: bool,
|
2020-07-05 11:19:16 +02:00
|
|
|
pub implementations: bool,
|
2020-09-01 16:33:02 +03:00
|
|
|
pub method_refs: bool,
|
2020-05-17 19:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for LensConfig {
|
|
|
|
fn default() -> Self {
|
2020-09-02 13:25:33 +03:00
|
|
|
Self { run: true, debug: true, implementations: true, method_refs: false }
|
2020-05-17 19:51:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LensConfig {
|
|
|
|
pub fn any(&self) -> bool {
|
2020-09-01 16:33:02 +03:00
|
|
|
self.implementations || self.runnable() || self.references()
|
2020-05-17 19:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn none(&self) -> bool {
|
|
|
|
!self.any()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn runnable(&self) -> bool {
|
|
|
|
self.run || self.debug
|
|
|
|
}
|
2020-09-01 16:33:02 +03:00
|
|
|
|
|
|
|
pub fn references(&self) -> bool {
|
|
|
|
self.method_refs
|
|
|
|
}
|
2020-04-01 14:32:04 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:55:04 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct FilesConfig {
|
2020-04-02 12:47:58 +02:00
|
|
|
pub watcher: FilesWatcher,
|
|
|
|
pub exclude: Vec<String>,
|
2020-04-02 11:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2020-04-02 12:47:58 +02:00
|
|
|
pub enum FilesWatcher {
|
2020-04-02 11:55:04 +02:00
|
|
|
Client,
|
|
|
|
Notify,
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:00:37 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct NotificationsConfig {
|
|
|
|
pub cargo_toml_not_found: bool,
|
|
|
|
}
|
|
|
|
|
2020-04-01 14:32:04 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum RustfmtConfig {
|
2020-07-10 00:28:12 +02:00
|
|
|
Rustfmt { extra_args: Vec<String> },
|
|
|
|
CustomCommand { command: String, args: Vec<String> },
|
2020-04-01 14:32:04 +02:00
|
|
|
}
|
|
|
|
|
2020-09-05 12:52:27 +03:00
|
|
|
/// Configuration for runnable items, such as `main` function or tests.
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct RunnablesConfig {
|
2020-09-05 16:20:33 +03:00
|
|
|
/// Custom command to be executed instead of `cargo` for runnables.
|
|
|
|
pub override_cargo: Option<String>,
|
2020-09-05 12:52:27 +03:00
|
|
|
/// Additional arguments for the `cargo`, e.g. `--release`.
|
|
|
|
pub cargo_extra_args: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2020-04-01 18:46:26 +02:00
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct ClientCapsConfig {
|
|
|
|
pub location_link: bool,
|
|
|
|
pub line_folding_only: bool,
|
2020-04-24 10:08:45 -04:00
|
|
|
pub hierarchical_symbols: bool,
|
2020-04-26 18:54:05 -04:00
|
|
|
pub code_action_literals: bool,
|
2020-05-09 17:15:22 -04:00
|
|
|
pub work_done_progress: bool,
|
2020-05-22 17:29:55 +02:00
|
|
|
pub code_action_group: bool,
|
2020-11-10 18:20:01 +01:00
|
|
|
pub code_action_resolve: bool,
|
2020-06-03 14:15:54 +03:00
|
|
|
pub hover_actions: bool,
|
2020-07-02 12:37:04 +02:00
|
|
|
pub status_notification: bool,
|
2020-07-16 18:41:16 +02:00
|
|
|
pub signature_help_label_offsets: bool,
|
2020-04-01 18:46:26 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 13:34:24 +02:00
|
|
|
impl Config {
|
|
|
|
pub fn new(root_path: AbsPathBuf) -> Self {
|
2020-12-02 17:31:24 +03:00
|
|
|
// Defaults here don't matter, we'll immediately re-write them with
|
|
|
|
// ConfigData.
|
|
|
|
let mut res = Config {
|
2020-04-02 11:33:49 +02:00
|
|
|
client_caps: ClientCapsConfig::default(),
|
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
publish_diagnostics: false,
|
2020-06-16 22:26:33 +02:00
|
|
|
diagnostics: DiagnosticsConfig::default(),
|
2020-08-18 16:03:15 +02:00
|
|
|
diagnostics_map: DiagnosticsMapConfig::default(),
|
2020-04-02 11:33:49 +02:00
|
|
|
lru_capacity: None,
|
|
|
|
proc_macro_srv: None,
|
2020-04-02 11:55:04 +02:00
|
|
|
files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() },
|
2020-12-02 17:31:24 +03:00
|
|
|
notifications: NotificationsConfig { cargo_toml_not_found: false },
|
2020-04-02 11:33:49 +02:00
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
cargo_autoreload: false,
|
2020-04-02 11:33:49 +02:00
|
|
|
cargo: CargoConfig::default(),
|
|
|
|
rustfmt: RustfmtConfig::Rustfmt { extra_args: Vec::new() },
|
2020-06-25 23:44:58 +02:00
|
|
|
flycheck: Some(FlycheckConfig::CargoCommand {
|
2020-12-02 17:31:24 +03:00
|
|
|
command: String::new(),
|
2020-07-21 10:50:24 +02:00
|
|
|
target_triple: None,
|
2020-07-30 16:04:01 +02:00
|
|
|
no_default_features: false,
|
2020-12-02 17:31:24 +03:00
|
|
|
all_targets: false,
|
2020-06-02 12:24:33 +03:00
|
|
|
all_features: false,
|
2020-04-02 11:33:49 +02:00
|
|
|
extra_args: Vec::new(),
|
2020-06-09 21:47:54 +02:00
|
|
|
features: Vec::new(),
|
2020-04-02 11:33:49 +02:00
|
|
|
}),
|
2020-09-05 12:52:27 +03:00
|
|
|
runnables: RunnablesConfig::default(),
|
2020-04-02 11:33:49 +02:00
|
|
|
|
2020-04-01 18:41:43 +02:00
|
|
|
inlay_hints: InlayHintsConfig {
|
2020-12-02 17:31:24 +03:00
|
|
|
type_hints: false,
|
|
|
|
parameter_hints: false,
|
|
|
|
chaining_hints: false,
|
2020-04-01 18:41:43 +02:00
|
|
|
max_length: None,
|
|
|
|
},
|
2020-12-02 17:31:24 +03:00
|
|
|
completion: CompletionConfig::default(),
|
2020-05-17 12:09:53 +02:00
|
|
|
assist: AssistConfig::default(),
|
2020-12-02 17:31:24 +03:00
|
|
|
call_info_full: false,
|
2020-05-17 19:51:44 +03:00
|
|
|
lens: LensConfig::default(),
|
2020-06-03 14:15:54 +03:00
|
|
|
hover: HoverConfig::default(),
|
2020-10-23 17:36:22 -04:00
|
|
|
semantic_tokens_refresh: false,
|
2020-12-09 14:36:47 -05:00
|
|
|
code_lens_refresh: false,
|
2020-06-03 12:22:01 +02:00
|
|
|
linked_projects: Vec::new(),
|
2020-06-24 13:34:24 +02:00
|
|
|
root_path,
|
2020-12-02 17:31:24 +03:00
|
|
|
};
|
|
|
|
res.do_update(serde_json::json!({}));
|
|
|
|
res
|
2020-04-01 17:00:37 +02:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
pub fn update(&mut self, json: serde_json::Value) {
|
2020-12-23 10:47:05 +03:00
|
|
|
log::info!("updating config from JSON: {:#}", json);
|
2020-07-20 18:11:32 -04:00
|
|
|
if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) {
|
2020-07-20 17:25:48 -04:00
|
|
|
return;
|
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
self.do_update(json);
|
2020-12-23 10:47:05 +03:00
|
|
|
log::info!("updated config: {:#?}", self);
|
2020-12-02 17:31:24 +03:00
|
|
|
}
|
|
|
|
fn do_update(&mut self, json: serde_json::Value) {
|
2020-07-10 00:28:12 +02:00
|
|
|
let data = ConfigData::from_json(json);
|
|
|
|
|
|
|
|
self.publish_diagnostics = data.diagnostics_enable;
|
|
|
|
self.diagnostics = DiagnosticsConfig {
|
2020-08-18 16:03:15 +02:00
|
|
|
disable_experimental: !data.diagnostics_enableExperimental,
|
|
|
|
disabled: data.diagnostics_disabled,
|
|
|
|
};
|
|
|
|
self.diagnostics_map = DiagnosticsMapConfig {
|
2020-07-10 00:28:12 +02:00
|
|
|
warnings_as_info: data.diagnostics_warningsAsInfo,
|
|
|
|
warnings_as_hint: data.diagnostics_warningsAsHint,
|
|
|
|
};
|
|
|
|
self.lru_capacity = data.lruCapacity;
|
|
|
|
self.files.watcher = match data.files_watcher.as_str() {
|
|
|
|
"notify" => FilesWatcher::Notify,
|
|
|
|
"client" | _ => FilesWatcher::Client,
|
|
|
|
};
|
|
|
|
self.notifications =
|
|
|
|
NotificationsConfig { cargo_toml_not_found: data.notifications_cargoTomlNotFound };
|
2020-07-10 15:27:34 +02:00
|
|
|
self.cargo_autoreload = data.cargo_autoreload;
|
2020-11-10 21:50:05 +01:00
|
|
|
|
|
|
|
let rustc_source = if let Some(rustc_source) = data.rustcSource {
|
|
|
|
let rustpath: PathBuf = rustc_source.into();
|
|
|
|
AbsPathBuf::try_from(rustpath)
|
|
|
|
.map_err(|_| {
|
|
|
|
log::error!("rustc source directory must be an absolute path");
|
|
|
|
})
|
|
|
|
.ok()
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.cargo = CargoConfig {
|
|
|
|
no_default_features: data.cargo_noDefaultFeatures,
|
|
|
|
all_features: data.cargo_allFeatures,
|
|
|
|
features: data.cargo_features.clone(),
|
|
|
|
load_out_dirs_from_check: data.cargo_loadOutDirsFromCheck,
|
2020-07-21 10:30:54 +02:00
|
|
|
target: data.cargo_target.clone(),
|
2020-11-10 21:50:05 +01:00
|
|
|
rustc_source: rustc_source,
|
2020-11-13 17:38:26 +01:00
|
|
|
no_sysroot: data.cargo_noSysroot,
|
2020-04-04 16:04:49 +03:00
|
|
|
};
|
2020-09-05 12:52:27 +03:00
|
|
|
self.runnables = RunnablesConfig {
|
2020-09-05 16:20:33 +03:00
|
|
|
override_cargo: data.runnables_overrideCargo,
|
2020-09-05 12:52:27 +03:00
|
|
|
cargo_extra_args: data.runnables_cargoExtraArgs,
|
|
|
|
};
|
2020-04-13 00:05:33 +08:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.proc_macro_srv = if data.procMacro_enable {
|
|
|
|
std::env::current_exe().ok().map(|path| (path, vec!["proc-macro".into()]))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
self.rustfmt = match data.rustfmt_overrideCommand {
|
2020-04-06 21:41:31 -07:00
|
|
|
Some(mut args) if !args.is_empty() => {
|
2020-04-02 14:30:28 +02:00
|
|
|
let command = args.remove(0);
|
2020-07-10 00:28:12 +02:00
|
|
|
RustfmtConfig::CustomCommand { command, args }
|
2020-04-06 21:41:31 -07:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
Some(_) | None => RustfmtConfig::Rustfmt { extra_args: data.rustfmt_extraArgs },
|
2020-04-06 21:41:31 -07:00
|
|
|
};
|
2020-04-04 16:04:49 +03:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.flycheck = if data.checkOnSave_enable {
|
|
|
|
let flycheck_config = match data.checkOnSave_overrideCommand {
|
2020-04-06 21:41:31 -07:00
|
|
|
Some(mut args) if !args.is_empty() => {
|
2020-04-02 14:30:28 +02:00
|
|
|
let command = args.remove(0);
|
2020-07-10 00:28:12 +02:00
|
|
|
FlycheckConfig::CustomCommand { command, args }
|
2020-04-06 21:41:31 -07:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
Some(_) | None => FlycheckConfig::CargoCommand {
|
|
|
|
command: data.checkOnSave_command,
|
2020-07-21 10:50:24 +02:00
|
|
|
target_triple: data.checkOnSave_target.or(data.cargo_target),
|
2020-07-10 00:28:12 +02:00
|
|
|
all_targets: data.checkOnSave_allTargets,
|
2020-07-30 16:04:01 +02:00
|
|
|
no_default_features: data
|
|
|
|
.checkOnSave_noDefaultFeatures
|
|
|
|
.unwrap_or(data.cargo_noDefaultFeatures),
|
2020-07-10 00:28:12 +02:00
|
|
|
all_features: data.checkOnSave_allFeatures.unwrap_or(data.cargo_allFeatures),
|
|
|
|
features: data.checkOnSave_features.unwrap_or(data.cargo_features),
|
|
|
|
extra_args: data.checkOnSave_extraArgs,
|
|
|
|
},
|
2020-04-06 21:41:31 -07:00
|
|
|
};
|
2020-07-10 00:28:12 +02:00
|
|
|
Some(flycheck_config)
|
2020-05-18 10:27:00 +03:00
|
|
|
} else {
|
2020-07-10 00:28:12 +02:00
|
|
|
None
|
|
|
|
};
|
2020-02-17 11:44:58 +03:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.inlay_hints = InlayHintsConfig {
|
|
|
|
type_hints: data.inlayHints_typeHints,
|
|
|
|
parameter_hints: data.inlayHints_parameterHints,
|
|
|
|
chaining_hints: data.inlayHints_chainingHints,
|
|
|
|
max_length: data.inlayHints_maxLength,
|
|
|
|
};
|
2020-06-03 14:48:38 +02:00
|
|
|
|
2020-09-12 11:55:01 +02:00
|
|
|
self.assist.insert_use.merge = match data.assist_importMergeBehaviour {
|
2020-12-10 17:41:57 +03:00
|
|
|
MergeBehaviorDef::None => None,
|
|
|
|
MergeBehaviorDef::Full => Some(MergeBehavior::Full),
|
|
|
|
MergeBehaviorDef::Last => Some(MergeBehavior::Last),
|
2020-09-12 11:55:01 +02:00
|
|
|
};
|
2020-10-05 17:41:49 +02:00
|
|
|
self.assist.insert_use.prefix_kind = match data.assist_importPrefix {
|
|
|
|
ImportPrefixDef::Plain => PrefixKind::Plain,
|
|
|
|
ImportPrefixDef::ByCrate => PrefixKind::ByCrate,
|
|
|
|
ImportPrefixDef::BySelf => PrefixKind::BySelf,
|
|
|
|
};
|
2020-09-12 11:55:01 +02:00
|
|
|
|
2020-11-14 23:17:08 +02:00
|
|
|
self.completion.enable_postfix_completions = data.completion_postfix_enable;
|
2020-12-08 14:27:18 +02:00
|
|
|
self.completion.enable_autoimport_completions = data.completion_autoimport_enable;
|
2020-11-14 23:17:08 +02:00
|
|
|
self.completion.add_call_parenthesis = data.completion_addCallParenthesis;
|
|
|
|
self.completion.add_call_argument_snippets = data.completion_addCallArgumentSnippets;
|
|
|
|
self.completion.merge = self.assist.insert_use.merge;
|
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.call_info_full = data.callInfo_full;
|
2020-03-12 22:31:47 +01:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
self.lens = LensConfig {
|
|
|
|
run: data.lens_enable && data.lens_run,
|
|
|
|
debug: data.lens_enable && data.lens_debug,
|
|
|
|
implementations: data.lens_enable && data.lens_implementations,
|
2020-09-01 16:33:02 +03:00
|
|
|
method_refs: data.lens_enable && data.lens_methodReferences,
|
2020-07-10 00:28:12 +02:00
|
|
|
};
|
2019-03-07 21:06:25 +01:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
if !data.linkedProjects.is_empty() {
|
|
|
|
self.linked_projects.clear();
|
|
|
|
for linked_project in data.linkedProjects {
|
|
|
|
let linked_project = match linked_project {
|
|
|
|
ManifestOrProjectJson::Manifest(it) => {
|
|
|
|
let path = self.root_path.join(it);
|
|
|
|
match ProjectManifest::from_manifest_file(path) {
|
|
|
|
Ok(it) => it.into(),
|
2020-09-17 17:37:52 +02:00
|
|
|
Err(e) => {
|
|
|
|
log::error!("failed to load linked project: {}", e);
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ManifestOrProjectJson::ProjectJson(it) => {
|
|
|
|
ProjectJson::new(&self.root_path, it).into()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
self.linked_projects.push(linked_project);
|
2020-04-01 18:41:43 +02:00
|
|
|
}
|
2019-08-06 13:34:28 +02:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
|
|
|
|
self.hover = HoverConfig {
|
|
|
|
implementations: data.hoverActions_enable && data.hoverActions_implementations,
|
|
|
|
run: data.hoverActions_enable && data.hoverActions_run,
|
|
|
|
debug: data.hoverActions_enable && data.hoverActions_debug,
|
|
|
|
goto_type_def: data.hoverActions_enable && data.hoverActions_gotoTypeDef,
|
2020-09-26 13:02:09 +08:00
|
|
|
links_in_hover: data.hoverActions_linksInHover,
|
2020-10-05 19:27:29 +02:00
|
|
|
markdown: true,
|
2020-07-10 00:28:12 +02:00
|
|
|
};
|
2019-03-07 21:06:25 +01:00
|
|
|
}
|
|
|
|
|
2020-05-09 17:15:22 -04:00
|
|
|
pub fn update_caps(&mut self, caps: &ClientCapabilities) {
|
|
|
|
if let Some(doc_caps) = caps.text_document.as_ref() {
|
2020-10-05 19:27:29 +02:00
|
|
|
if let Some(value) = doc_caps.hover.as_ref().and_then(|it| it.content_format.as_ref()) {
|
|
|
|
self.hover.markdown = value.contains(&MarkupKind::Markdown)
|
|
|
|
}
|
2020-05-09 17:15:22 -04:00
|
|
|
if let Some(value) = doc_caps.definition.as_ref().and_then(|it| it.link_support) {
|
2020-05-17 20:38:50 +03:00
|
|
|
self.client_caps.location_link = value;
|
|
|
|
}
|
2020-05-09 17:15:22 -04:00
|
|
|
if let Some(value) = doc_caps.folding_range.as_ref().and_then(|it| it.line_folding_only)
|
|
|
|
{
|
2020-05-17 20:38:50 +03:00
|
|
|
self.client_caps.line_folding_only = value
|
|
|
|
}
|
2020-05-09 17:15:22 -04:00
|
|
|
if let Some(value) = doc_caps
|
|
|
|
.document_symbol
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.hierarchical_document_symbol_support)
|
2020-05-17 20:38:50 +03:00
|
|
|
{
|
|
|
|
self.client_caps.hierarchical_symbols = value
|
|
|
|
}
|
2020-05-22 17:26:31 -04:00
|
|
|
if let Some(value) =
|
|
|
|
doc_caps.code_action.as_ref().map(|it| it.code_action_literal_support.is_some())
|
2020-05-17 20:38:50 +03:00
|
|
|
{
|
|
|
|
self.client_caps.code_action_literals = value;
|
|
|
|
}
|
2020-07-16 18:41:16 +02:00
|
|
|
if let Some(value) = doc_caps
|
|
|
|
.signature_help
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.signature_information.as_ref())
|
|
|
|
.and_then(|it| it.parameter_information.as_ref())
|
|
|
|
.and_then(|it| it.label_offset_support)
|
|
|
|
{
|
|
|
|
self.client_caps.signature_help_label_offsets = value;
|
|
|
|
}
|
2020-05-17 21:24:33 +02:00
|
|
|
|
2020-05-17 20:38:50 +03:00
|
|
|
self.completion.allow_snippets(false);
|
2020-12-03 00:27:26 +02:00
|
|
|
self.completion.active_resolve_capabilities =
|
2020-12-03 00:13:32 +02:00
|
|
|
enabled_completions_resolve_capabilities(caps).unwrap_or_default();
|
2020-05-09 17:15:22 -04:00
|
|
|
if let Some(completion) = &doc_caps.completion {
|
2020-05-17 20:38:50 +03:00
|
|
|
if let Some(completion_item) = &completion.completion_item {
|
|
|
|
if let Some(value) = completion_item.snippet_support {
|
|
|
|
self.completion.allow_snippets(value);
|
|
|
|
}
|
2020-04-24 02:39:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-10 18:20:01 +01:00
|
|
|
|
|
|
|
if let Some(code_action) = &doc_caps.code_action {
|
2020-11-12 17:48:07 -08:00
|
|
|
if let Some(resolve_support) = &code_action.resolve_support {
|
|
|
|
if resolve_support.properties.iter().any(|it| it == "edit") {
|
|
|
|
self.client_caps.code_action_resolve = true;
|
2020-11-10 18:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 02:39:07 +02:00
|
|
|
}
|
2020-05-09 17:15:22 -04:00
|
|
|
|
|
|
|
if let Some(window_caps) = caps.window.as_ref() {
|
|
|
|
if let Some(value) = window_caps.work_done_progress {
|
|
|
|
self.client_caps.work_done_progress = value;
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 21:24:33 +02:00
|
|
|
|
|
|
|
self.assist.allow_snippets(false);
|
|
|
|
if let Some(experimental) = &caps.experimental {
|
2020-06-03 14:44:40 +03:00
|
|
|
let get_bool =
|
|
|
|
|index: &str| experimental.get(index).and_then(|it| it.as_bool()) == Some(true);
|
2020-05-22 17:29:55 +02:00
|
|
|
|
2020-06-03 14:15:54 +03:00
|
|
|
let snippet_text_edit = get_bool("snippetTextEdit");
|
|
|
|
self.assist.allow_snippets(snippet_text_edit);
|
2020-06-02 22:21:48 +02:00
|
|
|
|
2020-06-03 14:15:54 +03:00
|
|
|
self.client_caps.code_action_group = get_bool("codeActionGroup");
|
|
|
|
self.client_caps.hover_actions = get_bool("hoverActions");
|
2020-07-02 12:37:04 +02:00
|
|
|
self.client_caps.status_notification = get_bool("statusNotification");
|
2020-05-17 21:24:33 +02:00
|
|
|
}
|
2020-10-23 17:36:22 -04:00
|
|
|
|
|
|
|
if let Some(workspace_caps) = caps.workspace.as_ref() {
|
|
|
|
if let Some(refresh_support) =
|
|
|
|
workspace_caps.semantic_tokens.as_ref().and_then(|it| it.refresh_support)
|
|
|
|
{
|
|
|
|
self.semantic_tokens_refresh = refresh_support;
|
|
|
|
}
|
2020-12-09 14:36:47 -05:00
|
|
|
|
|
|
|
if let Some(refresh_support) =
|
|
|
|
workspace_caps.code_lens.as_ref().and_then(|it| it.refresh_support)
|
|
|
|
{
|
|
|
|
self.code_lens_refresh = refresh_support;
|
|
|
|
}
|
2020-10-23 17:36:22 -04:00
|
|
|
}
|
2019-03-07 21:06:25 +01:00
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
|
|
|
|
pub fn json_schema() -> serde_json::Value {
|
|
|
|
ConfigData::json_schema()
|
|
|
|
}
|
2019-03-07 21:06:25 +01:00
|
|
|
}
|
2020-06-03 14:48:38 +02:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(untagged)]
|
2020-06-24 15:52:07 +02:00
|
|
|
enum ManifestOrProjectJson {
|
2020-06-03 14:48:38 +02:00
|
|
|
Manifest(PathBuf),
|
2020-06-24 15:52:07 +02:00
|
|
|
ProjectJson(ProjectJsonData),
|
2020-06-03 14:48:38 +02:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
|
2020-09-12 11:55:01 +02:00
|
|
|
#[derive(Deserialize)]
|
2020-10-05 17:41:49 +02:00
|
|
|
#[serde(rename_all = "snake_case")]
|
2020-12-10 17:41:57 +03:00
|
|
|
enum MergeBehaviorDef {
|
2020-09-12 11:55:01 +02:00
|
|
|
None,
|
|
|
|
Full,
|
|
|
|
Last,
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:41:49 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
enum ImportPrefixDef {
|
|
|
|
Plain,
|
|
|
|
BySelf,
|
|
|
|
ByCrate,
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
macro_rules! _config_data {
|
|
|
|
(struct $name:ident {
|
|
|
|
$(
|
|
|
|
$(#[doc=$doc:literal])*
|
|
|
|
$field:ident: $ty:ty = $default:expr,
|
|
|
|
)*
|
|
|
|
}) => {
|
2020-07-10 00:28:12 +02:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct $name { $($field: $ty,)* }
|
|
|
|
impl $name {
|
|
|
|
fn from_json(mut json: serde_json::Value) -> $name {
|
|
|
|
$name {$(
|
2020-12-02 17:31:24 +03:00
|
|
|
$field: get_field(&mut json, stringify!($field), $default),
|
2020-07-10 00:28:12 +02:00
|
|
|
)*}
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
fn json_schema() -> serde_json::Value {
|
|
|
|
schema(&[
|
|
|
|
$({
|
|
|
|
let field = stringify!($field);
|
|
|
|
let ty = stringify!($ty);
|
|
|
|
(field, ty, &[$($doc),*], $default)
|
|
|
|
},)*
|
|
|
|
])
|
|
|
|
}
|
2020-12-09 15:07:37 +03:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn manual() -> String {
|
|
|
|
manual(&[
|
|
|
|
$({
|
|
|
|
let field = stringify!($field);
|
|
|
|
let ty = stringify!($ty);
|
|
|
|
(field, ty, &[$($doc),*], $default)
|
|
|
|
},)*
|
|
|
|
])
|
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
};
|
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
use _config_data as config_data;
|
|
|
|
|
|
|
|
fn get_field<T: DeserializeOwned>(
|
|
|
|
json: &mut serde_json::Value,
|
|
|
|
field: &'static str,
|
|
|
|
default: &str,
|
|
|
|
) -> T {
|
|
|
|
let default = serde_json::from_str(default).unwrap();
|
|
|
|
|
|
|
|
let mut pointer = field.replace('_', "/");
|
|
|
|
pointer.insert(0, '/');
|
|
|
|
json.pointer_mut(&pointer)
|
|
|
|
.and_then(|it| serde_json::from_value(it.take()).ok())
|
|
|
|
.unwrap_or(default)
|
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
|
2020-12-02 17:31:24 +03:00
|
|
|
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
|
|
|
|
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
|
|
|
|
fn key(f: &str) -> &str {
|
|
|
|
f.splitn(2, "_").next().unwrap()
|
2021-01-02 20:48:39 +01:00
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
let map = fields
|
|
|
|
.iter()
|
|
|
|
.map(|(field, ty, doc, default)| {
|
|
|
|
let name = field.replace("_", ".");
|
|
|
|
let name = format!("rust-analyzer.{}", name);
|
|
|
|
let props = field_props(field, ty, doc, default);
|
|
|
|
(name, props)
|
|
|
|
})
|
|
|
|
.collect::<serde_json::Map<_, _>>();
|
|
|
|
map.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value {
|
|
|
|
let doc = doc.iter().map(|it| it.trim()).join(" ");
|
|
|
|
assert!(
|
|
|
|
doc.ends_with('.') && doc.starts_with(char::is_uppercase),
|
|
|
|
"bad docs for {}: {:?}",
|
|
|
|
field,
|
|
|
|
doc
|
|
|
|
);
|
|
|
|
let default = default.parse::<serde_json::Value>().unwrap();
|
|
|
|
|
|
|
|
let mut map = serde_json::Map::default();
|
|
|
|
macro_rules! set {
|
|
|
|
($($key:literal: $value:tt),*$(,)?) => {{$(
|
|
|
|
map.insert($key.into(), serde_json::json!($value));
|
|
|
|
)*}};
|
2020-07-10 00:28:12 +02:00
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
set!("markdownDescription": doc);
|
|
|
|
set!("default": default);
|
|
|
|
|
|
|
|
match ty {
|
|
|
|
"bool" => set!("type": "boolean"),
|
|
|
|
"String" => set!("type": "string"),
|
|
|
|
"Vec<String>" => set! {
|
|
|
|
"type": "array",
|
|
|
|
"items": { "type": "string" },
|
|
|
|
},
|
|
|
|
"FxHashSet<String>" => set! {
|
|
|
|
"type": "array",
|
|
|
|
"items": { "type": "string" },
|
|
|
|
"uniqueItems": true,
|
|
|
|
},
|
|
|
|
"Option<usize>" => set! {
|
|
|
|
"type": ["null", "integer"],
|
|
|
|
"minimum": 0,
|
|
|
|
},
|
|
|
|
"Option<String>" => set! {
|
|
|
|
"type": ["null", "string"],
|
|
|
|
},
|
|
|
|
"Option<bool>" => set! {
|
|
|
|
"type": ["null", "boolean"],
|
|
|
|
},
|
|
|
|
"Option<Vec<String>>" => set! {
|
|
|
|
"type": ["null", "array"],
|
|
|
|
"items": { "type": "string" },
|
|
|
|
},
|
2020-12-10 17:41:57 +03:00
|
|
|
"MergeBehaviorDef" => set! {
|
2020-12-02 17:31:24 +03:00
|
|
|
"type": "string",
|
|
|
|
"enum": ["none", "full", "last"],
|
|
|
|
"enumDescriptions": [
|
|
|
|
"No merging",
|
|
|
|
"Merge all layers of the import trees",
|
|
|
|
"Only merge the last layer of the import trees"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"ImportPrefixDef" => set! {
|
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"plain",
|
|
|
|
"by_self",
|
|
|
|
"by_crate"
|
|
|
|
],
|
|
|
|
"enumDescriptions": [
|
|
|
|
"Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.",
|
2020-12-22 01:15:50 +01:00
|
|
|
"Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name.",
|
2020-12-02 17:31:24 +03:00
|
|
|
"Force import paths to be absolute by always starting them with `crate` or the crate name they refer to."
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"Vec<ManifestOrProjectJson>" => set! {
|
|
|
|
"type": "array",
|
|
|
|
"items": { "type": ["string", "object"] },
|
|
|
|
},
|
|
|
|
_ => panic!("{}: {}", ty, default),
|
|
|
|
}
|
|
|
|
|
|
|
|
map.into()
|
|
|
|
}
|
|
|
|
|
2020-12-09 15:07:37 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
|
|
|
|
fields
|
|
|
|
.iter()
|
|
|
|
.map(|(field, _ty, doc, default)| {
|
2021-01-05 13:09:06 +03:00
|
|
|
let name = format!("rust-analyzer.{}", field.replace("_", "."));
|
|
|
|
format!("[[{}]]{} (default: `{}`)::\n{}\n", name, name, default, doc.join(" "))
|
2020-12-09 15:07:37 +03:00
|
|
|
})
|
|
|
|
.collect::<String>()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
use test_utils::project_dir;
|
|
|
|
|
|
|
|
use super::*;
|
2020-12-02 17:31:24 +03:00
|
|
|
|
2020-12-09 15:07:37 +03:00
|
|
|
#[test]
|
|
|
|
fn schema_in_sync_with_package_json() {
|
|
|
|
let s = Config::json_schema();
|
|
|
|
let schema = format!("{:#}", s);
|
|
|
|
let schema = schema.trim_start_matches('{').trim_end_matches('}');
|
2020-12-02 17:31:24 +03:00
|
|
|
|
2020-12-09 15:07:37 +03:00
|
|
|
let package_json = project_dir().join("editors/code/package.json");
|
|
|
|
let package_json = fs::read_to_string(&package_json).unwrap();
|
|
|
|
|
|
|
|
let p = remove_ws(&package_json);
|
|
|
|
let s = remove_ws(&schema);
|
|
|
|
|
|
|
|
assert!(p.contains(&s), "update config in package.json. New config:\n{:#}", schema);
|
|
|
|
}
|
2020-12-02 17:31:24 +03:00
|
|
|
|
2020-12-09 15:07:37 +03:00
|
|
|
#[test]
|
|
|
|
fn schema_in_sync_with_docs() {
|
|
|
|
let docs_path = project_dir().join("docs/user/generated_config.adoc");
|
|
|
|
let current = fs::read_to_string(&docs_path).unwrap();
|
|
|
|
let expected = ConfigData::manual();
|
2020-12-02 17:31:24 +03:00
|
|
|
|
2020-12-09 15:07:37 +03:00
|
|
|
if remove_ws(¤t) != remove_ws(&expected) {
|
|
|
|
fs::write(&docs_path, expected).unwrap();
|
|
|
|
panic!("updated config manual");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn remove_ws(text: &str) -> String {
|
|
|
|
text.replace(char::is_whitespace, "")
|
|
|
|
}
|
2020-07-10 00:28:12 +02:00
|
|
|
}
|