From 811be9e8ef5c9c1f69381ccd0f0e43cdeb058485 Mon Sep 17 00:00:00 2001 From: Liz Date: Sat, 2 Mar 2024 15:52:12 +0000 Subject: [PATCH 1/4] Updates dependenciec & fixed breaking changes --- .cargo/config.toml | 2 ++ Cargo.toml | 10 ++++---- dprint.json | 9 ++++--- src/config.rs | 30 +++++++++++++++++------- src/plugin.rs | 58 ++++++++++++++++++++++++++++------------------ 5 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/Cargo.toml b/Cargo.toml index 5404331..c655782 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,8 @@ lua54 = ["stylua/lua54"] luau = ["stylua/luau"] [dependencies] -anyhow = "1.0.65" -dprint-core = { version = "0.59.0", features = ["wasm"] } -serde = { version = "1.0.145", features = ["derive"] } -serde_json = "1.0.85" -stylua = { version = "0.15.2", features = ["serialize", "fromstr"], default-features = false } +anyhow = "1.0.80" +dprint-core = { version = "0.66.1", features = ["wasm"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.114" +stylua = { version = "0.20.0", features = ["serialize", "fromstr"], default-features = false } diff --git a/dprint.json b/dprint.json index c375a9b..9f171ec 100644 --- a/dprint.json +++ b/dprint.json @@ -16,8 +16,11 @@ "toml": { }, - "rustfmt": { - "max_width": 100 + "exec": { + "commands": [{ + "command": "rustfmt --edition 2021", + "exts": ["rs"] + }] }, "includes": ["**/*"], @@ -26,6 +29,6 @@ "https://plugins.dprint.dev/json-0.15.6.wasm", "https://plugins.dprint.dev/markdown-0.14.1.wasm", "https://plugins.dprint.dev/toml-0.5.4.wasm", - "https://plugins.dprint.dev/rustfmt-0.6.2.json@886c6f3161cf020c2d75160262b0f56d74a521e05cfb91ec4f956650c8ca76ca" + "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7" ] } diff --git a/src/config.rs b/src/config.rs index 2e91629..9a5a878 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,8 @@ use dprint_core::configuration::NewLineKind; use serde::Serialize; -use stylua_lib::{CallParenType, CollapseSimpleStatement, IndentType, QuoteStyle}; +use stylua_lib::{ + CallParenType, CollapseSimpleStatement, IndentType, LineEndings, QuoteStyle, SortRequiresConfig, +}; #[derive(Serialize, Clone)] #[serde(rename_all = "camelCase")] @@ -15,19 +17,29 @@ pub struct Configuration { pub quote_style: QuoteStyle, pub call_parentheses: CallParenType, pub collapse_simple_statement: CollapseSimpleStatement, + pub sort_requires: bool, } impl From<&Configuration> for stylua_lib::Config { fn from(conf: &Configuration) -> Self { - stylua_lib::Config::new() - .with_column_width(conf.line_width as usize) - .with_indent_type(match conf.use_tabs { + stylua_lib::Config { + column_width: conf.line_width as usize, + line_endings: match conf.new_line_kind { + NewLineKind::CarriageReturnLineFeed => LineEndings::Windows, + _ => LineEndings::Unix, + }, + indent_type: match conf.use_tabs { true => IndentType::Tabs, false => IndentType::Spaces, - }) - .with_indent_width(conf.indent_width as usize) - .with_quote_style(conf.quote_style) - .with_call_parentheses(conf.call_parentheses) - .with_collapse_simple_statement(conf.collapse_simple_statement) + }, + indent_width: conf.indent_width as usize, + quote_style: conf.quote_style, + call_parentheses: conf.call_parentheses, + collapse_simple_statement: conf.collapse_simple_statement, + sort_requires: SortRequiresConfig { + enabled: conf.sort_requires, + }, + ..Default::default() + } } } diff --git a/src/plugin.rs b/src/plugin.rs index 53aa6cc..c79202b 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -5,7 +5,7 @@ use dprint_core::{ self, ConfigKeyMap, GlobalConfiguration, ResolveConfigurationResult, RECOMMENDED_GLOBAL_CONFIGURATION, }, - plugins::{FormatResult, PluginInfo, SyncPluginHandler}, + plugins::{FileMatchingInfo, FormatResult, PluginInfo, SyncPluginHandler, SyncPluginInfo}, }; use stylua_lib::{LineEndings, OutputVerification}; @@ -61,19 +61,25 @@ impl SyncPluginHandler for StyluaPluginHandler { quote_style: configuration::get_value( &mut config, "quoteStyle", - default_config.quote_style(), + default_config.quote_style, &mut diagnostics, ), call_parentheses: configuration::get_value( &mut config, "callParentheses", - default_config.call_parentheses(), + default_config.call_parentheses, &mut diagnostics, ), collapse_simple_statement: configuration::get_value( &mut config, "collapseSimpleStatement", - default_config.collapse_simple_statement(), + default_config.collapse_simple_statement, + &mut diagnostics, + ), + sort_requires: configuration::get_value( + &mut config, + "sortRequires", + default_config.sort_requires.enabled, &mut diagnostics, ), }; @@ -86,16 +92,22 @@ impl SyncPluginHandler for StyluaPluginHandler { } } - fn plugin_info(&mut self) -> PluginInfo { - PluginInfo { - name: env!("CARGO_PKG_NAME").to_string(), - version: env!("CARGO_PKG_VERSION").to_string(), - config_key: "stylua".to_string(), - file_extensions: vec!["lua".to_string()], - file_names: vec![], - help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(), - config_schema_url: "".to_string(), - update_url: Some("https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string()), + fn plugin_info(&mut self) -> SyncPluginInfo { + SyncPluginInfo { + info: PluginInfo { + name: env!("CARGO_PKG_NAME").to_string(), + version: env!("CARGO_PKG_VERSION").to_string(), + config_key: "stylua".to_string(), + help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(), + config_schema_url: "".to_string(), + update_url: Some( + "https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string(), + ), + }, + file_matching: FileMatchingInfo { + file_extensions: vec!["lua".to_string()], + file_names: vec![], + }, } } @@ -106,21 +118,23 @@ impl SyncPluginHandler for StyluaPluginHandler { fn format( &mut self, _file_path: &Path, - file_text: &str, + file_text: Vec, config: &Configuration, - _format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> FormatResult, + _format_with_host: impl FnMut(&std::path::Path, Vec, &ConfigKeyMap) -> FormatResult, ) -> FormatResult { - let stylua_config = stylua_lib::Config::from(config).with_line_endings( - match configuration::resolve_new_line_kind(file_text, config.new_line_kind) { + let file_text = String::from_utf8(file_text)?; + + let mut stylua_config = stylua_lib::Config::from(config); + stylua_config.line_endings = + match configuration::resolve_new_line_kind(&file_text, config.new_line_kind) { "\r\n" => LineEndings::Windows, "\n" => LineEndings::Unix, // Fall back to \n in case upstream function changes _ => LineEndings::Unix, - }, - ); + }; let result = stylua_lib::format_code( - file_text, + &file_text, stylua_config, None, match config.verify { @@ -131,7 +145,7 @@ impl SyncPluginHandler for StyluaPluginHandler { if result == file_text { Ok(None) } else { - Ok(Some(result)) + Ok(Some(result.into_bytes())) } } } From f7222c5bb83546b2e3019161e1c6ffaef29a8cc0 Mon Sep 17 00:00:00 2001 From: Liz Date: Sat, 2 Mar 2024 15:57:06 +0000 Subject: [PATCH 2/4] Updated README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25efd08..ff96127 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,9 @@ Don't forget to add `lua` to your `includes` pattern. | newLineKind | NewLineKind | global config or `lf` | `auto`, `lf`, `crlf`, `system` | | verify | bool | `false` | `true`, `false` | | quoteStyle | QuoteStyle | `AutoPreferDouble` | `AutoPreferDouble`, `AutoPreferSingle`, `ForceDouble`, `ForceSingle` | -| callParanetheses | CallParenType | `Always` | `Always`, `NoSingleString`, `NoSingleTable`, `None` | +| callParenetheses | CallParenType | `Always` | `Always`, `NoSingleString`, `NoSingleTable`, `Input`, `None` | | collapseSimpleStatement | CollapseSimpleStatement | `Never` | `Never`, `FunctionOnly`, `ConditionalOnly`, `Always` | +| sortRequires | bool | `false` | `true`, `false` | Also have a look at the [StyLua configuration](https://github.com/JohnnyMorganz/StyLua#options). From 579746946a7f5e45a68ae09e3dbe2a34e57807f0 Mon Sep 17 00:00:00 2001 From: Elizabeth Date: Thu, 7 Nov 2024 16:24:24 +0000 Subject: [PATCH 3/4] Updated dependencies & fixed breaking changes --- .gitignore | 1 - Cargo.lock | 962 ++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 +- src/plugin.rs | 62 ++-- 4 files changed, 998 insertions(+), 35 deletions(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 4fffb2f..ea8c4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /target -/Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..00bc95f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,962 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + +[[package]] +name = "anyhow" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bstr" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +dependencies = [ + "allocator-api2", +] + +[[package]] +name = "bytecount" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap 1.9.3", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.87", +] + +[[package]] +name = "dprint-core" +version = "0.67.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75e378a003bb27a90f39ed9f707735cdd3fc91619cfecd7225cb1c59964b60e5" +dependencies = [ + "anyhow", + "bumpalo", + "hashbrown 0.14.5", + "indexmap 2.6.0", + "rustc-hash", + "serde", + "serde_json", + "unicode-width", +] + +[[package]] +name = "dprint-plugin-stylua" +version = "0.2.1" +dependencies = [ + "anyhow", + "dprint-core", + "serde", + "serde_json", + "stylua", +] + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "full_moon" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ef4f8ad0689d3a86bb483650422d72e6f79a37fdc83ed5426cafe96b776ce1" +dependencies = [ + "bytecount", + "cfg-if", + "derive_more", + "full_moon_derive", + "logos", + "paste", + "serde", + "smol_str", +] + +[[package]] +name = "full_moon_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b4bd12ce56927d1dc5478d21528ea8c4b93ca85ff8f8043b6a5351a2a3c6f7" +dependencies = [ + "indexmap 1.9.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "globset" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax 0.8.5", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "ignore" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.1", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.162" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "logos" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax 0.6.29", + "syn 1.0.109", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.214" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.214" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "serde_json" +version = "1.0.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +dependencies = [ + "indexmap 2.6.0", + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + +[[package]] +name = "similar" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +dependencies = [ + "serde", +] + +[[package]] +name = "smol_str" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" +dependencies = [ + "serde", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.87", +] + +[[package]] +name = "stylua" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9679728211651d9469d595f55917cecf0ace0a615d71f9f3210f1ce1e1d6294a" +dependencies = [ + "anyhow", + "cfg-if", + "clap", + "console", + "crossbeam-channel", + "env_logger", + "full_moon", + "globset", + "ignore", + "lazy_static", + "log", + "num_cpus", + "regex", + "serde", + "serde_json", + "similar", + "strum", + "thiserror", + "threadpool", + "toml", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + +[[package]] +name = "thiserror" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap 2.6.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] diff --git a/Cargo.toml b/Cargo.toml index c655782..9df7072 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,8 @@ lua54 = ["stylua/lua54"] luau = ["stylua/luau"] [dependencies] -anyhow = "1.0.80" -dprint-core = { version = "0.66.1", features = ["wasm"] } -serde = { version = "1.0.197", features = ["derive"] } -serde_json = "1.0.114" +anyhow = "1.0.93" +dprint-core = { version = "0.67.2", features = ["wasm"] } +serde = { version = "1.0.214", features = ["derive"] } +serde_json = "1.0.132" stylua = { version = "0.20.0", features = ["serialize", "fromstr"], default-features = false } diff --git a/src/plugin.rs b/src/plugin.rs index c79202b..741cb12 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,11 +1,10 @@ -use std::path::Path; - use dprint_core::{ - configuration::{ - self, ConfigKeyMap, GlobalConfiguration, ResolveConfigurationResult, - RECOMMENDED_GLOBAL_CONFIGURATION, + configuration::{self, ConfigKeyMap, GlobalConfiguration, RECOMMENDED_GLOBAL_CONFIGURATION}, + generate_plugin_code, + plugins::{ + FileMatchingInfo, FormatResult, PluginInfo, PluginResolveConfigurationResult, + SyncFormatRequest, SyncHostFormatRequest, SyncPluginHandler, }, - plugins::{FileMatchingInfo, FormatResult, PluginInfo, SyncPluginHandler, SyncPluginInfo}, }; use stylua_lib::{LineEndings, OutputVerification}; @@ -18,7 +17,7 @@ impl SyncPluginHandler for StyluaPluginHandler { &mut self, config: ConfigKeyMap, global_config: &GlobalConfiguration, - ) -> ResolveConfigurationResult { + ) -> PluginResolveConfigurationResult { let mut config = config; let mut diagnostics = vec![]; @@ -86,43 +85,39 @@ impl SyncPluginHandler for StyluaPluginHandler { diagnostics.extend(configuration::get_unknown_property_diagnostics(config)); - ResolveConfigurationResult { + PluginResolveConfigurationResult { diagnostics, config: resolved_config, - } - } - - fn plugin_info(&mut self) -> SyncPluginInfo { - SyncPluginInfo { - info: PluginInfo { - name: env!("CARGO_PKG_NAME").to_string(), - version: env!("CARGO_PKG_VERSION").to_string(), - config_key: "stylua".to_string(), - help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(), - config_schema_url: "".to_string(), - update_url: Some( - "https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string(), - ), - }, file_matching: FileMatchingInfo { - file_extensions: vec!["lua".to_string()], + file_extensions: vec!["txt".to_owned()], file_names: vec![], }, } } + fn plugin_info(&mut self) -> PluginInfo { + PluginInfo { + name: env!("CARGO_PKG_NAME").to_string(), + version: env!("CARGO_PKG_VERSION").to_string(), + config_key: "stylua".to_string(), + help_url: concat!(env!("CARGO_PKG_REPOSITORY"), "#readme").to_string(), + config_schema_url: "".to_string(), + update_url: Some("https://plugins.dprint.dev/RubixDev/stylua/latest.json".to_string()), + } + } + fn license_text(&mut self) -> String { include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/LICENSE")).into() } fn format( &mut self, - _file_path: &Path, - file_text: Vec, - config: &Configuration, - _format_with_host: impl FnMut(&std::path::Path, Vec, &ConfigKeyMap) -> FormatResult, + SyncFormatRequest { + file_bytes, config, .. + }: SyncFormatRequest, + _format_with_host: impl FnMut(SyncHostFormatRequest) -> FormatResult, ) -> FormatResult { - let file_text = String::from_utf8(file_text)?; + let file_text = String::from_utf8(file_bytes)?; let mut stylua_config = stylua_lib::Config::from(config); stylua_config.line_endings = @@ -148,7 +143,14 @@ impl SyncPluginHandler for StyluaPluginHandler { Ok(Some(result.into_bytes())) } } + + fn check_config_updates( + &self, + _message: dprint_core::plugins::CheckConfigUpdatesMessage, + ) -> anyhow::Result> { + todo!() + } } #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] -dprint_core::generate_plugin_code!(StyluaPluginHandler, StyluaPluginHandler); +generate_plugin_code!(StyluaPluginHandler, StyluaPluginHandler); From 972034548003a85862e8690674c9b05c043d7993 Mon Sep 17 00:00:00 2001 From: Elizabeth Date: Thu, 7 Nov 2024 16:33:29 +0000 Subject: [PATCH 4/4] fixed extensions --- src/plugin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.rs b/src/plugin.rs index 741cb12..7e6e224 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -89,7 +89,7 @@ impl SyncPluginHandler for StyluaPluginHandler { diagnostics, config: resolved_config, file_matching: FileMatchingInfo { - file_extensions: vec!["txt".to_owned()], + file_extensions: vec!["lua".to_owned()], file_names: vec![], }, }