-
Notifications
You must be signed in to change notification settings - Fork 56
Fix hover for global functions by adding global scope fallback #1541
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
fc8c8bf
2465506
79ebcfd
b50df8d
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 |
|---|---|---|
|
|
@@ -219,5 +219,44 @@ describe('HoverProcessor', () => { | |
| expect(hover?.range).to.eql(util.createRange(2, 40, 2, 50)); | ||
| expect(hover?.contents).to.eql(fence('const name.sp.a.c.e.SOME_VALUE = true')); | ||
| }); | ||
|
|
||
| it('finds hover for global function', () => { | ||
| const file = program.setFile('source/main.brs', ` | ||
| sub main() | ||
| result = Abs(-5) | ||
| end sub | ||
| `); | ||
| program.validate(); | ||
|
|
||
| // hover over the `Abs` function call | ||
| let hover = program.getHover(file.pathAbsolute, util.createPosition(2, 29))[0]; | ||
| expect(hover).to.exist; | ||
| expect(hover.range).to.eql(util.createRange(2, 29, 2, 32)); | ||
| expect(hover.contents).to.contain('function Abs(x as float) as float'); | ||
| }); | ||
|
|
||
| it('finds hover for global function when file has no scopes', () => { | ||
| // Create a program with no manifest and no scopes to ensure global scope fallback | ||
| const testProgram = new Program({ rootDir: rootDir }); | ||
|
|
||
| const file = testProgram.setFile('standalone/main.brs', ` | ||
| sub main() | ||
| result = Abs(-5) | ||
| end sub | ||
| `); | ||
|
|
||
| // Don't validate - this simulates a file that might not be in any scopes | ||
| const scopes = testProgram.getScopesForFile(file); | ||
|
|
||
| // hover over the `Abs` function call | ||
| let hover = testProgram.getHover(file.pathAbsolute, util.createPosition(2, 29))[0]; | ||
|
|
||
| testProgram.dispose(); | ||
|
|
||
| // After the fix, this should now work even when file has no scopes | ||
| expect(hover).to.exist; | ||
| expect(hover.range).to.eql(util.createRange(2, 29, 2, 32)); | ||
| expect(hover.contents).to.contain('function Abs(x as float) as float'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to also see the description of the function. Looking at Here's what I'm expecting. 'a test function
sub test()
end sub
sub init()
test() 'hover over this, it includes "a test function"
end subBut for the global functions, it doesn't. It's not even related to files with zero scopes. I can reproduce this in my source/main.brs file.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by modifying HoverProcessor to show shortDescription and documentation from global callables. The hover now includes descriptions like "Returns the absolute value of the argument." for global functions. Updated tests to verify the descriptions are shown. |
||
| }); | ||
| }); | ||
| }); | ||
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.
This is dead code. please remove. (you could find this out by running the lint rules before committing).
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.
Fixed by removing the unused variable. The build now passes without TypeScript errors.