-
Notifications
You must be signed in to change notification settings - Fork 7
Enhance constant lookup to support namespaced constants in ProjectManager #134
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -359,5 +359,62 @@ def some_method(meaningful) # line 17: parameter declaration | |||||||||
| assert_equal 11, results.first[:range][:start][:line] | ||||||||||
| end | ||||||||||
| end | ||||||||||
|
|
||||||||||
| describe 'constant lookup with namespace' do | ||||||||||
| let(:file_with_namespaced_constant) do | ||||||||||
| <<~CODE_FILE | ||||||||||
| module Foo | ||||||||||
| BAR = "bar constant" | ||||||||||
|
|
||||||||||
| class Baz | ||||||||||
| QUUX = "quux constant" | ||||||||||
| end | ||||||||||
| end | ||||||||||
|
|
||||||||||
| # Using the constant | ||||||||||
| puts Foo::BAR | ||||||||||
| puts Foo::Baz::QUUX | ||||||||||
| CODE_FILE | ||||||||||
| end | ||||||||||
|
|
||||||||||
| before(:each) do | ||||||||||
| project_manager.update_document_content('const_uri', file_with_namespaced_constant) | ||||||||||
| project_manager.tags_for_uri('const_uri') # Force load of tags | ||||||||||
| end | ||||||||||
|
|
||||||||||
| it 'finds constant definition when clicking on constant in Foo::BAR' do | ||||||||||
| # Position on "BAR" in "Foo::BAR" (line 9, character 10) | ||||||||||
| # The line is: "puts Foo::BAR" | ||||||||||
| position = OpenStruct.new(line: 9, character: 10) | ||||||||||
|
Comment on lines
+386
to
+388
|
||||||||||
| results = project_manager.possible_definitions('const_uri', position) | ||||||||||
|
|
||||||||||
| # Should find the BAR constant definition on line 1 | ||||||||||
| assert_equal 1, results.length, "Expected to find 1 definition for Foo::BAR, but got #{results.length}" | ||||||||||
| assert_equal 'const_uri', results.first[:uri] | ||||||||||
| assert_equal 1, results.first[:range][:start][:line] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| it 'finds constant definition when clicking on nested constant in Foo::Baz::QUUX' do | ||||||||||
| # Position on "QUUX" in "Foo::Baz::QUUX" (line 10, character 16) | ||||||||||
| position = OpenStruct.new(line: 10, character: 16) | ||||||||||
|
Comment on lines
+398
to
+399
|
||||||||||
| # Position on "QUUX" in "Foo::Baz::QUUX" (line 10, character 16) | |
| position = OpenStruct.new(line: 10, character: 16) | |
| # Position on "QUUX" in "Foo::Baz::QUUX" (line 15, character 16) | |
| position = OpenStruct.new(line: 15, character: 16) |
Copilot
AI
Jan 29, 2026
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.
Similar to the previous issues, this comment references line 9 but should reference line 14 where puts Foo::BAR is located in the test code.
| # Position on "Foo" in "Foo::BAR" (line 9, character 5) | |
| # Position on "Foo" in "Foo::BAR" (line 14, character 5) |
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.
The comment states 'This shouldn't happen' but the code handles it. If this truly should never occur, consider raising an error or adding logging to track if this case is ever hit, which would help identify bugs in the namespace parsing logic.