Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Notification use consistent #2887

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jekyll/add-ons.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ module RubyLsp
def initialize(message_queue, response_builder, node_context, index, dispatcher)
@message_queue = message_queue

# TODO: update example
@message_queue << Notification.new(
message: "$/progress",
params: Interface::ProgressParams.new(
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/base_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def start
document.is_a?(ERBDocument)

send_message(
# TODO: add method in Notification
Notification.new(
method: "delegate/textDocument/virtualState",
params: {
Expand Down
43 changes: 9 additions & 34 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,9 @@ def load_addons(include_project_addons: true)
errored_addons = Addon.addons.select(&:error?)

if errored_addons.any?
message = "Error loading add-ons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}"
send_message(
Notification.new(
method: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::WARNING,
message: "Error loading add-ons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}",
),
),
Notification.window_show_message(message, type: Constant::MessageType::WARNING),
)

unless @test_mode
Expand Down Expand Up @@ -380,13 +375,7 @@ def text_document_did_open(message)
MESSAGE

send_message(
Notification.new(
method: "window/logMessage",
params: Interface::LogMessageParams.new(
type: Constant::MessageType::WARNING,
message: log_message,
),
),
Notification.window_log_message(log_message, type: Constant::MessageType::WARNING),
)
end
end
Expand All @@ -400,10 +389,7 @@ def text_document_did_close(message)

# Clear diagnostics for the closed file, so that they no longer appear in the problems tab
send_message(
Notification.new(
method: "textDocument/publishDiagnostics",
params: Interface::PublishDiagnosticsParams.new(uri: uri.to_s, diagnostics: []),
),
Notification.clear_diagnostics(uri),
)
end
end
Expand Down Expand Up @@ -1171,27 +1157,16 @@ def process_indexing_configuration(indexing_options)

if File.exist?(index_path)
begin
@global_state.index.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
message = "The .index.yml configuration file is deprecated. " \
"Please use editor settings to configure the index"
send_message(
Notification.new(
method: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::WARNING,
message: "The .index.yml configuration file is deprecated. " \
"Please use editor settings to configure the index",
),
),
Notification.window_show_message(message, type: Constant::MessageType::WARNING),
)
@global_state.index.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
rescue Psych::SyntaxError => e
message = "Syntax error while loading configuration: #{e.message}"
send_message(
Notification.new(
method: "window/showMessage",
params: Interface::ShowMessageParams.new(
type: Constant::MessageType::WARNING,
message: message,
),
),
Notification.window_show_message(message, type: Constant::MessageType::WARNING),
)
end
return
Expand Down
28 changes: 21 additions & 7 deletions lib/ruby_lsp/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ def window_log_message(message, type: Constant::MessageType::LOG)
)
end

sig { params(uri: String).returns(Notification) }
def clear_diagnostics(uri)
new(
method: "textDocument/publishDiagnostics",
params: Interface::PublishDiagnosticsParams.new(uri: uri.to_s, diagnostics: []),
)
end

def progress(id, kind)
new(
method: "$/progress",
params: Interface::ProgressParams.new(
token: id,
value: Interface::WorkDoneProgressEnd.new(kind: kind),
),
)
end

sig { params(data: T::Hash[Symbol, T.untyped]).returns(Notification) }
def telemetry(data)
new(
Expand Down Expand Up @@ -134,13 +152,7 @@ def progress_report(id, percentage: nil, message: nil)

sig { params(id: String).returns(Notification) }
def progress_end(id)
Notification.new(
method: "$/progress",
params: Interface::ProgressParams.new(
token: id,
value: Interface::WorkDoneProgressEnd.new(kind: "end"),
),
)
Notification.progress(id, "end")
end
end

Expand All @@ -161,6 +173,8 @@ def initialize(id:, method:, params:)
super(method: method, params: params)
end

private_class_method :new # we want to force the use of the factory methods
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'll need to check if any add-ons call this)


sig { override.returns(T::Hash[Symbol, T.untyped]) }
def to_hash
{ id: @id, method: @method, params: T.unsafe(@params).to_hash }
Expand Down
Loading