Skip to content

Commit

Permalink
Decouple DocumentHighlight's request and listener logic
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Dec 19, 2023
1 parent 352c5d2 commit 3fce992
Show file tree
Hide file tree
Showing 4 changed files with 574 additions and 556 deletions.
22 changes: 5 additions & 17 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def run(request)
nil
end
when "textDocument/documentHighlight"
document_highlight(uri, request.dig(:params, :position))
dispatcher = Prism::Dispatcher.new
document = @store.get(uri)
request = Requests::DocumentHighlight.new(document, request.dig(:params, :position), dispatcher)
dispatcher.dispatch(document.tree)
request.response
when "textDocument/onTypeFormatting"
on_type_formatting(uri, request.dig(:params, :position), request.dig(:params, :ch))
when "textDocument/hover"
Expand Down Expand Up @@ -348,22 +352,6 @@ def on_type_formatting(uri, position, character)
Requests::OnTypeFormatting.new(@store.get(uri), position, character).run
end

sig do
params(
uri: URI::Generic,
position: T::Hash[Symbol, T.untyped],
).returns(T.nilable(T::Array[Interface::DocumentHighlight]))
end
def document_highlight(uri, position)
document = @store.get(uri)

target, parent = document.locate_node(position)
dispatcher = Prism::Dispatcher.new
listener = Requests::DocumentHighlight.new(target, parent, dispatcher)
dispatcher.visit(document.tree)
listener.response
end

sig do
params(
uri: URI::Generic,
Expand Down
Loading

0 comments on commit 3fce992

Please sign in to comment.