Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add additional language configuration support #3253

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading