Skip to content

Commit b4ec3e1

Browse files
committed
refactor about config
1 parent a0cdd78 commit b4ec3e1

File tree

18 files changed

+327
-77
lines changed

18 files changed

+327
-77
lines changed

Cargo.lock

Lines changed: 172 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ encoding_rs = "0.8"
3232
url = "2.5.2"
3333
smol_str = "0.3.2"
3434
tera = "1.20.0"
35+
serde_with = "3.12.0"

crates/code_analysis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ flagset.workspace = true
2525
encoding_rs.workspace = true
2626
url.workspace = true
2727
smol_str.workspace = true
28+
serde_with.workspace = true
2829

2930
[package.metadata.i18n]
3031
available-locales = ["en", "zh_CN", "zh_HK", "zh_TW"]

crates/code_analysis/src/config/config_loader.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde_json::Value;
44

55
use super::{flatten_config::FlattenConfigObject, Emmyrc};
66

7-
pub fn load_configs(config_files: Vec<PathBuf>) -> Emmyrc {
7+
pub fn load_configs(config_files: Vec<PathBuf>, partial_emmyrcs: Option<Vec<Value>>) -> Emmyrc {
88
let mut config_jsons = Vec::new();
99
for config_file in config_files {
1010
let config_json_str = match std::fs::read_to_string(&config_file) {
@@ -33,6 +33,12 @@ pub fn load_configs(config_files: Vec<PathBuf>) -> Emmyrc {
3333
config_jsons.push(config_json);
3434
}
3535

36+
if let Some(partial_emmyrcs) = partial_emmyrcs {
37+
for partial_emmyrc in partial_emmyrcs {
38+
config_jsons.push(partial_emmyrc);
39+
}
40+
}
41+
3642
if config_jsons.is_empty() {
3743
log::info!("No valid config file found.");
3844
Emmyrc::default()

crates/code_analysis/src/config/configs/completion.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
3+
use serde_with::{serde_as, DefaultOnError};
4+
5+
#[serde_as]
36
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
47
#[serde(rename_all = "camelCase")]
58
/// Configuration for EmmyLua code completion.
@@ -18,6 +21,7 @@ pub struct EmmyrcCompletion {
1821
pub auto_require_naming_convention: EmmyrcFilenameConvention,
1922
/// Whether to use call snippets in completions.
2023
#[serde(default)]
24+
#[serde_as(deserialize_as = "DefaultOnError")]
2125
pub call_snippet: bool,
2226
/// The postfix trigger used in completions.
2327
#[serde(default = "default_postfix")]
@@ -67,4 +71,3 @@ impl Default for EmmyrcFilenameConvention {
6771
EmmyrcFilenameConvention::Keep
6872
}
6973
}
70-

0 commit comments

Comments
 (0)