Skip to content

Commit 811be9e

Browse files
committed
Updates dependenciec & fixed breaking changes
1 parent 017360e commit 811be9e

File tree

5 files changed

+70
-39
lines changed

5 files changed

+70
-39
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-unknown-unknown"

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ lua54 = ["stylua/lua54"]
2222
luau = ["stylua/luau"]
2323

2424
[dependencies]
25-
anyhow = "1.0.65"
26-
dprint-core = { version = "0.59.0", features = ["wasm"] }
27-
serde = { version = "1.0.145", features = ["derive"] }
28-
serde_json = "1.0.85"
29-
stylua = { version = "0.15.2", features = ["serialize", "fromstr"], default-features = false }
25+
anyhow = "1.0.80"
26+
dprint-core = { version = "0.66.1", features = ["wasm"] }
27+
serde = { version = "1.0.197", features = ["derive"] }
28+
serde_json = "1.0.114"
29+
stylua = { version = "0.20.0", features = ["serialize", "fromstr"], default-features = false }

dprint.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
"toml": {
1717
},
1818

19-
"rustfmt": {
20-
"max_width": 100
19+
"exec": {
20+
"commands": [{
21+
"command": "rustfmt --edition 2021",
22+
"exts": ["rs"]
23+
}]
2124
},
2225

2326
"includes": ["**/*"],
@@ -26,6 +29,6 @@
2629
"https://plugins.dprint.dev/json-0.15.6.wasm",
2730
"https://plugins.dprint.dev/markdown-0.14.1.wasm",
2831
"https://plugins.dprint.dev/toml-0.5.4.wasm",
29-
"https://plugins.dprint.dev/rustfmt-0.6.2.json@886c6f3161cf020c2d75160262b0f56d74a521e05cfb91ec4f956650c8ca76ca"
32+
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
3033
]
3134
}

src/config.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use dprint_core::configuration::NewLineKind;
22
use serde::Serialize;
3-
use stylua_lib::{CallParenType, CollapseSimpleStatement, IndentType, QuoteStyle};
3+
use stylua_lib::{
4+
CallParenType, CollapseSimpleStatement, IndentType, LineEndings, QuoteStyle, SortRequiresConfig,
5+
};
46

57
#[derive(Serialize, Clone)]
68
#[serde(rename_all = "camelCase")]
@@ -15,19 +17,29 @@ pub struct Configuration {
1517
pub quote_style: QuoteStyle,
1618
pub call_parentheses: CallParenType,
1719
pub collapse_simple_statement: CollapseSimpleStatement,
20+
pub sort_requires: bool,
1821
}
1922

2023
impl From<&Configuration> for stylua_lib::Config {
2124
fn from(conf: &Configuration) -> Self {
22-
stylua_lib::Config::new()
23-
.with_column_width(conf.line_width as usize)
24-
.with_indent_type(match conf.use_tabs {
25+
stylua_lib::Config {
26+
column_width: conf.line_width as usize,
27+
line_endings: match conf.new_line_kind {
28+
NewLineKind::CarriageReturnLineFeed => LineEndings::Windows,
29+
_ => LineEndings::Unix,
30+
},
31+
indent_type: match conf.use_tabs {
2532
true => IndentType::Tabs,
2633
false => IndentType::Spaces,
27-
})
28-
.with_indent_width(conf.indent_width as usize)
29-
.with_quote_style(conf.quote_style)
30-
.with_call_parentheses(conf.call_parentheses)
31-
.with_collapse_simple_statement(conf.collapse_simple_statement)
34+
},
35+
indent_width: conf.indent_width as usize,
36+
quote_style: conf.quote_style,
37+
call_parentheses: conf.call_parentheses,
38+
collapse_simple_statement: conf.collapse_simple_statement,
39+
sort_requires: SortRequiresConfig {
40+
enabled: conf.sort_requires,
41+
},
42+
..Default::default()
43+
}
3244
}
3345
}

src/plugin.rs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use dprint_core::{
55
self, ConfigKeyMap, GlobalConfiguration, ResolveConfigurationResult,
66
RECOMMENDED_GLOBAL_CONFIGURATION,
77
},
8-
plugins::{FormatResult, PluginInfo, SyncPluginHandler},
8+
plugins::{FileMatchingInfo, FormatResult, PluginInfo, SyncPluginHandler, SyncPluginInfo},
99
};
1010
use stylua_lib::{LineEndings, OutputVerification};
1111

@@ -61,19 +61,25 @@ impl SyncPluginHandler<Configuration> for StyluaPluginHandler {
6161
quote_style: configuration::get_value(
6262
&mut config,
6363
"quoteStyle",
64-
default_config.quote_style(),
64+
default_config.quote_style,
6565
&mut diagnostics,
6666
),
6767
call_parentheses: configuration::get_value(
6868
&mut config,
6969
"callParentheses",
70-
default_config.call_parentheses(),
70+
default_config.call_parentheses,
7171
&mut diagnostics,
7272
),
7373
collapse_simple_statement: configuration::get_value(
7474
&mut config,
7575
"collapseSimpleStatement",
76-
default_config.collapse_simple_statement(),
76+
default_config.collapse_simple_statement,
77+
&mut diagnostics,
78+
),
79+
sort_requires: configuration::get_value(
80+
&mut config,
81+
"sortRequires",
82+
default_config.sort_requires.enabled,
7783
&mut diagnostics,
7884
),
7985
};
@@ -86,16 +92,22 @@ impl SyncPluginHandler<Configuration> for StyluaPluginHandler {
8692
}
8793
}
8894

89-
fn plugin_info(&mut self) -> PluginInfo {
90-
PluginInfo {
91-
name: env!("CARGO_PKG_NAME").to_string(),
92-
version: env!("CARGO_PKG_VERSION").to_string(),
93-
config_key: "stylua".to_string(),
94-
file_extensions: vec!["lua".to_string()],
95-
file_names: vec![],
96-
help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(),
97-
config_schema_url: "".to_string(),
98-
update_url: Some("https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string()),
95+
fn plugin_info(&mut self) -> SyncPluginInfo {
96+
SyncPluginInfo {
97+
info: PluginInfo {
98+
name: env!("CARGO_PKG_NAME").to_string(),
99+
version: env!("CARGO_PKG_VERSION").to_string(),
100+
config_key: "stylua".to_string(),
101+
help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(),
102+
config_schema_url: "".to_string(),
103+
update_url: Some(
104+
"https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string(),
105+
),
106+
},
107+
file_matching: FileMatchingInfo {
108+
file_extensions: vec!["lua".to_string()],
109+
file_names: vec![],
110+
},
99111
}
100112
}
101113

@@ -106,21 +118,23 @@ impl SyncPluginHandler<Configuration> for StyluaPluginHandler {
106118
fn format(
107119
&mut self,
108120
_file_path: &Path,
109-
file_text: &str,
121+
file_text: Vec<u8>,
110122
config: &Configuration,
111-
_format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> FormatResult,
123+
_format_with_host: impl FnMut(&std::path::Path, Vec<u8>, &ConfigKeyMap) -> FormatResult,
112124
) -> FormatResult {
113-
let stylua_config = stylua_lib::Config::from(config).with_line_endings(
114-
match configuration::resolve_new_line_kind(file_text, config.new_line_kind) {
125+
let file_text = String::from_utf8(file_text)?;
126+
127+
let mut stylua_config = stylua_lib::Config::from(config);
128+
stylua_config.line_endings =
129+
match configuration::resolve_new_line_kind(&file_text, config.new_line_kind) {
115130
"\r\n" => LineEndings::Windows,
116131
"\n" => LineEndings::Unix,
117132
// Fall back to \n in case upstream function changes
118133
_ => LineEndings::Unix,
119-
},
120-
);
134+
};
121135

122136
let result = stylua_lib::format_code(
123-
file_text,
137+
&file_text,
124138
stylua_config,
125139
None,
126140
match config.verify {
@@ -131,7 +145,7 @@ impl SyncPluginHandler<Configuration> for StyluaPluginHandler {
131145
if result == file_text {
132146
Ok(None)
133147
} else {
134-
Ok(Some(result))
148+
Ok(Some(result.into_bytes()))
135149
}
136150
}
137151
}

0 commit comments

Comments
 (0)