@@ -57,21 +57,48 @@ def active_linters
57
57
@linters . filter_map { |name | @supported_formatters [ name ] }
58
58
end
59
59
60
- sig { params ( options : T ::Hash [ Symbol , T . untyped ] ) . void }
60
+ # Applies the options provided by the editor and returns an array of notifications to send back to the client
61
+ sig { params ( options : T ::Hash [ Symbol , T . untyped ] ) . returns ( T ::Array [ Notification ] ) }
61
62
def apply_options ( options )
63
+ notifications = [ ]
62
64
direct_dependencies = gather_direct_dependencies
63
65
all_dependencies = gather_direct_and_indirect_dependencies
64
66
workspace_uri = options . dig ( :workspaceFolders , 0 , :uri )
65
67
@workspace_uri = URI ( workspace_uri ) if workspace_uri
66
68
67
69
specified_formatter = options . dig ( :initializationOptions , :formatter )
68
- @formatter = specified_formatter if specified_formatter
69
- @formatter = detect_formatter ( direct_dependencies , all_dependencies ) if @formatter == "auto"
70
+
71
+ if specified_formatter
72
+ @formatter = specified_formatter
73
+
74
+ if specified_formatter != "auto"
75
+ notifications << Notification . window_log_message ( "Using formatter specified by user: #{ @formatter } " )
76
+ end
77
+ end
78
+
79
+ if @formatter == "auto"
80
+ @formatter = detect_formatter ( direct_dependencies , all_dependencies )
81
+ notifications << Notification . window_log_message ( "Auto detected formatter: #{ @formatter } " )
82
+ end
70
83
71
84
specified_linters = options . dig ( :initializationOptions , :linters )
72
85
@linters = specified_linters || detect_linters ( direct_dependencies , all_dependencies )
86
+
87
+ notifications << if specified_linters
88
+ Notification . window_log_message ( "Using linters specified by user: #{ @linters . join ( ", " ) } " )
89
+ else
90
+ Notification . window_log_message ( "Auto detected linters: #{ @linters . join ( ", " ) } " )
91
+ end
92
+
73
93
@test_library = detect_test_library ( direct_dependencies )
94
+ notifications << Notification . window_log_message ( "Detected test library: #{ @test_library } " )
95
+
74
96
@has_type_checker = detect_typechecker ( direct_dependencies )
97
+ if @has_type_checker
98
+ notifications << Notification . window_log_message (
99
+ "Ruby LSP detected this is a Sorbet project and will defer to the Sorbet LSP for some functionality" ,
100
+ )
101
+ end
75
102
76
103
encodings = options . dig ( :capabilities , :general , :positionEncodings )
77
104
@encoding = if !encodings || encodings . empty?
@@ -91,6 +118,8 @@ def apply_options(options)
91
118
92
119
@experimental_features = options . dig ( :initializationOptions , :experimentalFeaturesEnabled ) || false
93
120
@type_inferrer . experimental_features = @experimental_features
121
+
122
+ notifications
94
123
end
95
124
96
125
sig { returns ( String ) }
@@ -163,16 +192,7 @@ def detect_test_library(dependencies)
163
192
def detect_typechecker ( dependencies )
164
193
return false if ENV [ "RUBY_LSP_BYPASS_TYPECHECKER" ]
165
194
166
- # We can't read the env from within `Bundle.with_original_env` so we need to set it here.
167
- ruby_lsp_env_is_test = ( ENV [ "RUBY_LSP_ENV" ] == "test" )
168
- Bundler . with_original_env do
169
- sorbet_static_detected = dependencies . any? ( /^sorbet-static/ )
170
- # Don't show message while running tests, since it's noisy
171
- if sorbet_static_detected && !ruby_lsp_env_is_test
172
- $stderr. puts ( "Ruby LSP detected this is a Sorbet project so will defer to Sorbet LSP for some functionality" )
173
- end
174
- sorbet_static_detected
175
- end
195
+ dependencies . any? ( /^sorbet-static/ )
176
196
rescue Bundler ::GemfileNotFound
177
197
false
178
198
end
0 commit comments