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

Remove BaseRequest #1260

Merged
merged 3 commits into from
Dec 19, 2023
Merged
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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ jobs:
- name: Check if documentation is up to date
run: bundle exec rake ruby_lsp:check_docs

- name: Check if all requests are using valid visits
run: bundle exec rake check_visit_overrides

- name: Typecheck
run: bundle exec srb tc

Expand Down
1 change: 0 additions & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ commands:
run: "bundle exec srb tc"
ci:
run: "bundle exec rake ruby_lsp:check_docs &&
bundle exec rake check_visit_overrides &&
bundle exec srb tc &&
bin/rubocop &&
bin/test &&
Expand Down
7 changes: 5 additions & 2 deletions lib/ruby_lsp/check_docs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ def run_task
# documented
features = ObjectSpace.each_object(Class).filter_map do |k|
klass = T.unsafe(k)
klass if klass < Requests::BaseRequest || (klass < Listener && klass != ExtensibleListener)
klass_name = klass.name
next unless klass_name

klass if klass_name.match?(/RubyLsp::Requests::\w[^:]+$/) && !klass_name.include?("Support")
end

missing_docs = T.let(Hash.new { |h, k| h[k] = [] }, T::Hash[String, T::Array[String]])

features.each do |klass|
class_name = T.must(klass.name)
class_name = klass.name
file_path, line_number = Module.const_source_location(class_name)
next unless file_path && line_number

Expand Down
1 change: 0 additions & 1 deletion lib/ruby_lsp/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module RubyLsp
# - [SignatureHelp](rdoc-ref:RubyLsp::Requests::SignatureHelp)

module Requests
autoload :BaseRequest, "ruby_lsp/requests/base_request"
autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
autoload :DocumentLink, "ruby_lsp/requests/document_link"
autoload :Hover, "ruby_lsp/requests/hover"
Expand Down
24 changes: 0 additions & 24 deletions lib/ruby_lsp/requests/base_request.rb

This file was deleted.

7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/code_action_resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Requests
#
# ```
#
class CodeActionResolve < BaseRequest
class CodeActionResolve
extend T::Sig
NEW_VARIABLE_NAME = "new_variable"

Expand All @@ -36,12 +36,11 @@ class Error < ::T::Enum

sig { params(document: Document, code_action: T::Hash[Symbol, T.untyped]).void }
def initialize(document, code_action)
super(document)

@document = document
@code_action = code_action
end

sig { override.returns(T.any(Interface::CodeAction, Error)) }
sig { returns(T.any(Interface::CodeAction, Error)) }
def run
return Error::EmptySelection if @document.source.empty?

Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/code_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Requests
# puts "Hello" # --> code action: quick fix indentation
# end
# ```
class CodeActions < BaseRequest
class CodeActions
extend T::Sig

sig do
Expand All @@ -27,14 +27,13 @@ class CodeActions < BaseRequest
).void
end
def initialize(document, range, context)
super(document)

@document = document
@uri = T.let(document.uri, URI::Generic)
@range = range
@context = context
end

sig { override.returns(T.nilable(T.all(T::Array[Interface::CodeAction], Object))) }
sig { returns(T.nilable(T.all(T::Array[Interface::CodeAction], Object))) }
def run
diagnostics = @context[:diagnostics]

Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/diagnostics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ module Requests
# puts "Hello" # --> diagnostics: incorrect indentation
# end
# ```
class Diagnostics < BaseRequest
class Diagnostics
extend T::Sig

sig { params(document: Document).void }
def initialize(document)
super(document)

@document = document
@uri = T.let(document.uri, URI::Generic)
end

sig { override.returns(T.nilable(T.all(T::Array[Interface::Diagnostic], Object))) }
sig { returns(T.nilable(T.all(T::Array[Interface::Diagnostic], Object))) }
def run
# Running RuboCop is slow, so to avoid excessive runs we only do so if the file is syntactically valid
return syntax_error_diagnostics if @document.syntax_error?
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Requests
# puts "Hello" # --> formatting: fixes the indentation on save
# end
# ```
class Formatting < BaseRequest
class Formatting
class Error < StandardError; end
class InvalidFormatter < StandardError; end

Expand Down Expand Up @@ -55,13 +55,12 @@ def register_formatter(identifier, instance)

sig { params(document: Document, formatter: String).void }
def initialize(document, formatter: "auto")
super(document)

@document = document
@uri = T.let(document.uri, URI::Generic)
@formatter = formatter
end

sig { override.returns(T.nilable(T.all(T::Array[Interface::TextEdit], Object))) }
sig { returns(T.nilable(T.all(T::Array[Interface::TextEdit], Object))) }
def run
return if @formatter == "none"
return if @document.syntax_error?
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/on_type_formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Requests
# # <-- cursor ends up here
# end # <-- end is automatically added
# ```
class OnTypeFormatting < BaseRequest
class OnTypeFormatting
extend T::Sig

END_REGEXES = T.let(
Expand All @@ -28,8 +28,7 @@ class OnTypeFormatting < BaseRequest

sig { params(document: Document, position: T::Hash[Symbol, T.untyped], trigger_character: String).void }
def initialize(document, position, trigger_character)
super(document)

@document = document
@lines = T.let(@document.source.lines, T::Array[String])
line = @lines[[position[:line] - 1, 0].max]

Expand All @@ -40,7 +39,7 @@ def initialize(document, position, trigger_character)
@trigger_character = trigger_character
end

sig { override.returns(T.all(T::Array[Interface::TextEdit], Object)) }
sig { returns(T.all(T::Array[Interface::TextEdit], Object)) }
def run
case @trigger_character
when "{"
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/requests/show_syntax_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ module Requests
# # (program (statements ((binary (int "1") + (int "1")))))
# ```
#
class ShowSyntaxTree < BaseRequest
class ShowSyntaxTree
extend T::Sig

sig { params(document: Document, range: T.nilable(T::Hash[Symbol, T.untyped])).void }
def initialize(document, range)
super(document)

@document = document
@range = range
end

sig { override.returns(String) }
sig { returns(String) }
def run
return ast_for_range if @range

Expand Down
38 changes: 0 additions & 38 deletions rakelib/check_valid_visits.rake

This file was deleted.