Skip to content

Commit

Permalink
feat(config): add additional language configuration support (TabbyML#…
Browse files Browse the repository at this point in the history
…3253)

* feat(config): add additional language configuration support

* [autofix.ci] apply automated fixes

* add feature changie

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Oct 10, 2024
1 parent f57068c commit 64ccce5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Features-20241008-164720.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Features
body: allow adding additional languages through config.toml
time: 2024-10-08T16:47:20.931378+08:00
4 changes: 4 additions & 0 deletions crates/tabby-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::debug;

use crate::{
api::code::CodeSearchParams,
languages,
path::repositories_dir,
terminal::{HeaderFormat, InfoMessage},
};
Expand All @@ -29,6 +30,9 @@ pub struct Config {

#[serde(default)]
pub answer: AnswerConfig,

#[serde(default)]
pub additional_languages: Vec<languages::Language>,
}

impl Config {
Expand Down
19 changes: 13 additions & 6 deletions crates/tabby-common/src/languages.rs
Original file line number Diff line number Diff line change
@@ -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![
Expand Down Expand Up @@ -46,12 +48,12 @@ lazy_static! {
];
}

#[derive(Deserialize)]
struct ConfigList {
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct ConfigList {
config: Vec<Language>,
}

#[derive(Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Language {
languages: Vec<String>,
exts: Vec<String>,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 64ccce5

Please sign in to comment.