diff --git a/.changes/unreleased/Features-20241008-164720.yaml b/.changes/unreleased/Features-20241008-164720.yaml new file mode 100644 index 000000000000..1285a8440e70 --- /dev/null +++ b/.changes/unreleased/Features-20241008-164720.yaml @@ -0,0 +1,3 @@ +kind: Features +body: allow adding additional languages through config.toml +time: 2024-10-08T16:47:20.931378+08:00 diff --git a/crates/tabby-common/src/config.rs b/crates/tabby-common/src/config.rs index 637793790682..22f680fd573b 100644 --- a/crates/tabby-common/src/config.rs +++ b/crates/tabby-common/src/config.rs @@ -9,6 +9,7 @@ use tracing::debug; use crate::{ api::code::CodeSearchParams, + languages, path::repositories_dir, terminal::{HeaderFormat, InfoMessage}, }; @@ -29,6 +30,9 @@ pub struct Config { #[serde(default)] pub answer: AnswerConfig, + + #[serde(default)] + pub additional_languages: Vec, } impl Config { diff --git a/crates/tabby-common/src/languages.rs b/crates/tabby-common/src/languages.rs index 4b3c5e3905a1..874141869367 100644 --- a/crates/tabby-common/src/languages.rs +++ b/crates/tabby-common/src/languages.rs @@ -1,7 +1,9 @@ use std::{collections::HashMap, ffi::OsStr}; use lazy_static::lazy_static; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; + +use crate::config; lazy_static! { static ref DEFAULT: Vec<&'static str> = vec![ @@ -46,12 +48,12 @@ lazy_static! { ]; } -#[derive(Deserialize)] -struct ConfigList { +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +pub struct ConfigList { config: Vec, } -#[derive(Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct Language { languages: Vec, exts: Vec, @@ -88,8 +90,13 @@ impl Language { } lazy_static! { - static ref CONFIG: ConfigList = - serdeconv::from_toml_str(include_str!("../assets/languages.toml")).unwrap(); + static ref CONFIG: ConfigList = { + let mut config_list: ConfigList = + serdeconv::from_toml_str(include_str!("../assets/languages.toml")).unwrap(); + let mut config = config::Config::load().unwrap(); + config_list.config.append(&mut config.additional_languages); + config_list + }; static ref LANGUAGE_CONFIG_MAPPING: HashMap<&'static str, &'static Language> = { let mut map = HashMap::new(); for c in &CONFIG.config {