From 608c90b5b447a801f791a70834ee20b5bb6d0caf Mon Sep 17 00:00:00 2001 From: Steven Willis Date: Tue, 9 Sep 2025 15:27:02 -0400 Subject: [PATCH 1/2] Send Diagnostic information on InitializationError --- lib/ruby_lsp/ruby_lsp_rails/runner_client.rb | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index 315224a3..fe82dbbe 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("from (?#{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} From 0c68e916232a84e0e71bd629d91cd7d45d93a4b8 Mon Sep 17 00:00:00 2001 From: Steven Willis Date: Tue, 9 Sep 2025 15:48:38 -0400 Subject: [PATCH 2/2] Match when the source location is on the first line of a backtrace --- lib/ruby_lsp/ruby_lsp_rails/runner_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index fe82dbbe..98d00fd6 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb @@ -27,7 +27,7 @@ def create_client(outgoing_queue, global_state) end rescue StandardError => e unless outgoing_queue.closed? - bt_matcher = Regexp.new("from (?#{Regexp.escape(global_state.workspace_uri.path)}/.*):(?[0-9]+):") + 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)