Skip to content
This repository was archived by the owner on Dec 17, 2022. It is now read-only.

Commit 22860d8

Browse files
committed
feat: Actually upgrade dprint-core.
1 parent 1b09a78 commit 22860d8

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["lib", "cdylib"]
1111
wasm = ["serde_json", "dprint-core/wasm"]
1212

1313
[dependencies]
14-
dprint-core = { version = "0.25.0", features = [] }
14+
dprint-core = { version = "0.26.2", features = [] }
1515
rustfmt-nightly = { version = "=1.4.18" }
1616
serde = { version = "1.0.88", features = ["derive"] }
1717
serde_json = { version = "1.0", optional = true }

src/config.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
use rustfmt_nightly::{Config, NewlineStyle, EmitMode, Edition};
22

3-
use std::collections::HashMap;
43
use serde::{Serialize, Deserialize};
5-
use dprint_core::configuration::{GlobalConfiguration, ResolveConfigurationResult, NewLineKind, ConfigurationDiagnostic};
4+
use dprint_core::configuration::{GlobalConfiguration, ResolveConfigurationResult, NewLineKind, ConfigurationDiagnostic, ConfigKeyMap, ConfigKeyValue};
65

76
#[derive(Clone, Serialize, Deserialize)]
87
pub struct Configuration {
98
// Unfortunately no resolved configuration at the moment because serializing
109
// rustfmt's PartialConfig configuration kept causing a panic
1110
#[serde(flatten)]
12-
pub(crate) config: HashMap<String, String>,
11+
pub(crate) config: ConfigKeyMap,
1312
#[serde(skip_serializing, skip_deserializing)]
1413
pub(crate) rustfmt_config: Config,
1514
}
1615

1716
pub fn resolve_config(
18-
config: HashMap<String, String>,
17+
config: ConfigKeyMap,
1918
global_config: &GlobalConfiguration,
2019
) -> ResolveConfigurationResult<Configuration> {
2120
let mut rustfmt_config = Config::default();
@@ -44,15 +43,23 @@ pub fn resolve_config(
4443

4544
for (key, value) in config.iter() {
4645
if key == "newLineKind" {
47-
match value.as_str() {
48-
"auto" => rustfmt_config.set().newline_style(NewlineStyle::Auto),
49-
"lf" => rustfmt_config.set().newline_style(NewlineStyle::Unix),
50-
"crlf" => rustfmt_config.set().newline_style(NewlineStyle::Windows),
51-
"system" => rustfmt_config.set().newline_style(NewlineStyle::Native),
46+
match value {
47+
ConfigKeyValue::String(value) => match value.as_str() {
48+
"auto" => rustfmt_config.set().newline_style(NewlineStyle::Auto),
49+
"lf" => rustfmt_config.set().newline_style(NewlineStyle::Unix),
50+
"crlf" => rustfmt_config.set().newline_style(NewlineStyle::Windows),
51+
"system" => rustfmt_config.set().newline_style(NewlineStyle::Native),
52+
_ => {
53+
diagnostics.push(ConfigurationDiagnostic {
54+
property_name: String::from(key),
55+
message: format!("Invalid newline kind: {}", value),
56+
});
57+
}
58+
},
5259
_ => {
5360
diagnostics.push(ConfigurationDiagnostic {
5461
property_name: String::from(key),
55-
message: format!("Invalid newline kind: {}", value),
62+
message: String::from("Newline kind must be a string."),
5663
});
5764
}
5865
}
@@ -65,8 +72,9 @@ pub fn resolve_config(
6572
"indentWidth" => "tab_spaces",
6673
_ => key,
6774
};
68-
if Config::is_valid_key_val(key, value) {
69-
rustfmt_config.override_value(key, value);
75+
let value = key_value_to_string(value);
76+
if Config::is_valid_key_val(key, &value) {
77+
rustfmt_config.override_value(key, &value);
7078
} else {
7179
let message = format!("Invalid key or value in configuration. Key: {}, Value: {}", key, value);
7280
diagnostics.push(ConfigurationDiagnostic {
@@ -83,3 +91,11 @@ pub fn resolve_config(
8391
config: Configuration { config, rustfmt_config },
8492
}
8593
}
94+
95+
fn key_value_to_string(value: &ConfigKeyValue) -> String {
96+
match value {
97+
ConfigKeyValue::String(value) => value.clone(),
98+
ConfigKeyValue::Number(value) => value.to_string(),
99+
ConfigKeyValue::Bool(value) => value.to_string(),
100+
}
101+
}

0 commit comments

Comments
 (0)