@@ -2,17 +2,30 @@ use anyhow::{Result, bail};
22use clap:: Parser ;
33
44use emacs_lsp_booster:: app;
5+ use emacs_lsp_booster:: bytecode;
56
67
7- #[ derive( Parser , Default ) ]
8+ #[ derive( Parser ) ]
89#[ command( long_about = None , about = None ,
9- arg_required_else_help = true , after_help = "For backward compatibility, `emacs-lsp-booster <SERVER_CMD>...` (without any options) is also supported\n " ) ]
10+ arg_required_else_help = true , after_help = "For backward compatibility, `emacs-lsp-booster <SERVER_CMD>...` (without any options) is also supported" ) ]
1011struct Cli {
1112 #[ command( flatten) ]
1213 verbose : clap_verbosity_flag:: Verbosity ,
1314
1415 #[ arg( last = true ) ]
1516 server_cmd : Vec < String > ,
17+
18+ #[ arg( long, default_value = "plist" ,
19+ help = "Lisp type used to represent a JSON object. Plist is the most performant one.\n Must match what lsp client expects.\n " ) ]
20+ json_object_type : bytecode:: ObjectType ,
21+
22+ #[ arg( long, default_value = "nil" ,
23+ help = "Which lisp value is used to represent a JSON null value. Support :SYMBOL or nil.\n Must match what lsp client expects.\n " ) ]
24+ json_null_value : bytecode:: LispObject ,
25+
26+ #[ arg( long, default_value = "nil" ,
27+ help = "Which lisp value is used to represent a JSON false value. Support :SYMBOL or nil.\n Must match what lsp client expects.\n " ) ]
28+ json_false_value : bytecode:: LispObject ,
1629}
1730
1831fn parse_args < T , S > ( args : T ) -> Cli
@@ -21,10 +34,9 @@ where T: IntoIterator<Item=S>,
2134 let args = args. into_iter ( ) . map ( |x| x. into ( ) ) . collect :: < Vec < String > > ( ) ;
2235 // backward compatible. support `emacs-lsp-booster server_cmd args...` directly
2336 if args. len ( ) > 1 && !args[ 1 ] . starts_with ( '-' ) && !args. contains ( & "--" . into ( ) ) {
24- Cli {
25- server_cmd : args[ 1 ..] . to_vec ( ) ,
26- ..Default :: default ( )
27- }
37+ let mut fake_args = vec ! [ args[ 0 ] . clone( ) , "--" . into( ) ] ;
38+ fake_args. extend_from_slice ( & args[ 1 ..] ) ;
39+ Cli :: parse_from ( fake_args)
2840 } else {
2941 Cli :: parse_from ( args)
3042 }
@@ -48,7 +60,13 @@ fn main() -> Result<()> {
4860 let mut cmd = std:: process:: Command :: new ( & cli. server_cmd [ 0 ] ) ;
4961 cmd. args ( & cli. server_cmd [ 1 ..] ) ;
5062
51- let exit_status = app:: run_app_forever ( std:: io:: stdin ( ) , std:: io:: stdout ( ) , cmd) ?;
63+ let exit_status = app:: run_app_forever ( std:: io:: stdin ( ) , std:: io:: stdout ( ) , cmd, app:: AppOptions {
64+ bytecode_options : bytecode:: BytecodeOptions {
65+ object_type : cli. json_object_type ,
66+ null_value : cli. json_null_value ,
67+ false_value : cli. json_false_value ,
68+ } ,
69+ } ) ?;
5270 std:: process:: exit ( exit_status. code ( ) . unwrap_or ( 1 ) )
5371}
5472
@@ -60,7 +78,14 @@ fn test_parse_args() {
6078 let cli = parse_args ( vec ! [ "emacs-lsp-booster" , "--" , "server_cmd" , "arg1" ] ) ;
6179 assert_eq ! ( cli. server_cmd, vec![ "server_cmd" , "arg1" ] ) ;
6280
63- let cli = parse_args ( vec ! [ "emacs-lsp-booster" , "-v" , "--" , "server_cmd" , "arg1" ] ) ;
81+ let cli = parse_args ( vec ! [ "emacs-lsp-booster" , "-v" ,
82+ "--json-object-type" , "hashtable" ,
83+ "--json-null-value" , ":null" ,
84+ "--json-false-value" , ":json-false" ,
85+ "--" , "server_cmd" , "arg1" ] ) ;
6486 assert_eq ! ( cli. verbose. log_level_filter( ) , log:: LevelFilter :: Warn ) ;
6587 assert_eq ! ( cli. server_cmd, vec![ "server_cmd" , "arg1" ] ) ;
88+ assert_eq ! ( cli. json_object_type, bytecode:: ObjectType :: Hashtable ) ;
89+ assert_eq ! ( cli. json_null_value, bytecode:: LispObject :: Symbol ( "null" . into( ) ) ) ;
90+ assert_eq ! ( cli. json_false_value, bytecode:: LispObject :: Symbol ( "json-false" . into( ) ) ) ;
6691}
0 commit comments