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-11-28 16:30:39 +02:00
|
|
|
use ide_db::helpers::insert_use::MergeBehaviour;
|
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-04-01 18:41:43 +02:00
|
|
|
use serde::Deserialize;
|
2020-07-08 18:22:57 +02:00
|
|
|
use vfs::AbsPathBuf;
|
2019-03-07 21:06:25 +01:00
|
|
|
|
2020-12-01 22:46:06 +02:00
|
|
|
use crate::{caps::enabled_resolve_capabilities, diagnostics::DiagnosticsMapConfig};
|
2020-07-03 17:19:00 +02:00
|
|
|
|
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-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-04-01 18:41:43 +02:00
|
|
|
Config {
|
2020-04-02 11:33:49 +02:00
|
|
|
client_caps: ClientCapsConfig::default(),
|
|
|
|
|
2020-04-01 18:41:43 +02:00
|
|
|
publish_diagnostics: true,
|
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-05-01 18:59:19 -04:00
|
|
|
notifications: NotificationsConfig { cargo_toml_not_found: true },
|
2020-04-02 11:33:49 +02:00
|
|
|
|
2020-07-10 15:27:34 +02:00
|
|
|
cargo_autoreload: true,
|
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-04-02 11:33:49 +02:00
|
|
|
command: "check".to_string(),
|
2020-07-21 10:50:24 +02:00
|
|
|
target_triple: None,
|
2020-07-30 16:04:01 +02:00
|
|
|
no_default_features: false,
|
2020-04-02 11:33:49 +02:00
|
|
|
all_targets: true,
|
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 {
|
|
|
|
type_hints: true,
|
|
|
|
parameter_hints: true,
|
|
|
|
chaining_hints: true,
|
|
|
|
max_length: None,
|
|
|
|
},
|
|
|
|
completion: CompletionConfig {
|
|
|
|
enable_postfix_completions: true,
|
2020-11-25 00:02:45 +02:00
|
|
|
enable_experimental_completions: true,
|
2020-04-01 18:41:43 +02:00
|
|
|
add_call_parenthesis: true,
|
|
|
|
add_call_argument_snippets: true,
|
2020-04-24 02:06:12 +02:00
|
|
|
..CompletionConfig::default()
|
2020-04-01 18:41:43 +02:00
|
|
|
},
|
2020-05-17 12:09:53 +02:00
|
|
|
assist: AssistConfig::default(),
|
2020-04-01 18:41:43 +02:00
|
|
|
call_info_full: true,
|
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-06-03 12:22:01 +02:00
|
|
|
linked_projects: Vec::new(),
|
2020-06-24 13:34:24 +02:00
|
|
|
root_path,
|
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) {
|
|
|
|
log::info!("Config::update({:#})", json);
|
2020-07-20 17:25:48 -04:00
|
|
|
|
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-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 {
|
|
|
|
MergeBehaviourDef::None => None,
|
|
|
|
MergeBehaviourDef::Full => Some(MergeBehaviour::Full),
|
|
|
|
MergeBehaviourDef::Last => Some(MergeBehaviour::Last),
|
|
|
|
};
|
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-11-25 00:02:45 +02:00
|
|
|
self.completion.enable_experimental_completions = data.completion_enableExperimental;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
log::info!("Config::update() = {:#?}", self);
|
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-01 22:46:06 +02:00
|
|
|
self.completion.resolve_capabilities =
|
|
|
|
enabled_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;
|
|
|
|
}
|
|
|
|
}
|
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-09-12 11:55:01 +02:00
|
|
|
enum MergeBehaviourDef {
|
|
|
|
None,
|
|
|
|
Full,
|
|
|
|
Last,
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:41:49 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
enum ImportPrefixDef {
|
|
|
|
Plain,
|
|
|
|
BySelf,
|
|
|
|
ByCrate,
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
macro_rules! config_data {
|
|
|
|
(struct $name:ident { $($field:ident: $ty:ty = $default:expr,)*}) => {
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct $name { $($field: $ty,)* }
|
|
|
|
impl $name {
|
|
|
|
fn from_json(mut json: serde_json::Value) -> $name {
|
|
|
|
$name {$(
|
|
|
|
$field: {
|
|
|
|
let pointer = stringify!($field).replace('_', "/");
|
|
|
|
let pointer = format!("/{}", pointer);
|
|
|
|
json.pointer_mut(&pointer)
|
|
|
|
.and_then(|it| serde_json::from_value(it.take()).ok())
|
|
|
|
.unwrap_or($default)
|
|
|
|
},
|
|
|
|
)*}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
config_data! {
|
|
|
|
struct ConfigData {
|
2020-11-29 16:43:30 +01:00
|
|
|
assist_importMergeBehaviour: MergeBehaviourDef = MergeBehaviourDef::Full,
|
2020-10-05 17:41:49 +02:00
|
|
|
assist_importPrefix: ImportPrefixDef = ImportPrefixDef::Plain,
|
2020-09-12 11:55:01 +02:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
callInfo_full: bool = true,
|
|
|
|
|
2020-07-10 15:27:34 +02:00
|
|
|
cargo_autoreload: bool = true,
|
2020-07-10 00:28:12 +02:00
|
|
|
cargo_allFeatures: bool = false,
|
|
|
|
cargo_features: Vec<String> = Vec::new(),
|
|
|
|
cargo_loadOutDirsFromCheck: bool = false,
|
|
|
|
cargo_noDefaultFeatures: bool = false,
|
|
|
|
cargo_target: Option<String> = None,
|
2020-11-13 17:38:26 +01:00
|
|
|
cargo_noSysroot: bool = false,
|
2020-07-10 00:28:12 +02:00
|
|
|
|
2020-09-02 17:44:21 -04:00
|
|
|
checkOnSave_enable: bool = true,
|
2020-07-10 00:28:12 +02:00
|
|
|
checkOnSave_allFeatures: Option<bool> = None,
|
|
|
|
checkOnSave_allTargets: bool = true,
|
|
|
|
checkOnSave_command: String = "check".into(),
|
2020-07-30 16:04:01 +02:00
|
|
|
checkOnSave_noDefaultFeatures: Option<bool> = None,
|
2020-07-21 10:30:54 +02:00
|
|
|
checkOnSave_target: Option<String> = None,
|
2020-07-10 00:28:12 +02:00
|
|
|
checkOnSave_extraArgs: Vec<String> = Vec::new(),
|
|
|
|
checkOnSave_features: Option<Vec<String>> = None,
|
|
|
|
checkOnSave_overrideCommand: Option<Vec<String>> = None,
|
|
|
|
|
|
|
|
completion_addCallArgumentSnippets: bool = true,
|
|
|
|
completion_addCallParenthesis: bool = true,
|
|
|
|
completion_postfix_enable: bool = true,
|
2020-11-25 00:02:45 +02:00
|
|
|
completion_enableExperimental: bool = true,
|
2020-07-10 00:28:12 +02:00
|
|
|
|
|
|
|
diagnostics_enable: bool = true,
|
2020-07-24 17:39:16 +02:00
|
|
|
diagnostics_enableExperimental: bool = true,
|
2020-08-18 16:03:15 +02:00
|
|
|
diagnostics_disabled: FxHashSet<String> = FxHashSet::default(),
|
2020-07-10 00:28:12 +02:00
|
|
|
diagnostics_warningsAsHint: Vec<String> = Vec::new(),
|
|
|
|
diagnostics_warningsAsInfo: Vec<String> = Vec::new(),
|
|
|
|
|
|
|
|
files_watcher: String = "client".into(),
|
|
|
|
|
|
|
|
hoverActions_debug: bool = true,
|
|
|
|
hoverActions_enable: bool = true,
|
|
|
|
hoverActions_gotoTypeDef: bool = true,
|
|
|
|
hoverActions_implementations: bool = true,
|
|
|
|
hoverActions_run: bool = true,
|
2020-09-26 13:02:09 +08:00
|
|
|
hoverActions_linksInHover: bool = true,
|
2020-07-10 00:28:12 +02:00
|
|
|
|
|
|
|
inlayHints_chainingHints: bool = true,
|
|
|
|
inlayHints_maxLength: Option<usize> = None,
|
|
|
|
inlayHints_parameterHints: bool = true,
|
|
|
|
inlayHints_typeHints: bool = true,
|
|
|
|
|
2020-09-01 16:33:02 +03:00
|
|
|
lens_debug: bool = true,
|
|
|
|
lens_enable: bool = true,
|
|
|
|
lens_implementations: bool = true,
|
|
|
|
lens_run: bool = true,
|
2020-09-02 13:25:33 +03:00
|
|
|
lens_methodReferences: bool = false,
|
2020-07-10 00:28:12 +02:00
|
|
|
|
|
|
|
linkedProjects: Vec<ManifestOrProjectJson> = Vec::new(),
|
|
|
|
lruCapacity: Option<usize> = None,
|
|
|
|
notifications_cargoTomlNotFound: bool = true,
|
|
|
|
procMacro_enable: bool = false,
|
|
|
|
|
2020-09-05 16:20:33 +03:00
|
|
|
runnables_overrideCargo: Option<String> = None,
|
|
|
|
runnables_cargoExtraArgs: Vec<String> = Vec::new(),
|
2020-09-05 12:52:27 +03:00
|
|
|
|
2020-07-10 00:28:12 +02:00
|
|
|
rustfmt_extraArgs: Vec<String> = Vec::new(),
|
|
|
|
rustfmt_overrideCommand: Option<Vec<String>> = None,
|
|
|
|
|
2020-11-10 21:50:05 +01:00
|
|
|
rustcSource : Option<String> = None,
|
2020-07-10 00:28:12 +02:00
|
|
|
}
|
|
|
|
}
|