Skip to content

Commit e112a77

Browse files
committed
support read config file with utf8-bom
1 parent a50c8db commit e112a77

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# 0.7.2 (unreleased)
44

5+
`FIX` Fix reading configuration file encoded with UTF-8 BOM
6+
57
# 0.7.1
68

79
`NEW` Now language server configuration might be provided globally via the `<os-specific home dir>/.emmyrc.json`, `<os-specific config dir>/emmylua_ls/.emmyrc.json`, or by setting a variable `EMMYLUALS_CONFIG` with a path to the json configuration.

crates/emmylua_code_analysis/src/config/config_loader.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ use std::{collections::HashSet, path::PathBuf};
22

33
use serde_json::Value;
44

5+
use crate::read_file_with_encoding;
6+
57
use super::{flatten_config::FlattenConfigObject, Emmyrc};
68

79
pub fn load_configs(config_files: Vec<PathBuf>, partial_emmyrcs: Option<Vec<Value>>) -> Emmyrc {
810
let mut config_jsons = Vec::new();
11+
912
for config_file in config_files {
10-
let config_json_str = match std::fs::read_to_string(&config_file) {
11-
Ok(json_str) => json_str,
12-
Err(e) => {
13+
log::info!("Loading config file: {:?}", config_file);
14+
let config_json_str = match read_file_with_encoding(&config_file, "utf-8") {
15+
Some(json_str) => json_str,
16+
None => {
1317
log::error!(
14-
"Failed to read config file: {:?}, error: {:?}",
15-
config_file,
16-
e
18+
"Failed to read config file: {:?}, error: File not found or unreadable",
19+
config_file
1720
);
1821
continue;
1922
}
2023
};
24+
2125
let config_json: Value = match serde_json::from_str(&config_json_str) {
2226
Ok(json) => json,
2327
Err(e) => {

crates/emmylua_code_analysis/src/diagnostic/checker/unnecessary_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use emmylua_parser::{LuaAstNode, LuaExpr, LuaIfStat};
22

3-
use crate::{DiagnosticCode, LuaType, SemanticModel};
3+
use crate::{DiagnosticCode, SemanticModel};
44

55
use super::{Checker, DiagnosticContext};
66

0 commit comments

Comments
 (0)