-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add scope to list of symbols #333
Conversation
I have signed the CLA! |
test "correctly handles scope" do | ||
response = generate_document_symbols_for_source(<<~RUBY) | ||
class FooModel < ApplicationRecord | ||
scope :foo, ->{ where(a: 1).order(:b) } | ||
end | ||
RUBY | ||
|
||
assert_equal(1, response.size) | ||
assert_equal("FooModel", response[0].name) | ||
assert_equal(2, response[0].children.size) | ||
assert_equal("scope :foo", response[0].children[0].name) | ||
assert_equal("scope <anonymous>", response[0].children[1].name) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if you wanted this test. I see that a lot of supported methods are all untested and just fall under the "correctly handles validate method with all argument types" test basically. So maybe this test isn't necessary.
0a21651
to
adfa58c
Compare
I just rebased this to resolve the merge conflict |
I should have suggested this in #332 too, but can we add an example of this to the dummy app to allow for easy manual testing? |
Done! 0630ff5 |
This might not be a blocker, but when testing I realised that we will be unintentionally listing |
@vinistock @st0012 we could try make this only detect |
Is there a way to scope all of these to the app/models folder? Right now you’re kind of assuming these are ActiveRecord methods right? Gems like ActiveModelSerizers define |
I don't think it's a major issue to include the |
@natematykiewicz do you want to try that? It would a similar what we do here, but allowing for any class. |
Yup! I'll give it a go. |
How's this look? ffd73e7 This is my first time using Sorbet. I think I set up that union type right. I also struggled to figure out how Prism knows to call I basically guessed that Without the module ones, the concern's symbols started failing to get indexed. I wasn't sure if you wanted this class/module check only for |
@@ -37,6 +45,8 @@ def on_call_node_enter(node) | |||
) | |||
end | |||
|
|||
return if @namespace_stack.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) we could move this to the first line of the method, since tests would always be defined within a module or class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! ba61090
I forgot ActiveSupport::TestCase uses classes. I'm so used to RSpec.describe do end
.
@natematykiewicz thanks! |
Fixes #311