Skip to content

Account for dynamic constant paths in document symbol #437

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

Merged
merged 1 commit into from
Aug 28, 2024
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: 2 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def handle_all_arg_types(node, message)
selection_range: range_from_location(argument.location),
)
when Prism::ConstantReadNode, Prism::ConstantPathNode
name = argument.full_name
name = constant_name(argument)
next unless name
next if name.empty?

append_document_symbol(
Expand Down
12 changes: 12 additions & 0 deletions test/ruby_lsp_rails/document_symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ class FooModel < ApplicationRecord
assert_equal("belongs_to :baz", response[0].children[1].name)
end

test "does not break with incomplete constant path nodes" do
response = generate_document_symbols_for_source(<<~RUBY)
class FooModel < ApplicationRecord
validate var::Foo
end
RUBY

assert_equal(1, response.size)
assert_equal("FooModel", response[0].name)
assert_empty(response[0].children)
end

private

def generate_document_symbols_for_source(source)
Expand Down
Loading