-
Notifications
You must be signed in to change notification settings - Fork 132
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
Feature comment docs onhover #234
Feature comment docs onhover #234
Conversation
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
==========================================
+ Coverage 71.61% 73.47% +1.86%
==========================================
Files 18 18
Lines 539 558 +19
Branches 87 90 +3
==========================================
+ Hits 386 410 +24
+ Misses 131 125 -6
- Partials 22 23 +1
Continue to review full report at Codecov.
|
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.
Thanks! This is a great suggestion.
A few things:
- can you add some unit tests documenting this new bahaviour (see https://github.com/nikita-skobov/bash-language-server/blob/68a15ff3c7a578ecf951e1c5754065d745020b67/server/src/__tests__/server.test.ts#L50) and probably also one for the analyzer extension you did
- we already have an AST of the program analyzed by tree sitter bash. We would need to figure out if that can return the comment instead of us manually parsing the file. It might not be able to do this right now, but it could be a future improvement
- once we have some tests in place I might have a few suggestions around the implementation
Again, thank for your contribution. This would be a great extension!
I’m curious to know why the tests are failing locally for you. As you see CI isn’t failing, all tests pass. So it must be something in your environment that the test suite is not catering for. Can you share more information/output from the failure. Is there more output from when running the tests? Which OS are you running? |
I'm a little confused on the architecture with the server. Before I run the tests do I need to do something to set up the server? In any case here is my system information:
I recloned the repo in a new directory straight from master, and I did the following steps:
I hope that helps. Let me know if theres any other info needed |
In regards to the feature PR, I will try my hand at writing some tests. I suppose the tests I need to write/modify are:
I can see (somewhat) how to modify the existing test to test for the comment doc feature, but Im not sure I'd know how to go about creating a new test for the In regards to the AST, can you give me some suggestions on how to use it to extract comments at a specific line? |
Can I get you to do a As for the tests, then I can come with some suggestions for these tests if you are fine with that. We basically want to test the different cases (one comment above, multiple comments, no comments) and see how the function reacts to this. After that we can refactor the function and be sure it still works. About the AST, then it currently doesn’t support this (I investigated it). So your current approach is fine. |
Yes. Here is the output:
Maybe Im wrong but it seems the issue is that the test assumes that there are less than 5 executables on a user's PATH that begin with Solution: update to less than 6? Or otherwise it probably doesn't matter much because this test fails based on a user's path, and as long as it works on the CI, does it really matter if a user has a bunch of extra executables that start with |
previously it was hardcoded at 10. It took me a while to realize that 10 referred to the number of files in the fixtures folder that ended in .sh and since I added another file: comment-doc-on-hover.sh this value of 10 needed to be updated to 11
I added the tests mentioned above using a new fixture: Also, I wonder whats the best way to display the comments, ie: should it preserve newlines or not? Should it attempt to style it differently somehow? The current functionality will not preserve comment newlines, eg:
will be returned from
but because it's rendered with markdown it will show up as:
Personally I think this is fine because comment documentations are typically wrapped around when the line gets too long, and this allows you to read it as a sentence like it was intended. But that's just my opinion, changing it to preserve the newlines would be trivial: just add an extra \n when it joins the lines. |
Let us do less than 8. Would be nice that it runs on your machine. The point of the test is just that the set returned is limited. |
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.
Thank you so much for the tests and your contribution! I've added a bunch of comments that I hope you find useful.
/** | ||
* Find a block of comments above a line position | ||
*/ | ||
public commentsAbove(uri: string, line: number): string | null { |
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'm wondering if we should call this findRelatedComment
. More precise as it only returns a comment for when we find a match above the function/variable.
maybe a user has several executables on their path that start with 'rm', so for this test to be a bit more inclusive, we increase the result.length maximum
As of commit 1e35af1 I think Ive resolved all issues mentioned in the comments. Please let me know if this can be merged into master, or if there are any other issues. |
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.
Thank you so much for your contribution. I'll release a new version with this (soonish).
Language server changelog: 1.16.1 Fix brace expansion bug (bash-lsp/bash-language-server#240) Do not crash if bash is not installed (bash-lsp/bash-language-server#242) 1.16.0 Improved completion handler for parameter expansions (bash-lsp/bash-language-server#237) 1.15.0 Use comments above symbols for documentation (bash-lsp/bash-language-server#234, bash-lsp/bash-language-server#235) 1.14.0 onHover and onCompletion documentation improvements (bash-lsp/bash-language-server#230) support 0/1 as values for HIGHLIGHT_PARSING_ERRORS (bash-lsp/bash-language-server#231) 1.13.1 Gracefully handle glob failures (bash-lsp/bash-language-server#224, bash-lsp/bash-language-server#226) Maintenance (bash-lsp/bash-language-server#222, bash-lsp/bash-language-server#225) Signed-off-by: Alexander Kurtakov <[email protected]>
Language server changelog: 1.16.1 Fix brace expansion bug (bash-lsp/bash-language-server#240) Do not crash if bash is not installed (bash-lsp/bash-language-server#242) 1.16.0 Improved completion handler for parameter expansions (bash-lsp/bash-language-server#237) 1.15.0 Use comments above symbols for documentation (bash-lsp/bash-language-server#234, bash-lsp/bash-language-server#235) 1.14.0 onHover and onCompletion documentation improvements (bash-lsp/bash-language-server#230) support 0/1 as values for HIGHLIGHT_PARSING_ERRORS (bash-lsp/bash-language-server#231) 1.13.1 Gracefully handle glob failures (bash-lsp/bash-language-server#224, bash-lsp/bash-language-server#226) Maintenance (bash-lsp/bash-language-server#222, bash-lsp/bash-language-server#225) Signed-off-by: Alexander Kurtakov <[email protected]>
In most languages, comments above a function serve as documentation for that function. I modified this extension to be able to view the comments that are above functions as tooltips onHover.
It looks like this:
Also works for functions defined in other files that are included in the
this.uriToDeclarations
from analyser.ts:I followed the steps in the development guide before editing the extension and I got this failure:
so that error is unrelated to my changes. I then ran
yarn test
again after making my changes, and no other tests failed.I'm new to working on VScode extensions, so let me know if there is a more idiomatic/efficient way to achieve what my code does.