Skip to content

Commit bf7161b

Browse files
author
Aryan Soni
committed
Implement document symbol for associations
1 parent 46b97ce commit bf7161b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There is no need to add the gem to your bundle.
1616

1717
* Hover over an ActiveRecord model to reveal its schema.
1818
* Run or debug a test by clicking on the code lens which appears above the test class, or an individual test.
19-
* Navigate to validations, callbacks and test cases using your editor's "Go to Symbol" feature, or outline view.
19+
* Navigate to associations, validations, callbacks and test cases using your editor's "Go to Symbol" feature, or outline view.
2020

2121
## Documentation
2222

lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def on_call_node_enter(node)
100100
case message
101101
when *CALLBACKS, "validate"
102102
handle_all_arg_types(node, T.must(message))
103-
when "validates", "validates!", "validates_each"
103+
when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many", "has_and_belongs_to_many"
104104
handle_symbol_and_string_arg_types(node, T.must(message))
105105
when "validates_with"
106106
handle_class_arg_types(node, T.must(message))

test/dummy/app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
class User < ApplicationRecord
55
before_create :foo_arg, -> () {}
66
validates :name, presence: true
7+
has_one :profile
78
end

test/ruby_lsp_rails/document_symbol_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,20 @@ class FooModel < ApplicationRecord
349349
assert_equal("validates_with(Foo::BarClass)", response[0].children[1].name)
350350
end
351351

352+
test "correctly handles association callbacks with string and symbol argument types" do
353+
response = generate_document_symbols_for_source(<<~RUBY)
354+
class FooModel < ApplicationRecord
355+
belongs_to :foo, "baz"
356+
end
357+
RUBY
358+
359+
assert_equal(1, response.size)
360+
assert_equal("FooModel", response[0].name)
361+
assert_equal(2, response[0].children.size)
362+
assert_equal("belongs_to(foo)", response[0].children[0].name)
363+
assert_equal("belongs_to(baz)", response[0].children[1].name)
364+
end
365+
352366
private
353367

354368
def generate_document_symbols_for_source(source)

0 commit comments

Comments
 (0)