5

is is possible to use Revel framework with Go code completion support. As far as i know the gocode utility requires the code to be compiled into a library into a pkg subfolder in order to function, but the framework does compilation on the fly.

I am kind of lost on the topic. Would the proper way be calling the go install for relevant subpackages? That seems to work but it is not the most elegant way of doing this from my perspective.

Hope that someone can point me in right direction.

EDIT: the problem is focused only on sources that I write as part of my Revel application. Downloaded packages have autocompletion as expected

EDIT2: This is the best solution I have found so far - executing go get command on your project's app/tmp subfolder. So if your project is called my_project then you would call something like go get my_project/revel/app/tmp Because this folder contains the main function for the project, it will pull all the dependencies and build them into packages. If the tmp folder does not exist you have to do revel run on your project and open your web app so it gets created on the fly. Hope this helps at least a bit. I am still open for a better alternative :)

Rick-777
  • 9,714
  • 5
  • 34
  • 50
  • What are you using to write Go? Sublime Text + the GoSublime plugin, for example, uses packages installed on your GOPATH to provide "autocomplete" functionality when you add that to your package imports. Revel, being "go gettable", should work the same way. – elithrar Oct 30 '13 at 00:53
  • 1
    I am using LiteIDE, GOPATH is set to my workspace as usual. Packages that are installed using go get have autocompletion. Problem occurs when you start to write the Revel application. The sources I write are not compiled into pkg subfolder when I run the application so there are no autocompletion for my code. Sorry if that wasnt clear from the post, I will edit it to make the problem clear. – Dario Filipović Oct 30 '13 at 05:23

2 Answers2

0

You revel application needs to reside inside of your $GOPATH/src folder and then code completion will work for your web app.

  • It does reside in /src folder. 'gocode' utility does code completion based on *.a libraries created in /pkg subfolder and GOOS and GOARCH variables that define the subfolder in /pkg folder where the 'gocode will look into' – Dario Filipović Nov 13 '13 at 19:24
0

Update

Either the process of compilation by Revel's harness has changed or gocode has been improved. But everything works now out of the box. No additional efforts are required.

Old answer

I have faced the same problem. My solution is a modified version of your EDIT 2 workaround. In my app/init.go I added:

import "os/exec"

and

// Build the project packages on app start so it's possible to use autocomplete.
revel.OnAppStart(func() {
    if revel.Config.BoolDefault("mode.dev", false) {
        go func() {
            _, err := exec.Command("go", "get", "bitbucket.org/USERNAME/PROJECT/app/tmp").Output()
            if err != nil {
                revel.ERROR.Printf("failed to 'go get' project, error: %v", err)
            }
        }()
    }
})

So, now in dev mode it automatically recompiles all the packages on every recompilation of revel project.