Move hint settings on the language level
This commit is contained in:
parent
480d8c511b
commit
667b70afde
7 changed files with 196 additions and 145 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{File, Language};
|
||||
use anyhow::Result;
|
||||
use collections::HashMap;
|
||||
use collections::{HashMap, HashSet};
|
||||
use globset::GlobMatcher;
|
||||
use gpui::AppContext;
|
||||
use schemars::{
|
||||
|
@ -52,6 +52,7 @@ pub struct LanguageSettings {
|
|||
pub show_copilot_suggestions: bool,
|
||||
pub show_whitespaces: ShowWhitespaceSetting,
|
||||
pub extend_comment_on_newline: bool,
|
||||
pub inlay_hints: InlayHintSettings,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@ -98,6 +99,8 @@ pub struct LanguageSettingsContent {
|
|||
pub show_whitespaces: Option<ShowWhitespaceSetting>,
|
||||
#[serde(default)]
|
||||
pub extend_comment_on_newline: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub inlay_hints: Option<InlayHintSettings>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
|
@ -150,6 +153,41 @@ pub enum Formatter {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub struct InlayHintSettings {
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub show_type_hints: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub show_parameter_hints: bool,
|
||||
#[serde(default = "default_true")]
|
||||
pub show_other_hints: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl InlayHintSettings {
|
||||
pub fn enabled_inlay_hint_kinds(&self) -> HashSet<Option<InlayHintKind>> {
|
||||
let mut kinds = HashSet::default();
|
||||
if !self.enabled {
|
||||
return kinds;
|
||||
}
|
||||
if self.show_type_hints {
|
||||
kinds.insert(Some(InlayHintKind::Type));
|
||||
}
|
||||
if self.show_parameter_hints {
|
||||
kinds.insert(Some(InlayHintKind::Parameter));
|
||||
}
|
||||
if self.show_other_hints {
|
||||
kinds.insert(None);
|
||||
}
|
||||
kinds
|
||||
}
|
||||
}
|
||||
|
||||
impl AllLanguageSettings {
|
||||
pub fn language<'a>(&'a self, language_name: Option<&str>) -> &'a LanguageSettings {
|
||||
if let Some(name) = language_name {
|
||||
|
@ -184,6 +222,29 @@ impl AllLanguageSettings {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum InlayHintKind {
|
||||
Type,
|
||||
Parameter,
|
||||
}
|
||||
|
||||
impl InlayHintKind {
|
||||
pub fn from_name(name: &str) -> Option<Self> {
|
||||
match name {
|
||||
"type" => Some(InlayHintKind::Type),
|
||||
"parameter" => Some(InlayHintKind::Parameter),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
InlayHintKind::Type => "type",
|
||||
InlayHintKind::Parameter => "parameter",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl settings::Setting for AllLanguageSettings {
|
||||
const KEY: Option<&'static str> = None;
|
||||
|
||||
|
@ -347,6 +408,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
|
|||
&mut settings.extend_comment_on_newline,
|
||||
src.extend_comment_on_newline,
|
||||
);
|
||||
merge(&mut settings.inlay_hints, src.inlay_hints);
|
||||
fn merge<T>(target: &mut T, value: Option<T>) {
|
||||
if let Some(value) = value {
|
||||
*target = value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue