mirror of
https://github.com/TabbyML/tabby
synced 2024-11-22 00:08:06 +00:00
feat(config): add additional language configuration support (#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>
This commit is contained in:
parent
f57068c5c3
commit
64ccce57f4
3
.changes/unreleased/Features-20241008-164720.yaml
Normal file
3
.changes/unreleased/Features-20241008-164720.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
kind: Features
|
||||
body: allow adding additional languages through config.toml
|
||||
time: 2024-10-08T16:47:20.931378+08:00
|
@ -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<languages::Language>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -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<Language>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Language {
|
||||
languages: Vec<String>,
|
||||
exts: Vec<String>,
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user