mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-22 12:34:39 +00:00
feat: make configuration items null-safe (#1988)
When passing configuration items with null values, the default configurations are used. Note: I don't ensure this to be always true, some configuration items may have different non-default behaviors when accepting a null value now or in future. The `deserialize_null_default` is taken from https://github.com/serde-rs/serde/issues/1098. Configuration parsing changes: + some configurations only accepting boolean now coerce null to `false` (default). + some configurations only accepting an object now coerce null to default. + The `tinymist.preview.invertColors` now now coerces null to `"never"` (default).
This commit is contained in:
parent
f33f612f43
commit
fb1c8b3b35
2 changed files with 87 additions and 32 deletions
|
|
@ -70,17 +70,17 @@ type LspCompletion = CompletionItem;
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CompletionFeat {
|
||||
/// Whether to trigger completions on arguments (placeholders) of snippets.
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_null_default")]
|
||||
pub trigger_on_snippet_placeholders: bool,
|
||||
/// Whether supports trigger suggest completion, a.k.a. auto-completion.
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_null_default")]
|
||||
pub trigger_suggest: bool,
|
||||
/// Whether supports trigger parameter hint, a.k.a. signature help.
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_null_default")]
|
||||
pub trigger_parameter_hints: bool,
|
||||
/// Whether supports trigger the command combining suggest and parameter
|
||||
/// hints.
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "deserialize_null_default")]
|
||||
pub trigger_suggest_and_parameter_hints: bool,
|
||||
|
||||
/// The Way to complete symbols.
|
||||
|
|
@ -995,6 +995,17 @@ fn is_arg_like_context(mut matching: &LinkedNode) -> bool {
|
|||
// ctx.completions.push(compl);
|
||||
// }
|
||||
|
||||
fn deserialize_null_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
|
||||
where
|
||||
T: Default + Deserialize<'de>,
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let opt = Option::deserialize(deserializer)?;
|
||||
Ok(opt.unwrap_or_default())
|
||||
}
|
||||
|
||||
// todo: doesn't complete parameter now, which is not good.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::slice_at;
|
||||
|
|
@ -1009,5 +1020,3 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo: doesn't complete parameter now, which is not good.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue