7
7
compile_error ! ( "Feature preview-engine and preview-builtin need to be enabled together when building native LSP" ) ;
8
8
9
9
mod common;
10
+ mod fmt;
10
11
mod language;
11
12
pub mod lsp_ext;
12
13
#[ cfg( feature = "preview-engine" ) ]
@@ -22,7 +23,7 @@ use lsp_types::notification::{
22
23
} ;
23
24
use lsp_types:: { DidChangeTextDocumentParams , DidOpenTextDocumentParams , InitializeParams , Url } ;
24
25
25
- use clap:: Parser ;
26
+ use clap:: { Args , Parser , Subcommand } ;
26
27
use lsp_server:: { Connection , ErrorCode , IoThreads , Message , RequestId , Response } ;
27
28
use std:: cell:: RefCell ;
28
29
use std:: collections:: HashMap ;
@@ -58,6 +59,25 @@ pub struct Cli {
58
59
/// Hide the preview toolbar
59
60
#[ arg( long, action) ]
60
61
no_toolbar : bool ,
62
+
63
+ #[ command( subcommand) ]
64
+ command : Option < Commands > ,
65
+ }
66
+
67
+ #[ derive( Subcommand , Clone ) ]
68
+ enum Commands {
69
+ /// Format slint files
70
+ Format ( Format ) ,
71
+ }
72
+
73
+ #[ derive( Args , Clone ) ]
74
+ struct Format {
75
+ #[ arg( name = "path to .slint file(s)" , action) ]
76
+ paths : Vec < std:: path:: PathBuf > ,
77
+
78
+ /// modify the file inline instead of printing to stdout
79
+ #[ arg( short, long, action) ]
80
+ inline : bool ,
61
81
}
62
82
63
83
enum OutgoingRequest {
@@ -156,6 +176,14 @@ fn main() {
156
176
std:: env:: set_var ( "SLINT_BACKEND" , & args. backend ) ;
157
177
}
158
178
179
+ if let Some ( Commands :: Format ( args) ) = args. command {
180
+ let _ = fmt:: tool:: run ( args. paths , args. inline ) . map_err ( |e| {
181
+ eprintln ! ( "{e}" ) ;
182
+ std:: process:: exit ( 1 ) ;
183
+ } ) ;
184
+ std:: process:: exit ( 0 ) ;
185
+ }
186
+
159
187
#[ cfg( feature = "preview-engine" ) ]
160
188
{
161
189
let cli_args = args. clone ( ) ;
@@ -187,6 +215,7 @@ fn main() {
187
215
preview:: start_ui_event_loop ( cli_args) ;
188
216
lsp_thread. join ( ) . unwrap ( ) ;
189
217
}
218
+
190
219
#[ cfg( not( feature = "preview-engine" ) ) ]
191
220
match run_lsp_server ( args) {
192
221
Ok ( threads) => threads. join ( ) . unwrap ( ) ,
0 commit comments