Skip to content

Commit e7f10ea

Browse files
Add attr_readonly to list of Symbols (#332)
Thanks @natematykiewicz !
1 parent 64a56af commit e7f10ea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def on_call_node_enter(node)
4444
case message
4545
when *Support::Callbacks::ALL, "validate"
4646
handle_all_arg_types(node, T.must(message))
47-
when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many", "has_and_belongs_to_many"
47+
when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many",
48+
"has_and_belongs_to_many", "attr_readonly"
4849
handle_symbol_and_string_arg_types(node, T.must(message))
4950
when "validates_with"
5051
handle_class_arg_types(node, T.must(message))

test/ruby_lsp_rails/document_symbol_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ class NestedTest < ActiveSupport::TestCase
155155
assert_equal("back to the same level", response[0].children[2].name)
156156
end
157157

158+
test "correctly handles attr_readonly" do
159+
response = generate_document_symbols_for_source(<<~RUBY)
160+
class FooModel < ApplicationRecord
161+
attr_readonly :foo
162+
end
163+
RUBY
164+
165+
assert_equal(1, response.size)
166+
assert_equal("FooModel", response[0].name)
167+
assert_equal(1, response[0].children.size)
168+
assert_equal("attr_readonly :foo", response[0].children[0].name)
169+
end
170+
158171
test "correctly handles model callbacks with multiple string arguments" do
159172
response = generate_document_symbols_for_source(<<~RUBY)
160173
class FooModel < ApplicationRecord

0 commit comments

Comments
 (0)