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:
Meng Zhang 2024-10-10 10:56:18 +08:00 committed by GitHub
parent f57068c5c3
commit 64ccce57f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 6 deletions

View File

@ -0,0 +1,3 @@
kind: Features
body: allow adding additional languages through config.toml
time: 2024-10-08T16:47:20.931378+08:00

View File

@ -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 {

View File

@ -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 {