therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.49k stars 748 forks source link

On OSX / VSCode, "Go to Definition" not working for me #163

Closed joeblew99 closed 7 years ago

joeblew99 commented 7 years ago

i am using VSCode on OSX.

i remember reading something about how to get QT golang to work with finding references. I use VSCode, and when i right click on an object and choose "Go to Definition", nothing happens. Mhh... Would be nice and make it quicker for me :)

i have the full QT 5.7 installed, rather than using brew. I think that is one of the prerequisites to have "go to definition" to work ?

Any ideas ?

https://github.com/therecipe/qt/issues/90 ?

joeblew99 commented 7 years ago

It seems that the golang extension for VSCode does "Go to Definition" (using gogetdoc or godef+godoc)

jordanorelli commented 7 years ago

I have this problem, too, but I don't think this is specific to VSCode. I'm using VSCode on Windows and Vim on OSX and I have this problem in both. Both rely on gocode internally, which presumably is choking on the size of the generated code. This isn't specific to this project; I've seen this with other projects, too.

Generally when I'm having this problem, I use "godoc" on the command line. E.g., "godoc github.com/therecipe/qt".

therecipe commented 7 years ago

Yes, code-autocompletion (and so probably definition lookup as well) is a bit buggy in some editors/IDEs.

The auto-completion issues for IntelliJ Idea and Neovim can be solved by editing the plugin settings, like it's documented here: https://github.com/therecipe/qt#code-editor-settings-for-code-completion

So I suspect, that the plugin(s) in VSCode simply timeout while waiting for godef, godoc or gocode

Another idea, would be to use QT_STUB to get smaller *.a archives from go install, so that the tools can work faster and therefore the plugins don't timeout.

But that's just speculation.

akamensky commented 7 years ago

@therecipe BTW, for IDEA the Custom VM Options is no longer valid... It freezes and chokes very often and indexing breaks half-way through. My settings on IDEA that worked perfectly fine are:

-Xms128m
-Xmx4000m
-XX:ReservedCodeCacheSize=512m
-XX:+UseCompressedOops

That is of course assuming the host has enough RAM. My current host has 8 GB, works quite okay without freezing etc.

therecipe commented 7 years ago

@akamensky Thanks for the info :) I will update the readme.

joeblew99 commented 7 years ago

I dont want to change to IDEA, and prefer VSCode. I will ask the maintinaer of the go extension to have a look at it.

joeblew99 commented 7 years ago

@therecipe can you see if this is a good idea ? https://github.com/rogpeppe/godef/issues/50#issuecomment-269972482

therecipe commented 7 years ago

@joeblew99 It's probably a good workaround, but the potential big problem I see is that there would be like 30% more generated Go code. Beside the problems to get this working with qtmoc and qtminimal. This makes go install probably even slower and also bumps the 8gb ram usage to 9gb maybe 10gb during the setup (for the widgets package).

edit: also there seems to be an open pr that solves this issue in godef https://github.com/rogpeppe/godef/pull/44

joeblew99 commented 7 years ago

Thanks for the reply. The golang plugin for VSCode was updated yesterday, so i tried this again.

Now i get typeahead as i type, showing the function call, but not showing the signature variables. So its slightly better.

For example: var window = widgets.NewQMainWindow(nil, 0) window.AcceptDrops()

When i type window., i get the list of functions.

But after i choose AcceptsDrops, i dont get any of the values its expects to be passed in. Also if i hover over the AcceptsDrops, to try to see the values it expects it just says loading and does nothing.

rogpeppe/godef#44 has been marked as fixed and closed.

what should we do ? We could raise an issue over at godef asking to try out therecipe/qt so they can reproduce it.

therecipe commented 7 years ago

maybe your example is a bit unfortunately selected as acceptDrops doesn't has parameters http://doc.qt.io/qt-5/qwidget.html#acceptDrops-prop

does it work for widgets.NewQMainWindow?

what should we do ? We could raise an issue over at godef asking to try out therecipe/qt so they can reproduce it.

As I said in the other issue, I'm currently working on reducing the binding code. I was able to reduce the (go) code by 75% for the "widgets" package, so maybe that solves the code-generation / godef / gocode issues.

Thats why I would like to wait until this is done, to see if it maybe solves this and the other (probably related) issues. If it however doesn't work after that, then we probably have no other chance than opening an issue over there.

therecipe commented 7 years ago

made the changes to the code-generator yesterday and now there should be a lot less Go code. could you try it again with the latest version?

you can also set QT_VERSION=5.7.0 and QT_DIR=path/to/Qt5.7.0, if you don't want to update to 5.8 yet. (as the update to 5.8 happened in the meantime as well)

joeblew99 commented 7 years ago

i just did a clean install of 5.8 qt and the repo.

is now worse then before :(

for example: github.com/therecipe/qt/internal/examples/grpc/hello_world/hello_world.go

package main

import (
    "os"

    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/quick"
)

//go:generate qtmoc
type HelloClientRPC struct {
    core.QObject

    _ func(string) []*core.QVariant `slot:"sayHello"`
    _ func() error                  `slot:"shutdown"`
}

type HelloClientFactory struct {
    core.QObject

    _ func(addr string) *HelloClientRPC `slot:"newClient"`
}

func main() {
    go serve()

    gui.NewQGuiApplication(len(os.Args), os.Args)

hovering over gui, showing the import overlay as it should. clicking over gui -->go to definition, goes to the import at the top as it should.

hovering over gui.NewQGuiApplication, does nothing clicking over gui.NewQGuiApplication -->go to definition works, does nothing.

typing gui.NewQAccessibleEvent, does bring up the functions list. But on choosing one, no function signature help happen.

Hope i have explained it enough ?

therecipe commented 7 years ago

Did you use rogpeppe/godef with rogpeppe/godef#44 or some fork?

joeblew99 commented 7 years ago

yes i think its using the master of rogpeppe/godef.

When you install the standand VSCode golang plugin it installs about 10 golang binaries. godef is one of them.

i am pretty sure its using the master version of godef. Here is the source code that kicks it off: https://github.com/Microsoft/vscode-go/blob/master/src/goInstallTools.ts

I tried deleting all my binary files in the golang bin, and the VSCode plugin asked to redownload it using: go get -v github.com/rogpeppe/godef

So i am not doing anything different from everyones install. I am have a pretty standard VSCode Prefs:

// Place your settings in this file to overwrite the default settings
{
    "editor.tabSize": 4,
    "editor.insertSpaces": false,
    "editor.detectIndentation": true,
    "go.buildOnSave": true,
    "go.lintOnSave": true,
    "go.vetOnSave": true,
    //"go.formatTool": "goreturns",
    "go.gocodeAutoBuild": false,
    // "files.autoSave": "onFocusChange",
    "files.autoSave": "onFocusChange",
    "files.autoSaveDelay": 1000,
    "git.confirmSync": false,
    "git.autorefresh": true,
    "vsicons.projectDetection.autoReload": true,
    "[go]": {

    }
}

After VSCode gets all the golang binaries installed i have:

/Users/apple/workspace/go/bin
x-MacBook-Pro:bin apple$ ls -al
total 157064
drwxr-xr-x  16 apple  staff       544 Feb 26 14:21 .
drwxr-xr-x   6 apple  staff       204 Oct 10 13:54 ..
-rw-r--r--@  1 apple  staff      6148 Feb 26 13:22 .DS_Store
-rwxr-xr-x   1 apple  staff   3103776 Feb 26 13:46 bolt
-rwxr-xr-x   1 apple  staff  10461508 Feb 26 13:47 glide
-rwxr-xr-x   1 apple  staff   2856160 Feb 26 14:20 go-outline
-rwxr-xr-x   1 apple  staff   3534208 Feb 26 14:20 go-symbols
-rwxr-xr-x   1 apple  staff  10413876 Feb 26 14:20 gocode
-rwxr-xr-x   1 apple  staff   5463296 Feb 26 14:21 godef
-rwxr-xr-x   1 apple  staff   5124448 Feb 26 14:21 golint
-rwxr-xr-x   1 apple  staff   1888080 Feb 26 14:20 gopkgs
-rwxr-xr-x   1 apple  staff   5407408 Feb 26 14:21 gorename
-rwxr-xr-x   1 apple  staff   5732432 Feb 26 14:21 goreturns
-rwxr-xr-x   1 apple  staff   7004912 Feb 26 14:21 gotests
-rwxr-xr-x   1 apple  staff   8147472 Feb 26 14:21 guru
-rwxr-xr-x   1 apple  staff  11240676 Feb 26 13:46 ponzu
therecipe commented 7 years ago

yes, they are using the (broken) master, using https://github.com/rogpeppe/godef/pull/44 however

diff --git a/go/parser/parser.go b/go/parser/parser.go
index b6bfef7..69e4cfe 100644
--- a/go/parser/parser.go
+++ b/go/parser/parser.go
@@ -1967,6 +1967,9 @@ func parseImportSpec(p *parser, doc *ast.CommentGroup, decl *ast.GenDecl, _ int)
        if declIdent == nil {
            filename := p.fset.Position(path.Pos()).Filename
            name, err := p.pathToName(litToString(path), filepath.Dir(filename))
+           if litToString(path) == "C" {
+               name = "C"
+           }
            if name == "" {
                p.error(path.Pos(), fmt.Sprintf("cannot find identifier for package %q: %v", litToString(path), err))
            } else {

made "go to definition" work for me.

I also got the function list somewhat working by:

  1. typing gui.NewQ
  2. hitting "enter"
  3. hitting "remove" until the Q suffix gets removed
  4. hitting Q

and the input parameter help seems to work as well.

So, there is definitely something wrong with how vsc makes the code-completion work. I would guess, there is a timeout and because there is to much code in core, gui, widgets the plugin will just stop, because it can't complete the request in the desired timeframe. That would explain why it's still working for smaller packages such as network, dbus, nfc, ...

After further investigation is seems that the file size limit is somewhere between 1.2mb and 1.5mb. As multimedia is working with 1.2mb, but core (1.5mb), gui (1.7mb) and widgets (2.9mb) are not working.

joeblew99 commented 7 years ago

thanks for looking into this deeper.

Geez so crappy of vscode.

I think that i need to change to another IDE.

What do you use ?

jeanlucmongrain commented 7 years ago

Intellij community edition + golang plug-in

joeblew99 commented 7 years ago

ok ta.

I am going to ry the new https://www.jetbrains.com/go/download/

Will report back ...

therecipe commented 7 years ago

I'm currently using Atom + go-plus ("go to definition" isn't working there for me as well, even with the patched godef). So I will probably go back to sublime text.

joeblew99 commented 7 years ago

i tried out gogland.

https://www.jetbrains.com/go/download/ works very well !

Setup it fast. Takes about 30 minutes to parse everything in the GOPATH to build an index. Until thats done, nothing really works.

The Intellisense is much much better. Did not have a problem with the c code.

It picked up lots of warnings in the code.

On the widgets.go file it blew up the intellisense buffer, giving a warning. I think there is a setting to expand that, but have not found that yet.

Really curious what you think... I really think its worth a shot

therecipe commented 7 years ago

Tested Gogland as well, and it works so far.

What I observed is, that the code-competition works without the need to install the packages with "go install", which is really nice. The other editors seems to use gocode and therefore depend on the *.a files created during "go install"

But the "go to definition" function, even though it works out of the box, is way slower for me then with vsc. And the code competition for the "widgets" package seems to be broken as well, but I got it working by using the IntelliJ Idea settings from: https://github.com/therecipe/qt#code-editor-settings-for-code-completion

joeblew99 commented 7 years ago

I tested LiteIDE, which is a golang IDE written in QT.

Its really nice actually.

I just had to tell is my goroot in the menu: "View" --> "Edit Current Environment".

I use homebrew to install go, and so all i had to do was give it the exact same thing i have in my .bash_profile:

# native compiler drawin amd64

# installed using: "brew install go"
GOROOT=/usr/local/opt/go/libexec
GOPATH=$HOME/workspace/go

PATH=$PATH:$GOROOT/bin
PATH=$PATH:$GOPATH/bin

#GOROOT=/usr/local/opt/go/libexec
#GOBIN=
#GOARCH=amd64
#GOOS=darwin
#CGO_ENABLED=1

#PATH=$GOROOT/bin:$PATH

LITEIDE_GDB=/usr/local/bin/gdb
LITEIDE_MAKE=make
LITEIDE_TERM=/usr/bin/open
LITEIDE_TERMARGS=-a Terminal
LITEIDE_EXEC=/usr/X11R6/bin/xterm
LITEIDE_EXECOPT=-e

So far its the fastest IDE i have used by far. Very easy on the eyes, and really nice tabs, and lots of extras that are smartly mapped ot the many go tools out there.

I would recommend trying it.

Also its works on all OS's.

therecipe commented 7 years ago

Yeah, I already have had experience with that one :) And it was great overall, but there was an exausting bug when I used it (2 years ago or so) that made it crash, when you pressed the wrong key combination. Sadly I can't exactly recall what it was, but it had something todo with ctrl or cmd on mac. And so I switched, but these things are probably sorted out by now, so I will maybe switch back.

joeblew99 commented 7 years ago

i have been using it for 5 days and all ok on OSX for me. No crashs. they did a release a few days ago, try it.

key bindings are not well done at the moment, and i raised a issue for it. my issues was that on a non english keyboard the keybindings conflict with the way you write a "[]" and {}. I fixed it by editting the key bindings myself for now.

so far this is easily the best IDE i have used for golang. debugging with DLV works too very well.

Its ironic that its using QT, but programmed in c :) I was seriously thinking about how easy a pot could be. Not that hard i think, but i am stopping my scope creepy self !!

On Tue, Mar 7, 2017 at 5:54 PM therecipe notifications@github.com wrote:

Yeah, I already have had experience with that one :) And it was great overall, but there was an exausting bug when I used it (2 years ago or so) that made it crash, when you pressed the wrong key combination. Sadly I can't exactly recall what it was, but it had something todo with ctrl or cmd on mac. And so I switched, but these things are probably sorted out by now, so I will maybe switch back.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/therecipe/qt/issues/163#issuecomment-284785291, or mute the thread https://github.com/notifications/unsubscribe-auth/ALcac2e8qBvquSFBl9f0_T6Pw_7YJi0cks5rjYvhgaJpZM4LXhQk .

therecipe commented 7 years ago

:D I will give it a try

joeblew99 commented 7 years ago

@therecipe Did you have time to try out lideIDE ?

Curious what you think ? For me its been clear sailing for everything and much more productive

therecipe commented 7 years ago

Yes, I had time to test it. It works great and as you said, you directly feel that it's way faster than the rest.

I will try to use it from time to time and maybe fully switch at some points, but currently I'm (too) used to Atom and its git integration. So I will need some time to acclimatize with LiteIDE.

joeblew99 commented 7 years ago

ok. This was originally about VSCOde and got highjacked along the way by me. I will close it, as my solution was to not use vscode anymore :)