-
Notifications
You must be signed in to change notification settings - Fork 646
Add item documentation to completions #2054
Add item documentation to completions #2054
Conversation
Using `go doc` instead of `godoc` due to golang/go#25443 `go doc` doesn't seem to support giving the code of an unsaved file via stdin like `gocode`, so it won't display documentation for unsaved changes. Fixes microsoft#194
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 for the PR @segevfiner!
I've left a few comments, please take a look.
Also, I see that this is your first contribution to vscode-go. Welcome & Thanks!
I hope that you have registered both for the Microsoft Hacktoberfest and the one from Digitalocean
Happy Coding!
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 have pushed a commit for a small refactoring.
Also made the change to not reject the promise and instead to console.log the error and return the completion item without docs.
Please take a look and let me know if you are ok with those changes as well.
I have tested the changes and it works well!
One concern is around the line breaks. I'll look into how we solved this problem in other languages and get back to you.
Do you know what the behavior would be when using an older version of gocode
that doesn't return the package info at all?
Looks fine to me.
I'm not sure myself how VS Code handles line breaking in plain string documentation and whether that's compatible with the output of Go documentation comments do have some small amount of formatting, which we can try to convert to Markdown so that it shows nicer in VS Code. But that's best left to a separate PR, and done in all places that show Go documentation strings.
In older versions of |
And in the newer |
It's an empty string, the property always seems to exist in the newer version (gocode/formatters.go:160-161). I pushed a commit that should implement this. |
Thanks for the review & merge! 🎉 |
Thanks for all your work! I have pushed 3ba34e0 that converts the doc string to markdown. It looks better now. |
But aren't Go documentation strings not Markdown? They don't render as Markdown in godoc comments do have some very minimal formatting: paragraph handling (Similar to Markdown) indented preformatted text, hyperlinks, and sections (If I'm not missing any...) But no things like bold/italic and such. So I think the right way to handle this is to write a function which will convert any godoc formatting not already handled by What do you think? |
Can you point me to some examples? |
Some references: This shows the difference in rendering: package docexample
// Hello **World**!
func Frob() {
} Granted, in this example it doesn't matter much, but there are likely plenty of examples where this can really mess up the formatting, I just don't have one on the top of my head. I remember vscode-python hitting a similar issue where Python comments are often formatted as reStructuredText, which isn't the same as Markdown. Treating it like it's Markdown lead to formatting errors in some libraries. |
I am aware of the markdown syntax elements like ** or ~~ causing issues. We already have this problem in the hover widget. See #1486 But since that is a corner case, I am ok with both the hover and completion widgets having this problem. When we do find a solution, we can apply it to both widgets. |
@segevfiner You mentioned the below when I asked about the need for
I tested the case of symbol from same package, I don't get any docs... |
I do get them locally, but you have to save the file first as |
You found a bug. The problem is that the package import path likely ends with I guess we should handle the current package ( |
go doc prefers packages when given only a name without a package. So use go list to figure out the current package name instead of relying on the working directory. See microsoft#2054 (comment)
Using
go doc
instead ofgodoc
due to golang/go#25443 (plusgodoc
doesn't show doc for unexported identifiers nor for anything in a main package)go doc
doesn't seem to support giving the code of an unsaved file via stdin likegocode
, so it won't display documentation for unsaved changes.Fixes #194
cc @ramya-rao-a