Skip to content

Commit 0a21651

Browse files
Add scope to list of symbols
Fixes #311
1 parent 8c0e73a commit 0a21651

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def on_call_node_enter(node)
4242

4343
message = node.message
4444
case message
45-
when *Support::Callbacks::ALL, "validate"
45+
when *Support::Callbacks::ALL, "validate", "scope"
4646
handle_all_arg_types(node, T.must(message))
4747
when "validates", "validates!", "validates_each", "belongs_to", "has_one", "has_many", "has_and_belongs_to_many"
4848
handle_symbol_and_string_arg_types(node, T.must(message))

test/ruby_lsp_rails/document_symbol_test.rb

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

158+
test "correctly handles scope" do
159+
response = generate_document_symbols_for_source(<<~RUBY)
160+
class FooModel < ApplicationRecord
161+
scope :foo, ->{ where(a: 1).order(:b) }
162+
end
163+
RUBY
164+
165+
assert_equal(1, response.size)
166+
assert_equal("FooModel", response[0].name)
167+
assert_equal(2, response[0].children.size)
168+
assert_equal("scope :foo", response[0].children[0].name)
169+
assert_equal("scope <anonymous>", response[0].children[1].name)
170+
end
171+
158172
test "correctly handles model callbacks with multiple string arguments" do
159173
response = generate_document_symbols_for_source(<<~RUBY)
160174
class FooModel < ApplicationRecord

0 commit comments

Comments
 (0)