-
Notifications
You must be signed in to change notification settings - Fork 172
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
Account for private constants in features #1004
Conversation
e69179d
to
eae8b7b
Compare
97051dc
to
0a1d9fd
Compare
0a1d9fd
to
fad6231
Compare
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.
Nice comments
end | ||
|
||
def test_completion_private_constants_from_different_namespace | ||
RubyLsp::DependencyDetector.const_set(:HAS_TYPECHECKER, false) |
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.
Not in this PR, but since we use this a lot I wonder we should extract it out, e.g.:
def with_typechecker_disabled(&block)
RubyLsp::DependencyDetector.const_set(:HAS_TYPECHECKER, false)
yield
ensure
RubyLsp::DependencyDetector.const_set(:HAS_TYPECHECKER, true)
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.
That's true. We can extract it in another PR.
RUBY | ||
|
||
result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::CONSTANT", @index).run | ||
assert_equal(1, result.length) |
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 may be misunderstanding the test, but if we're looking up Foo::CONSTANT
then why is Foo
in the results?
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.
Because we fuzzy match the results for workspace symbol and the Jaro-Winkler similarity between Foo
and Foo::CONSTANT
is high. The reason is likely because Jaro-Winkler gives a higher importance to the prefix than it does to the rest of the word
ruby-lsp(main):001> DidYouMean::JaroWinkler.distance("Foo", "Foo::CONSTANT")
=> 0.8205128205128205
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.
Ah, I see. That may be worth a code comment.
Motivation
Closes #966
We should only provide definition, completion and hover for private constants if the reference happens inside the exact same namespace as they are defined. Otherwise, it's a reference to a constant that doesn't actually exist.
Similarly, private constants should never be shown in workspace symbol.
Implementation
I split the PR by commits to make it easier to review.
On each request, started skipping adding results if we find a non-private reference to a private constant.
Automated Tests
Added tests for all features.