diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index 315224a3..98d00fd6 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb @@ -27,6 +27,33 @@ def create_client(outgoing_queue, global_state) end rescue StandardError => e unless outgoing_queue.closed? + bt_matcher = Regexp.new("(?#{Regexp.escape(global_state.workspace_uri.path)}/.*):(?[0-9]+):") + message_matcher = Regexp.new(".+:[0-9]+:in.*: ?(?.*) \\(RubyLsp::Rails::RunnerClient::InitializationError\\)") + + m = bt_matcher.match(e.full_message) + + unless m.nil? + outgoing_queue << RubyLsp::Notification.publish_diagnostics( + URI::File.build([nil, m["path"]]), + [ + Interface::Diagnostic.new( + range: Interface::Range.new( + start: Interface::Position.new( + line: m["line"].to_i - 1, + character: 0, + ), + end: Interface::Position.new( + line: m["line"].to_i - 1, + character: 0, + ), + ), + message: message_matcher.match(e.full_message)&.[]("message") || e.full_message.split("\n")[0], + severity: Constant::DiagnosticSeverity::ERROR, + source: "Ruby LSP", + ), + ], + ) + end outgoing_queue << RubyLsp::Notification.window_log_message( <<~MESSAGE.chomp, Ruby LSP Rails failed to initialize server: #{e.full_message}