File tree Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,40 @@ impl RubyLsp {
86
86
_ => None ,
87
87
}
88
88
}
89
+
90
+ pub fn language_server_initialization_options (
91
+ & self ,
92
+ language_server_id : & zed:: LanguageServerId ,
93
+ worktree : & zed:: Worktree ,
94
+ ) -> zed:: Result < Option < zed:: serde_json:: Value > > {
95
+ let mut initialization_options =
96
+ zed:: settings:: LspSettings :: for_worktree ( language_server_id. as_ref ( ) , worktree)
97
+ . ok ( )
98
+ . and_then ( |lsp_settings| lsp_settings. initialization_options . clone ( ) )
99
+ . unwrap_or_default ( ) ;
100
+
101
+ if !initialization_options. is_object ( ) {
102
+ initialization_options = zed:: serde_json:: json!( { } ) ;
103
+ }
104
+
105
+ let options_obj = initialization_options
106
+ . as_object_mut ( )
107
+ . expect ( "initialization_options must be an object" ) ;
108
+
109
+ let enabled_features = options_obj
110
+ . entry ( "enabledFeatures" )
111
+ . or_insert_with ( || zed:: serde_json:: json!( { } ) ) ;
112
+
113
+ // Workaround ruby-lsp upstream issue
114
+ // https://github.com/zed-extensions/ruby/issues/38
115
+ if let Some ( features_obj) = enabled_features. as_object_mut ( ) {
116
+ features_obj
117
+ . entry ( "onTypeFormatting" )
118
+ . or_insert ( zed:: serde_json:: Value :: Bool ( false ) ) ;
119
+ }
120
+
121
+ Ok ( Some ( initialization_options) )
122
+ }
89
123
}
90
124
91
125
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -82,13 +82,18 @@ impl zed::Extension for RubyExtension {
82
82
language_server_id : & zed:: LanguageServerId ,
83
83
worktree : & zed:: Worktree ,
84
84
) -> zed:: Result < Option < zed:: serde_json:: Value > > {
85
- let initialization_options =
86
- zed:: settings:: LspSettings :: for_worktree ( language_server_id. as_ref ( ) , worktree)
87
- . ok ( )
88
- . and_then ( |lsp_settings| lsp_settings. initialization_options . clone ( ) )
89
- . unwrap_or_default ( ) ;
90
-
91
- Ok ( Some ( zed:: serde_json:: json!( initialization_options) ) )
85
+ match language_server_id. as_ref ( ) {
86
+ RubyLsp :: SERVER_ID => {
87
+ let ruby = self . ruby_lsp . get_or_insert_with ( RubyLsp :: new) ;
88
+ ruby. language_server_initialization_options ( language_server_id, worktree)
89
+ }
90
+ _ => Ok ( Some (
91
+ zed:: settings:: LspSettings :: for_worktree ( language_server_id. as_ref ( ) , worktree)
92
+ . ok ( )
93
+ . and_then ( |lsp_settings| lsp_settings. initialization_options . clone ( ) )
94
+ . unwrap_or_default ( ) ,
95
+ ) ) ,
96
+ }
92
97
}
93
98
94
99
fn label_for_completion (
You can’t perform that action at this time.
0 commit comments