Skip to content

Commit

Permalink
Extract Notification.window_show_error (Shopify#1441)
Browse files Browse the repository at this point in the history
Extract `Notification.error`

Co-authored-by: Andy Waite <[email protected]>
  • Loading branch information
andyw8 and andyw8 authored Mar 1, 2024
1 parent 00c42a2 commit f42455c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 51 deletions.
59 changes: 9 additions & 50 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,10 @@ def run(request)
begin
formatting(uri)
rescue Requests::Formatting::InvalidFormatter => error
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Configuration error: #{error.message}",
),
)

@message_queue << Notification.window_show_error("Configuration error: #{error.message}")
nil
rescue StandardError, LoadError => error
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Formatting error: #{error.message}",
),
)

@message_queue << Notification.window_show_error("Formatting error: #{error.message}")
nil
end
when "textDocument/documentHighlight"
Expand Down Expand Up @@ -174,14 +160,7 @@ def run(request)
begin
diagnostic(uri)
rescue StandardError, LoadError => error
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Error running diagnostics: #{error.message}",
),
)

@message_queue << Notification.window_show_error("Error running diagnostics: #{error.message}")
nil
end
when "textDocument/completion"
Expand Down Expand Up @@ -287,13 +266,7 @@ def perform_initial_indexing
false
end
rescue StandardError => error
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Error while indexing: #{error.message}",
),
)
@message_queue << Notification.window_show_error("Error while indexing: #{error.message}")
end

# Always end the progress notification even if indexing failed or else it never goes away and the user has no
Expand Down Expand Up @@ -402,21 +375,11 @@ def code_action_resolve(params)

case result
when Requests::CodeActionResolve::Error::EmptySelection
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Invalid selection for Extract Variable refactor",
),
)
@message_queue << Notification.window_show_error("Invalid selection for Extract Variable refactor")
raise Requests::CodeActionResolve::CodeActionError
when Requests::CodeActionResolve::Error::InvalidTargetRange
@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Couldn't find an appropriate location to place extracted refactor",
),
@message_queue << Notification.window_show_error(
"Couldn't find an appropriate location to place extracted refactor",
)
raise Requests::CodeActionResolve::CodeActionError
else
Expand Down Expand Up @@ -639,12 +602,8 @@ def check_formatter_is_available
unless defined?(RubyLsp::Requests::Support::RuboCopRunner)
@store.formatter = "none"

@message_queue << Notification.new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: "Ruby LSP formatter is set to `rubocop` but RuboCop was not found in the Gemfile or gemspec.",
),
@message_queue << Notification.window_show_error(
"Ruby LSP formatter is set to `rubocop` but RuboCop was not found in the Gemfile or gemspec.",
)
end
end
Expand Down
17 changes: 16 additions & 1 deletion lib/ruby_lsp/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ def initialize(message:, params:)
end
end

class Notification < Message; end
class Notification < Message
class << self
extend T::Sig
sig { params(message: String).returns(Notification) }
def window_show_error(message)
new(
message: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::ERROR,
message: message,
),
)
end
end
end

class Request < Message; end

# The final result of running a request before its IO is finalized
Expand Down

0 comments on commit f42455c

Please sign in to comment.