@@ -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} ;
1010use 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