Auto merge of #11985 - Veykril:config-valid, r=Veykril
minor: Simplify config.rs a bit
This commit is contained in:
commit
5620d25972
@ -380,6 +380,8 @@ pub struct Config {
|
||||
snippets: Vec<Snippet>,
|
||||
}
|
||||
|
||||
type ParallelPrimeCachesNumThreads = u8;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum LinkedProject {
|
||||
ProjectManifest(ProjectManifest),
|
||||
@ -400,9 +402,14 @@ fn from(v: ProjectJson) -> Self {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LensConfig {
|
||||
// runnables
|
||||
pub run: bool,
|
||||
pub debug: bool,
|
||||
|
||||
// implementations
|
||||
pub implementations: bool,
|
||||
|
||||
// references
|
||||
pub method_refs: bool,
|
||||
pub refs: bool, // for Struct, Enum, Union and Trait
|
||||
pub enum_variant_refs: bool,
|
||||
@ -410,7 +417,12 @@ pub struct LensConfig {
|
||||
|
||||
impl LensConfig {
|
||||
pub fn any(&self) -> bool {
|
||||
self.implementations || self.runnable() || self.references()
|
||||
self.run
|
||||
|| self.debug
|
||||
|| self.implementations
|
||||
|| self.method_refs
|
||||
|| self.refs
|
||||
|| self.enum_variant_refs
|
||||
}
|
||||
|
||||
pub fn none(&self) -> bool {
|
||||
@ -623,6 +635,12 @@ macro_rules! try_or {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! try_or_def {
|
||||
($expr:expr) => {
|
||||
try_!($expr).unwrap_or_default()
|
||||
};
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn linked_projects(&self) -> Vec<LinkedProject> {
|
||||
match self.data.linkedProjects.as_slice() {
|
||||
@ -651,14 +669,13 @@ pub fn linked_projects(&self) -> Vec<LinkedProject> {
|
||||
}
|
||||
|
||||
pub fn did_save_text_document_dynamic_registration(&self) -> bool {
|
||||
let caps =
|
||||
try_or!(self.caps.text_document.as_ref()?.synchronization.clone()?, Default::default());
|
||||
let caps = try_or_def!(self.caps.text_document.as_ref()?.synchronization.clone()?);
|
||||
caps.did_save == Some(true) && caps.dynamic_registration == Some(true)
|
||||
}
|
||||
|
||||
pub fn did_change_watched_files_dynamic_registration(&self) -> bool {
|
||||
try_or!(
|
||||
self.caps.workspace.as_ref()?.did_change_watched_files.as_ref()?.dynamic_registration?,
|
||||
false
|
||||
try_or_def!(
|
||||
self.caps.workspace.as_ref()?.did_change_watched_files.as_ref()?.dynamic_registration?
|
||||
)
|
||||
}
|
||||
|
||||
@ -667,22 +684,24 @@ pub fn prefill_caches(&self) -> bool {
|
||||
}
|
||||
|
||||
pub fn location_link(&self) -> bool {
|
||||
try_or!(self.caps.text_document.as_ref()?.definition?.link_support?, false)
|
||||
try_or_def!(self.caps.text_document.as_ref()?.definition?.link_support?)
|
||||
}
|
||||
|
||||
pub fn line_folding_only(&self) -> bool {
|
||||
try_or!(self.caps.text_document.as_ref()?.folding_range.as_ref()?.line_folding_only?, false)
|
||||
try_or_def!(self.caps.text_document.as_ref()?.folding_range.as_ref()?.line_folding_only?)
|
||||
}
|
||||
|
||||
pub fn hierarchical_symbols(&self) -> bool {
|
||||
try_or!(
|
||||
try_or_def!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
.document_symbol
|
||||
.as_ref()?
|
||||
.hierarchical_document_symbol_support?,
|
||||
false
|
||||
.hierarchical_document_symbol_support?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn code_action_literals(&self) -> bool {
|
||||
try_!(self
|
||||
.caps
|
||||
@ -694,12 +713,15 @@ pub fn code_action_literals(&self) -> bool {
|
||||
.as_ref()?)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn work_done_progress(&self) -> bool {
|
||||
try_or!(self.caps.window.as_ref()?.work_done_progress?, false)
|
||||
try_or_def!(self.caps.window.as_ref()?.work_done_progress?)
|
||||
}
|
||||
|
||||
pub fn will_rename(&self) -> bool {
|
||||
try_or!(self.caps.workspace.as_ref()?.file_operations.as_ref()?.will_rename?, false)
|
||||
try_or_def!(self.caps.workspace.as_ref()?.file_operations.as_ref()?.will_rename?)
|
||||
}
|
||||
|
||||
pub fn change_annotation_support(&self) -> bool {
|
||||
try_!(self
|
||||
.caps
|
||||
@ -711,24 +733,24 @@ pub fn change_annotation_support(&self) -> bool {
|
||||
.as_ref()?)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn code_action_resolve(&self) -> bool {
|
||||
try_or!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
.code_action
|
||||
.as_ref()?
|
||||
.resolve_support
|
||||
.as_ref()?
|
||||
.properties
|
||||
.as_slice(),
|
||||
&[]
|
||||
)
|
||||
try_or_def!(self
|
||||
.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
.code_action
|
||||
.as_ref()?
|
||||
.resolve_support
|
||||
.as_ref()?
|
||||
.properties
|
||||
.as_slice())
|
||||
.iter()
|
||||
.any(|it| it == "edit")
|
||||
}
|
||||
|
||||
pub fn signature_help_label_offsets(&self) -> bool {
|
||||
try_or!(
|
||||
try_or_def!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
@ -738,10 +760,10 @@ pub fn signature_help_label_offsets(&self) -> bool {
|
||||
.as_ref()?
|
||||
.parameter_information
|
||||
.as_ref()?
|
||||
.label_offset_support?,
|
||||
false
|
||||
.label_offset_support?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn offset_encoding(&self) -> OffsetEncoding {
|
||||
if supports_utf8(&self.caps) {
|
||||
OffsetEncoding::Utf8
|
||||
@ -751,11 +773,13 @@ pub fn offset_encoding(&self) -> OffsetEncoding {
|
||||
}
|
||||
|
||||
fn experimental(&self, index: &'static str) -> bool {
|
||||
try_or!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?, false)
|
||||
try_or_def!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?)
|
||||
}
|
||||
|
||||
pub fn code_action_group(&self) -> bool {
|
||||
self.experimental("codeActionGroup")
|
||||
}
|
||||
|
||||
pub fn server_status_notification(&self) -> bool {
|
||||
self.experimental("serverStatusNotification")
|
||||
}
|
||||
@ -763,6 +787,7 @@ pub fn server_status_notification(&self) -> bool {
|
||||
pub fn publish_diagnostics(&self) -> bool {
|
||||
self.data.diagnostics_enable
|
||||
}
|
||||
|
||||
pub fn diagnostics(&self) -> DiagnosticsConfig {
|
||||
DiagnosticsConfig {
|
||||
disable_experimental: !self.data.diagnostics_enableExperimental,
|
||||
@ -773,6 +798,7 @@ pub fn diagnostics(&self) -> DiagnosticsConfig {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn diagnostics_map(&self) -> DiagnosticsMapConfig {
|
||||
DiagnosticsMapConfig {
|
||||
remap_prefix: self.data.diagnostics_remapPrefix.clone(),
|
||||
@ -780,9 +806,11 @@ pub fn diagnostics_map(&self) -> DiagnosticsMapConfig {
|
||||
warnings_as_hint: self.data.diagnostics_warningsAsHint.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lru_capacity(&self) -> Option<usize> {
|
||||
self.data.lruCapacity
|
||||
}
|
||||
|
||||
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec<OsString>)> {
|
||||
if !self.data.procMacro_enable {
|
||||
return None;
|
||||
@ -793,12 +821,15 @@ pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec<OsString>)> {
|
||||
};
|
||||
Some((path, vec!["proc-macro".into()]))
|
||||
}
|
||||
|
||||
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {
|
||||
&self.data.procMacro_ignored
|
||||
}
|
||||
|
||||
pub fn expand_proc_attr_macros(&self) -> bool {
|
||||
self.data.experimental_procAttrMacros
|
||||
}
|
||||
|
||||
pub fn files(&self) -> FilesConfig {
|
||||
FilesConfig {
|
||||
watcher: match self.data.files_watcher.as_str() {
|
||||
@ -811,15 +842,19 @@ pub fn files(&self) -> FilesConfig {
|
||||
exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notifications(&self) -> NotificationsConfig {
|
||||
NotificationsConfig { cargo_toml_not_found: self.data.notifications_cargoTomlNotFound }
|
||||
}
|
||||
|
||||
pub fn cargo_autoreload(&self) -> bool {
|
||||
self.data.cargo_autoreload
|
||||
}
|
||||
|
||||
pub fn run_build_scripts(&self) -> bool {
|
||||
self.data.cargo_runBuildScripts || self.data.procMacro_enable
|
||||
}
|
||||
|
||||
pub fn cargo(&self) -> CargoConfig {
|
||||
let rustc_source = self.data.rustcSource.as_ref().map(|rustc_src| {
|
||||
if rustc_src == "discover" {
|
||||
@ -855,6 +890,7 @@ pub fn rustfmt(&self) -> RustfmtConfig {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flycheck(&self) -> Option<FlycheckConfig> {
|
||||
if !self.data.checkOnSave_enable {
|
||||
return None;
|
||||
@ -891,12 +927,14 @@ pub fn flycheck(&self) -> Option<FlycheckConfig> {
|
||||
};
|
||||
Some(flycheck_config)
|
||||
}
|
||||
|
||||
pub fn runnables(&self) -> RunnablesConfig {
|
||||
RunnablesConfig {
|
||||
override_cargo: self.data.runnables_overrideCargo.clone(),
|
||||
cargo_extra_args: self.data.runnables_cargoExtraArgs.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inlay_hints(&self) -> InlayHintsConfig {
|
||||
InlayHintsConfig {
|
||||
render_colons: self.data.inlayHints_renderColons,
|
||||
@ -917,6 +955,7 @@ pub fn inlay_hints(&self) -> InlayHintsConfig {
|
||||
max_length: self.data.inlayHints_maxLength,
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_use_config(&self) -> InsertUseConfig {
|
||||
InsertUseConfig {
|
||||
granularity: match self.data.assist_importGranularity {
|
||||
@ -935,6 +974,7 @@ fn insert_use_config(&self) -> InsertUseConfig {
|
||||
skip_glob_imports: !self.data.assist_allowMergingIntoGlobImports,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn completion(&self) -> CompletionConfig {
|
||||
CompletionConfig {
|
||||
enable_postfix_completions: self.data.completion_postfix_enable,
|
||||
@ -945,7 +985,7 @@ pub fn completion(&self) -> CompletionConfig {
|
||||
add_call_parenthesis: self.data.completion_addCallParenthesis,
|
||||
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
|
||||
insert_use: self.insert_use_config(),
|
||||
snippet_cap: SnippetCap::new(try_or!(
|
||||
snippet_cap: SnippetCap::new(try_or_def!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
@ -953,12 +993,12 @@ pub fn completion(&self) -> CompletionConfig {
|
||||
.as_ref()?
|
||||
.completion_item
|
||||
.as_ref()?
|
||||
.snippet_support?,
|
||||
false
|
||||
.snippet_support?
|
||||
)),
|
||||
snippets: self.snippets.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assist(&self) -> AssistConfig {
|
||||
AssistConfig {
|
||||
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
|
||||
@ -966,6 +1006,7 @@ pub fn assist(&self) -> AssistConfig {
|
||||
insert_use: self.insert_use_config(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join_lines(&self) -> JoinLinesConfig {
|
||||
JoinLinesConfig {
|
||||
join_else_if: self.data.joinLines_joinElseIf,
|
||||
@ -974,9 +1015,11 @@ pub fn join_lines(&self) -> JoinLinesConfig {
|
||||
join_assignments: self.data.joinLines_joinAssignments,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn call_info_full(&self) -> bool {
|
||||
self.data.callInfo_full
|
||||
}
|
||||
|
||||
pub fn lens(&self) -> LensConfig {
|
||||
LensConfig {
|
||||
run: self.data.lens_enable && self.data.lens_run,
|
||||
@ -987,6 +1030,7 @@ pub fn lens(&self) -> LensConfig {
|
||||
enum_variant_refs: self.data.lens_enable && self.data.lens_enumVariantReferences,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hover_actions(&self) -> HoverActionsConfig {
|
||||
let enable = self.experimental("hoverActions") && self.data.hoverActions_enable;
|
||||
HoverActionsConfig {
|
||||
@ -997,24 +1041,24 @@ pub fn hover_actions(&self) -> HoverActionsConfig {
|
||||
goto_type_def: enable && self.data.hoverActions_gotoTypeDef,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn highlighting_strings(&self) -> bool {
|
||||
self.data.highlighting_strings
|
||||
}
|
||||
|
||||
pub fn hover(&self) -> HoverConfig {
|
||||
HoverConfig {
|
||||
links_in_hover: self.data.hover_linksInHover,
|
||||
documentation: self.data.hover_documentation.then(|| {
|
||||
let is_markdown = try_or!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
.hover
|
||||
.as_ref()?
|
||||
.content_format
|
||||
.as_ref()?
|
||||
.as_slice(),
|
||||
&[]
|
||||
)
|
||||
let is_markdown = try_or_def!(self
|
||||
.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
.hover
|
||||
.as_ref()?
|
||||
.content_format
|
||||
.as_ref()?
|
||||
.as_slice())
|
||||
.contains(&MarkupKind::Markdown);
|
||||
if is_markdown {
|
||||
HoverDocFormat::Markdown
|
||||
@ -1042,13 +1086,15 @@ pub fn workspace_symbol(&self) -> WorkspaceSymbolConfig {
|
||||
}
|
||||
|
||||
pub fn semantic_tokens_refresh(&self) -> bool {
|
||||
try_or!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?, false)
|
||||
try_or_def!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?)
|
||||
}
|
||||
|
||||
pub fn code_lens_refresh(&self) -> bool {
|
||||
try_or!(self.caps.workspace.as_ref()?.code_lens.as_ref()?.refresh_support?, false)
|
||||
try_or_def!(self.caps.workspace.as_ref()?.code_lens.as_ref()?.refresh_support?)
|
||||
}
|
||||
|
||||
pub fn insert_replace_support(&self) -> bool {
|
||||
try_or!(
|
||||
try_or_def!(
|
||||
self.caps
|
||||
.text_document
|
||||
.as_ref()?
|
||||
@ -1056,10 +1102,10 @@ pub fn insert_replace_support(&self) -> bool {
|
||||
.as_ref()?
|
||||
.completion_item
|
||||
.as_ref()?
|
||||
.insert_replace_support?,
|
||||
false
|
||||
.insert_replace_support?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn client_commands(&self) -> ClientCommandsConfig {
|
||||
let commands =
|
||||
try_or!(self.caps.experimental.as_ref()?.get("commands")?, &serde_json::Value::Null);
|
||||
@ -1096,6 +1142,8 @@ pub fn prime_caches_num_threads(&self) -> u8 {
|
||||
}
|
||||
}
|
||||
|
||||
// Deserialization definitions
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum SnippetScopeDef {
|
||||
@ -1218,8 +1266,6 @@ enum WorkspaceSymbolSearchKindDef {
|
||||
AllSymbols,
|
||||
}
|
||||
|
||||
type ParallelPrimeCachesNumThreads = u8;
|
||||
|
||||
macro_rules! _config_data {
|
||||
(struct $name:ident {
|
||||
$(
|
||||
|
Loading…
Reference in New Issue
Block a user