Skip to content

Commit

Permalink
Remove class level run method
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jun 7, 2022
1 parent 46d931d commit 0d42475
Show file tree
Hide file tree
Showing 18 changed files with 15 additions and 82 deletions.
14 changes: 7 additions & 7 deletions lib/ruby_lsp/handler.rb
Expand Up @@ -114,14 +114,14 @@ def respond_with_capabilities(enabled_features)
sig { params(uri: String).returns(T::Array[LanguageServer::Protocol::Interface::DocumentSymbol]) }
def respond_with_document_symbol(uri)
store.cache_fetch(uri, :document_symbol) do |document|
RubyLsp::Requests::DocumentSymbol.run(document)
RubyLsp::Requests::DocumentSymbol.new(document).run
end
end

sig { params(uri: String).returns(T::Array[LanguageServer::Protocol::Interface::FoldingRange]) }
def respond_with_folding_ranges(uri)
store.cache_fetch(uri, :folding_ranges) do |document|
Requests::FoldingRanges.run(document)
Requests::FoldingRanges.new(document).run
end
end

Expand All @@ -133,7 +133,7 @@ def respond_with_folding_ranges(uri)
end
def respond_with_selection_ranges(uri, positions)
ranges = store.cache_fetch(uri, :selection_ranges) do |document|
Requests::SelectionRanges.run(document)
Requests::SelectionRanges.new(document).run
end

# Per the selection range request spec (https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange),
Expand All @@ -159,13 +159,13 @@ def respond_with_semantic_highlighting(uri)

sig { params(uri: String).returns(T.nilable(T::Array[LanguageServer::Protocol::Interface::TextEdit])) }
def respond_with_formatting(uri)
Requests::Formatting.run(uri, store.get(uri))
Requests::Formatting.new(uri, store.get(uri)).run
end

sig { params(uri: String).void }
def send_diagnostics(uri)
response = store.cache_fetch(uri, :diagnostics) do |document|
Requests::Diagnostics.run(uri, document)
Requests::Diagnostics.new(uri, document).run
end

@writer.write(
Expand All @@ -182,7 +182,7 @@ def send_diagnostics(uri)
end
def respond_with_code_actions(uri, range)
store.cache_fetch(uri, :code_actions) do |document|
Requests::CodeActions.run(uri, document, range)
Requests::CodeActions.new(uri, document, range).run
end
end

Expand All @@ -193,7 +193,7 @@ def respond_with_code_actions(uri, range)
).returns(T::Array[LanguageServer::Protocol::Interface::DocumentHighlight])
end
def respond_with_document_highlight(uri, position)
Requests::DocumentHighlight.run(store.get(uri), position)
Requests::DocumentHighlight.new(store.get(uri), position).run
end

sig do
Expand Down
8 changes: 0 additions & 8 deletions lib/ruby_lsp/requests/base_request.rb
Expand Up @@ -7,17 +7,9 @@ module Requests
class BaseRequest < SyntaxTree::Visitor
extend T::Sig
extend T::Helpers
extend T::Generic

Response = type_template { { upper: T.untyped } }

abstract!

sig { overridable.params(document: Document).returns(Response) }
def self.run(document)
new(document).run
end

sig { params(document: Document).void }
def initialize(document)
@document = document
Expand Down
13 changes: 1 addition & 12 deletions lib/ruby_lsp/requests/code_actions.rb
Expand Up @@ -17,17 +17,6 @@ module Requests
class CodeActions
extend T::Sig

sig do
params(
uri: String,
document: Document,
range: T::Range[Integer]
).returns(T::Array[LanguageServer::Protocol::Interface::CodeAction])
end
def self.run(uri, document, range)
new(uri, document, range).run
end

sig do
params(
uri: String,
Expand All @@ -43,7 +32,7 @@ def initialize(uri, document, range)

sig { returns(T::Array[LanguageServer::Protocol::Interface::CodeAction]) }
def run
diagnostics = Diagnostics.run(@uri, @document)
diagnostics = Diagnostics.new(@uri, @document).run
corrections = diagnostics.select do |diagnostic|
diagnostic.correctable? && T.cast(diagnostic, Support::RuboCopDiagnostic).in_range?(@range)
end
Expand Down
10 changes: 0 additions & 10 deletions lib/ruby_lsp/requests/diagnostics.rb
Expand Up @@ -16,16 +16,6 @@ module Requests
# ```
class Diagnostics < RuboCopRequest
extend T::Sig
extend T::Generic

Response = type_template do
{
fixed: T.any(
T::Array[Support::RuboCopDiagnostic],
T::Array[Support::SyntaxErrorDiagnostic],
),
}
end

sig do
override.returns(
Expand Down
13 changes: 0 additions & 13 deletions lib/ruby_lsp/requests/document_highlight.rb
Expand Up @@ -22,9 +22,6 @@ module Requests
# ```
class DocumentHighlight < BaseRequest
extend T::Sig
extend T::Generic

Response = type_template { { fixed: T::Array[LanguageServer::Protocol::Interface::DocumentHighlight] } }

VarNodes = T.type_alias do
T.any(
Expand All @@ -36,16 +33,6 @@ class DocumentHighlight < BaseRequest
)
end

sig do
override(allow_incompatible: true).params(
document: Document,
position: Document::PositionShape
).returns(Response)
end
def self.run(document, position)
new(document, position).run
end

sig { params(document: Document, position: Document::PositionShape).void }
def initialize(document, position)
@highlights = T.let([], T::Array[LanguageServer::Protocol::Interface::DocumentHighlight])
Expand Down
3 changes: 0 additions & 3 deletions lib/ruby_lsp/requests/document_symbol.rb
Expand Up @@ -26,9 +26,6 @@ module Requests
# ```
class DocumentSymbol < BaseRequest
extend T::Sig
extend T::Generic

Response = type_template { { fixed: T::Array[LanguageServer::Protocol::Interface::DocumentSymbol] } }

SYMBOL_KIND = T.let({
file: 1,
Expand Down
3 changes: 0 additions & 3 deletions lib/ruby_lsp/requests/folding_ranges.rb
Expand Up @@ -14,9 +14,6 @@ module Requests
# ```
class FoldingRanges < BaseRequest
extend T::Sig
extend T::Generic

Response = type_template { { fixed: T::Array[LanguageServer::Protocol::Interface::FoldingRange] } }

SIMPLE_FOLDABLES = T.let([
SyntaxTree::ArrayLiteral,
Expand Down
3 changes: 0 additions & 3 deletions lib/ruby_lsp/requests/formatting.rb
Expand Up @@ -16,9 +16,6 @@ module Requests
# ```
class Formatting < RuboCopRequest
extend T::Sig
extend T::Generic

Response = type_template { { fixed: T.nilable(T::Array[LanguageServer::Protocol::Interface::TextEdit]) } }

RUBOCOP_FLAGS = T.let((COMMON_RUBOCOP_FLAGS + ["--autocorrect"]).freeze, T::Array[String])

Expand Down
8 changes: 0 additions & 8 deletions lib/ruby_lsp/requests/rubocop_request.rb
Expand Up @@ -10,9 +10,6 @@ module Requests
class RuboCopRequest < RuboCop::Runner
extend T::Sig
extend T::Helpers
extend T::Generic

Response = type_template { { upper: T.untyped } }

abstract!

Expand All @@ -28,11 +25,6 @@ class RuboCopRequest < RuboCop::Runner
sig { returns(String) }
attr_reader :text

sig { overridable.params(uri: String, document: Document).returns(Response) }
def self.run(uri, document)
new(uri, document).run
end

sig { params(uri: String, document: Document).void }
def initialize(uri, document)
@file = T.let(CGI.unescape(URI.parse(uri).path), String)
Expand Down
3 changes: 0 additions & 3 deletions lib/ruby_lsp/requests/selection_ranges.rb
Expand Up @@ -18,9 +18,6 @@ module Requests
# ```
class SelectionRanges < BaseRequest
extend T::Sig
extend T::Generic

Response = type_template { { fixed: T::Array[Support::SelectionRange] } }

NODES_THAT_CAN_BE_PARENTS = T.let([
SyntaxTree::Assign,
Expand Down
5 changes: 0 additions & 5 deletions lib/ruby_lsp/requests/semantic_highlighting.rb
Expand Up @@ -18,11 +18,6 @@ module Requests
# ```
class SemanticHighlighting < BaseRequest
extend T::Sig
extend T::Generic

Response = type_template do
{ fixed: T.any(LanguageServer::Protocol::Interface::SemanticTokens, T::Array[SemanticToken]) }
end

TOKEN_TYPES = T.let([
:variable,
Expand Down
2 changes: 1 addition & 1 deletion test/expectations/expectations_test_runner.rb
Expand Up @@ -14,7 +14,7 @@ def expectations_tests(handler_class, expectation_suffix)
module ExpectationsRunnerMethods
def run_expectations(source)
document = RubyLsp::Document.new(source)
#{handler_class}.run(document)
#{handler_class}.new(document).run
end
def assert_expectations(source, expected)
Expand Down
2 changes: 1 addition & 1 deletion test/requests/code_actions_test.rb
Expand Up @@ -34,7 +34,7 @@ def assert_code_actions(source, code_actions, range)
result = T.let(nil, T.nilable(T::Array[LanguageServer::Protocol::Interface::CodeAction]))

stdout, _ = capture_io do
result = RubyLsp::Requests::CodeActions.run("file://#{__FILE__}", document, range)
result = RubyLsp::Requests::CodeActions.new("file://#{__FILE__}", document, range).run
end

assert_empty(stdout)
Expand Down
2 changes: 1 addition & 1 deletion test/requests/diagnostics_expectations_test.rb
Expand Up @@ -9,7 +9,7 @@ class DiagnosticsExpectationsTest < ExpectationsTestRunner

def run_expectations(source)
document = RubyLsp::Document.new(source)
RubyLsp::Requests::Diagnostics.run("file://#{__FILE__}", document)
RubyLsp::Requests::Diagnostics.new("file://#{__FILE__}", document).run
end

def assert_expectations(source, expected)
Expand Down
2 changes: 1 addition & 1 deletion test/requests/diagnostics_test.rb
Expand Up @@ -17,7 +17,7 @@ class Foo

document.push_edits([error_edit])

result = RubyLsp::Requests::Diagnostics.run("file://#{__FILE__}", document)
result = RubyLsp::Requests::Diagnostics.new("file://#{__FILE__}", document).run
assert_equal(syntax_error_diagnostics([error_edit]).to_json, result.map(&:to_lsp_diagnostic).to_json)
end

Expand Down
2 changes: 1 addition & 1 deletion test/requests/document_highlight_test.rb
Expand Up @@ -130,7 +130,7 @@ def foo

def assert_highlight(source, position, expected)
document = RubyLsp::Document.new(source)
actual = RubyLsp::Requests::DocumentHighlight.run(document, position)
actual = RubyLsp::Requests::DocumentHighlight.new(document, position).run
ranges = JSON.parse(actual.to_json, symbolize_names: true)

assert_equal(expected.count, ranges.count)
Expand Down
2 changes: 1 addition & 1 deletion test/requests/formatting_expectations_test.rb
Expand Up @@ -9,7 +9,7 @@ class FormattingExpectationsTest < ExpectationsTestRunner

def run_expectations(source)
document = RubyLsp::Document.new(source)
RubyLsp::Requests::Formatting.run("file://#{__FILE__}", document)&.first&.new_text
RubyLsp::Requests::Formatting.new("file://#{__FILE__}", document).run&.first&.new_text
end

def assert_expectations(source, expected)
Expand Down
2 changes: 1 addition & 1 deletion test/requests/selection_ranges_test.rb
Expand Up @@ -1175,7 +1175,7 @@ def test_selecting_pattern_matching

def assert_ranges(source, positions, expected_ranges)
document = RubyLsp::Document.new(source)
actual = RubyLsp::Requests::SelectionRanges.run(document)
actual = RubyLsp::Requests::SelectionRanges.new(document).run
filtered = positions.map { |position| actual.find { |range| range.cover?(position) } }

assert_equal(expected_ranges, JSON.parse(filtered.to_json, symbolize_names: true))
Expand Down

0 comments on commit 0d42475

Please sign in to comment.