Skip to content
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

GoDoc doesn't properly find documentation #332

Closed
tgrosinger opened this issue Feb 24, 2015 · 14 comments · Fixed by #782
Closed

GoDoc doesn't properly find documentation #332

tgrosinger opened this issue Feb 24, 2015 · 14 comments · Fixed by #782
Labels

Comments

@tgrosinger
Copy link
Contributor

I have vim-go fully installed and my $GOPATH contains everything needed for a full build of my package. It does reference a few different directories though.

When I try to run :GoDoc on anything other than standard package items I receive:

2015/02/24 15:07:24 open /usr/local/go/src/db.Db: no such file or directory

Where db.Db is the package of the item I was hovering over.

Additionally, when running :GoDocBrowser I get referred to https://godoc.org/db.Db#Select which of course does not actually exist. Did I miss something that will give GoDoc the information I need? Is there a way to refer it to a running instance of GoDoc -http

Let me know if I can provided more helpful information about my setup. Thank you

@fatih fatih added the bug label Feb 26, 2015
@fatih
Copy link
Owner

fatih commented Feb 26, 2015

Can you give an example file so I can test on it. :GoDoc command definitely needs some work and it's not perfect.

@tgrosinger
Copy link
Contributor Author

Yeah, of course. Also I am particularly interested in using the :GoDocBrowser command to connect to a running instance of GoDoc -http

So, a minimal replication of my setup:

  1. Create a new go/src/company outside of your $GOPATH
  2. export GOPATH=/path/to/new/go/src/company:$GOPATH
  3. Make a directory "models" and put these contents in a file called "application.go" (looks pretty weird, I know, but it gives you something to try to look up):
package models

type ApplicationManager struct {}
type ApplicationPageManager struct {
    page        string
    application ApplicationManager
}
type ApplicationAlertManager struct {
    alert       string
    application ApplicationManager
}

Put the mouse over one of the struct types and attempt to open in GoDoc. Should fail with the error mentioned above.

@fatih
Copy link
Owner

fatih commented Mar 1, 2015

If you are already inside the source code, there is not much Godoc can do. We can surely optimize the outcome here. But I've tried your steps and created an example.go main file like this:

package main

import (
    "company/models"
    "fmt"
)

func main() {
    a := models.ApplicationPageManager{}

    fmt.Printf("a = %+v\n", a)
}

When I put my cursor on top of ApplicationPageManager and invoke :GoDoc everything seems to be fine:

image

However if you try :GoDocBrowser it will fail, because :GoDocBrowser connects to godoc.org instead of your local GoDoc server. We can introduce a variable which would change the godoc server. I've tested it quickly and it would look like:

image

Is this what you want? If yes I can work on adding an option to use :GoDocBrowser. If not could you please provide more information because I couldn't reproduce it with the command :GoDoc.

Thanks

@tgrosinger
Copy link
Contributor Author

Hmm, not sure why it wasn't reproducable. Here is another thing to try.
Change the struct to this:

type ApplicationPageManager struct {
    page        PageManager
    application ApplicationManager
}

Then create another file called page.go (but the same package) and put in this struct:

type PageManager struct {}

But yes, a variable specifying the host to use for GoDoc would be awesome. There are some cool flags you can enable on a local GoDoc server that the main one does not have.

@fatih
Copy link
Owner

fatih commented Mar 7, 2015

I can't follow your question. As described above I could open the doc inside the company folder. I think you are misusing it somehow. Can you give more details what to do once I've created the page.go file? Please give more info, possible with more steps so I can reproduce it. Based on your report I couldn't do it, so it's getting hard for me to follow it.

@metal3d
Copy link

metal3d commented Apr 3, 2015

I've got exactly the same issue.

I've created an application in $GOPATH/src/website

Wherever I try to call ":GoDoc" I've got the same error:

2015/04/03 19:17:23 open /home/patachou/go/src/package: no such file or directory
2015/04/03 19:17:28 open /home/patachou/go/src/type: no such file or directory

and so on... note that "package", or "type" is the text under cursor... That exactly the same with my packages inside the project.
My GOPATH is /home/patachou/goprojects

Running godoc in terminal is ok...

EDIT: I tried to change my GOPATH to point on /home/patachou/goprojects/website too, same problem

@igungor
Copy link

igungor commented Apr 27, 2015

I'm experiencing a problem with GoDoc too but I'm not sure if this bug is correlated with mine.

Here is a simplified snippet: http://play.golang.org/p/Hlx7RttH7l. Put the cursor on "Peek" and call :GoDoc. Error message is

No documentation found for "s.r".

If it is a different problem, I can file a different issue.

@ivulfson
Copy link

I also wanted this, since I'm running godoc daemon on my box. I ended up patching my copy of doc.vim to change its behaviour:

diff --git a/autoload/go/doc.vim b/autoload/go/doc.vim
index 3291026..1bb48b4 100644
--- a/autoload/go/doc.vim
+++ b/autoload/go/doc.vim
@@ -89,7 +89,8 @@ function! go#doc#OpenBrowser(...)
     let exported_name = pkgs[1]

     " example url: https://godoc.org/github.com/fatih/set#Set
-    let godoc_url = "https://godoc.org/" . pkg . "#" . exported_name
+    "let godoc_url = "https://godoc.org/" . pkg . "#" . exported_name
+    let godoc_url = "http://" . hostname() . ":6060/pkg/" . pkg . "#" . exported_name
     call go#tool#OpenBrowser(godoc_url)
 endfunction

@ivulfson
Copy link

(it's be nice to be able to make this change via an option in ~/.vimrc file)

@zmb3
Copy link
Contributor

zmb3 commented Mar 23, 2016

I wrote a tool that uses go/types to get documentation, which may be useful to you here. It may need some work yet before it's ready for integration, but I'd be happy to work with you on this.

There's even a blog post showing how it handles several cases that vim-go currently chokes on: https://zmb3.github.io/post/gogetdoc/

@jzacsh
Copy link

jzacsh commented Mar 27, 2016

tl;dr someone w/enough VimL-foo, can update pkg in s:godocWord() of doc.vim to ask oracle instead

If cursor's word is passed to golang's oracle first to determine "package", I think this will be solvable inline in the current autoload/go/doc.vim. Here's what I've learned:

$ go get golang.org/x/tools/cmd/oracle

In the below, my/file/path:#342 is the byte position 342 on that file where i have imported github.com/stretchr/testify/assert and my cursor is on Equals of an expression assert.Equals

$ oracle -format plain -pos="my/file/path:#342" definition
  your-go-path/src/github.com/stretchr/testify/assert/assertions.go:261:6: defined here as func github.com/stretchr/testify/assert.Equal(t github.com/stretchr/testify/assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
$ godoc "$(dirname your-go-path/src/github.com/stretchr/testify/assert/assertions.go)"
# success!

@fatih
Copy link
Owner

fatih commented Mar 28, 2016

@jzacsh thanks for the feedback. Your solution requires two roundtrips and will increase the UI latency. This needs to be done in one single query. @zmb3 has a great tool that does it already (and I've also wanted to use something like that already. But my original plan was to use oracle's new definition to provide the necessary documentation. That would make it really useful and would minimize the number of tools required.

@fatih fatih mentioned this issue Apr 2, 2016
@fatih
Copy link
Owner

fatih commented Apr 2, 2016

Hi everyone, please try #782 which uses @zmb3 new excellent tool called gogetdoc. It solves most of our problem here. Just call :GoDoc and it should show the documentation for the identifier under the cursor. Hit esc or enter to close the window easily.

@igungor
Copy link

igungor commented Apr 3, 2016

#782 definitely solves the problem I had (#332 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants