-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make document symbol extensible (#949)
* Make DocumentSymbol extensible * Add test_extension helper for extension tests
- Loading branch information
Showing
7 changed files
with
121 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,67 @@ | ||
# typed: strict | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "expectations/expectations_test_runner" | ||
|
||
class DocumentSymbolExpectationsTest < ExpectationsTestRunner | ||
expectations_tests RubyLsp::Requests::DocumentSymbol, "document_symbol" | ||
|
||
def test_document_symbol_extensions | ||
source = <<~RUBY | ||
test "foo" do | ||
end | ||
RUBY | ||
|
||
test_extension(:create_document_symbol_extension, source: source) do |executor| | ||
response = executor.execute({ | ||
method: "textDocument/documentSymbol", | ||
params: { textDocument: { uri: "file:///fake.rb" }, position: { line: 0, character: 1 } }, | ||
}).response | ||
|
||
assert_equal("foo", response.first.name) | ||
assert_equal(LanguageServer::Protocol::Constant::SymbolKind::METHOD, response.first.kind) | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_document_symbol_extension | ||
Class.new(RubyLsp::Extension) do | ||
def activate; end | ||
|
||
def name | ||
"Document SymbolsExtension" | ||
end | ||
|
||
def create_document_symbol_listener(emitter, message_queue) | ||
klass = Class.new(RubyLsp::Listener) do | ||
attr_reader :response | ||
|
||
def initialize(emitter, message_queue) | ||
super | ||
emitter.register(self, :on_command) | ||
end | ||
|
||
def on_command(node) | ||
T.bind(self, RubyLsp::Listener[T.untyped]) | ||
message_value = node.message.value | ||
return unless message_value == "test" && node.arguments.parts.any? | ||
|
||
first_argument = node.arguments.parts.first | ||
test_name = first_argument.parts.map(&:value).join | ||
|
||
@response = [RubyLsp::Interface::DocumentSymbol.new( | ||
name: test_name, | ||
kind: LanguageServer::Protocol::Constant::SymbolKind::METHOD, | ||
selection_range: range_from_syntax_tree_node(node), | ||
range: range_from_syntax_tree_node(node), | ||
)] | ||
end | ||
end | ||
|
||
klass.new(emitter, message_queue) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters