@@ -40,11 +40,14 @@ impl ProtoLanguageServer {
4040 info ! ( "Connected with client {cname} {cversion}" ) ;
4141
4242 // Parse initialization options for include paths
43- if let Some ( init_options) = & params. initialization_options {
44- if let Some ( include_paths) = parse_init_include_paths ( init_options) {
45- info ! ( "Setting include paths from initialization options: {:?}" , include_paths) ;
46- self . configs . set_init_include_paths ( include_paths) ;
47- }
43+ if let Some ( init_options) = & params. initialization_options
44+ && let Some ( include_paths) = parse_init_include_paths ( init_options)
45+ {
46+ info ! (
47+ "Setting include paths from initialization options: {:?}" ,
48+ include_paths
49+ ) ;
50+ self . configs . set_init_include_paths ( include_paths) ;
4851 }
4952
5053 let file_operation_filers = vec ! [ FileOperationFilter {
@@ -535,36 +538,25 @@ impl ProtoLanguageServer {
535538
536539/// Parse include_paths from initialization options
537540fn parse_init_include_paths ( init_options : & Value ) -> Option < Vec < PathBuf > > {
538- match init_options {
539- Value :: Object ( obj) => {
540- if let Some ( Value :: Array ( paths) ) = obj. get ( "include_paths" ) {
541- let mut result = Vec :: new ( ) ;
542- for path_value in paths {
543- if let Value :: String ( path) = path_value {
544- result. push ( PathBuf :: from ( path) ) ;
545- } else {
546- warn ! ( "Invalid include path in initialization options: {:?}" , path_value) ;
547- }
548- }
549- if !result. is_empty ( ) {
550- return Some ( result) ;
551- }
552- } else if let Some ( Value :: String ( paths_str) ) = obj. get ( "include_paths" ) {
553- // Support comma-separated string format like CLI
554- let result: Vec < PathBuf > = paths_str
555- . split ( ',' )
556- . map ( |s| PathBuf :: from ( s. trim ( ) ) )
557- . collect ( ) ;
558- if !result. is_empty ( ) {
559- return Some ( result) ;
560- }
561- }
562- }
563- _ => {
564- warn ! ( "initialization_options is not an object: {:?}" , init_options) ;
541+ let mut result = vec ! [ ] ;
542+ let paths = init_options[ "include_paths" ] . as_array ( ) ?;
543+
544+ for path_value in paths {
545+ if let Some ( path) = path_value. as_str ( ) {
546+ result. push ( PathBuf :: from ( path) ) ;
547+ } else {
548+ warn ! (
549+ "Invalid include path in initialization options: {:?}" ,
550+ path_value
551+ ) ;
565552 }
566553 }
567- None
554+
555+ if result. is_empty ( ) {
556+ None
557+ } else {
558+ Some ( result)
559+ }
568560}
569561
570562#[ cfg( test) ]
@@ -584,19 +576,6 @@ mod tests {
584576 assert_eq ! ( result[ 1 ] , PathBuf :: from( "relative/path" ) ) ;
585577 }
586578
587- #[ test]
588- fn test_parse_init_include_paths_string ( ) {
589- let init_options = json ! ( {
590- "include_paths" : "/path1,/path2,relative/path"
591- } ) ;
592-
593- let result = parse_init_include_paths ( & init_options) . unwrap ( ) ;
594- assert_eq ! ( result. len( ) , 3 ) ;
595- assert_eq ! ( result[ 0 ] , PathBuf :: from( "/path1" ) ) ;
596- assert_eq ! ( result[ 1 ] , PathBuf :: from( "/path2" ) ) ;
597- assert_eq ! ( result[ 2 ] , PathBuf :: from( "relative/path" ) ) ;
598- }
599-
600579 #[ test]
601580 fn test_parse_init_include_paths_missing ( ) {
602581 let init_options = json ! ( {
@@ -639,11 +618,14 @@ mod tests {
639618 "../shared-protos"
640619 ]
641620 } ) ;
642-
621+
643622 let include_paths = parse_init_include_paths ( & neovim_style_init_options) . unwrap ( ) ;
644-
623+
645624 assert_eq ! ( include_paths. len( ) , 3 ) ;
646- assert_eq ! ( include_paths[ 0 ] , PathBuf :: from( "/usr/local/include/protobuf" ) ) ;
625+ assert_eq ! (
626+ include_paths[ 0 ] ,
627+ PathBuf :: from( "/usr/local/include/protobuf" )
628+ ) ;
647629 assert_eq ! ( include_paths[ 1 ] , PathBuf :: from( "vendor/protos" ) ) ;
648630 assert_eq ! ( include_paths[ 2 ] , PathBuf :: from( "../shared-protos" ) ) ;
649631 }
0 commit comments