New gocode plugin

550 views
Skip to first unread message

gmiller

unread,
Nov 2, 2010, 11:43:26 AM11/2/10
to goclipse
OK, The checkins are done. To try out the new gocode-based auto-
complete do the following:

* Download and install gocode from here: http://github.com/nsf/gocode
(installation instructions in the README). This will put the gocode
executable in your go/bin folder.
* svn update goclipse-n and import the new
"com.googlecode.goclipse.gocode" plugin into your workspace.
* Make sure gocode is running (gocode -s)
* Run the eclipse application
* Create a new project
* Create itworks.go in the cmd source folder with the following
content:

package main

import (
"fmt"
)

func main() {
fmt.
}

* put your cursor after the '.' and hit ctrl-space.

Adrian Mihalcea

unread,
Nov 2, 2010, 7:24:07 PM11/2/10
to gocl...@googlegroups.com
cool .. it works. I had to do some changes to gocode which is not by
default windows friendly. Attached is gocode.exe file which is
hardcoded to open port 9999 on localmachine. The weird extension is
because gmail does not allow sending exe. If there is any interest,
I'll do some more changes to it. For now, it works like this.

Also, to make things, I had to
- add the extension point in plugin.xml of goclipse
- do the following change in the com.googlecode.goclipse.gocode plugin

GoCodeClient.java, method getCompletions:
String ext = Environment.INSTANCE.getArch().getExecutableExt();
String cmd = Path.fromOSString(goroot).append("bin").append("gocode").toOSString();
ExternalCommand command = new ExternalCommand(cmd + ext);

which makes sure windows gets its exe extension.

Adrian

gocode.exe_

nsf

unread,
Nov 3, 2010, 12:43:15 AM11/3/10
to goclipse
On 2 ноя, 20:43, gmiller <graham.mil...@gmail.com> wrote:
> * Download and install gocode from here:http://github.com/nsf/gocode
> (installation instructions in the README).  This will put the gocode
> executable in your go/bin folder.

To be more exact this will put gocode executable into the $GOBIN dir,
which is $GOROOT/bin by default. For some time it was $HOME/bin by
default and as a result I'm sure there are people who has it that way
(me for example).

> * Make sure gocode is running (gocode -s)

You don't need to do that. When you're running gocode in client mode
it will make sure that there is a server up and running.



On 3 ноя, 04:24, Adrian Mihalcea <adrian.mihal...@gmail.com> wrote:
> cool .. it works. I had to do some changes to gocode which is not by
> default windows friendly. Attached is gocode.exe file which is
> hardcoded to open port 9999 on localmachine.

That's quite interesting, because Mac has problems with TempDir as
well
(I'm using TempDir for storing unix sockets). It would be nice to have
a more general patch that allows people to run 'gocode' using other
types of sockets than unix ones.

Btw, can anyone drop a screenshot of gocode in goclipse? Just curious
how it looks like there. :)

Adrian Mihalcea

unread,
Nov 3, 2010, 1:37:07 AM11/3/10
to gocl...@googlegroups.com
For the windows version I've changed things to use tcp Dial on the
client and ListenTCP on the server. This should be pretty generic on
all systems.
However gocode -s is required to run. I get an error when using the
client without previously starting the server. I did not have time to
look into it.

>
> Btw, can anyone drop a screenshot of gocode in goclipse? Just curious
> how it looks like there. :)

see attached.

gocodeInGoclipse.jpg

nsf

unread,
Nov 3, 2010, 2:35:19 AM11/3/10
to gocl...@googlegroups.com, adrian....@gmail.com
On Wed, 3 Nov 2010 07:37:07 +0200
Adrian Mihalcea <adrian....@gmail.com> wrote:
> For the windows version I've changed things to use tcp Dial on the
> client and ListenTCP on the server. This should be pretty generic on
> all systems.

I see, I'll look into it.

> However gocode -s is required to run. I get an error when using the
> client without previously starting the server. I did not have time to
> look into it.

I guess it's because client app expects gocode executable in $PATH. I'm
not sure how this will work on windows. Of course windows has $PATH
too, but as far as I remember it is not used a lot.

And maybe it should attach '.exe' as well when running executable.

So.. If you want to fix that, feel free to do this. I won't setup Go
environment on my windows machine, because windows is out of my
interests. Although I will make 'tcp' patch on my own.

>
> >
> > Btw, can anyone drop a screenshot of gocode in goclipse? Just curious
> > how it looks like there. :)
> see attached.

Nice :D

Adrian Mihalcea

unread,
Nov 3, 2010, 3:52:11 AM11/3/10
to gocl...@googlegroups.com, nsf
On Wed, Nov 3, 2010 at 8:35 AM, nsf <no.smi...@gmail.com> wrote:
> On Wed, 3 Nov 2010 07:37:07 +0200
> Adrian Mihalcea <adrian....@gmail.com> wrote:
>> For the windows version I've changed things to use tcp Dial on the
>> client and ListenTCP on the server. This should be pretty generic on
>> all systems.
>
> I see, I'll look into it.
>
>> However gocode -s is required to run. I get an error when using the
>> client without previously starting the server. I did not have time to
>> look into it.
>
> I guess it's because client app expects gocode executable in $PATH. I'm
> not sure how this will work on windows. Of course windows has $PATH
> too, but as far as I remember it is not used a lot.
>
> And maybe it should attach '.exe' as well when running executable.

I think a more generic approach could use the configuration stuff in
gocode or something similar instead of referring to system variables
directly in the code which are clearly different on different systems.
I'm not sure about Mac OS if it has exactly the same names for
variables as Linux, but Windows clearly does not have them in that
exact form.
So instead of going for $PATH or $HOME or other things like this, just
have them written somewhere by the user or an installer script. Even
the name of the app could be written somewhere with sensible defaults
or at least the extension that appears only in windows.

There are some building issues now in goclipse but as soon as they are
fixed I will try to write a guide on how to build gocode within
goclipse. At the moment I had to do some changes to the code itself
just for the sake of building with goclipse - changed main package to
"gocode" package - and they are too ugly to be made public.

>
> So.. If you want to fix that, feel free to do this. I won't setup Go
> environment on my windows machine, because windows is out of my
> interests. Although I will make 'tcp' patch on my own.
>

My experience with Go is rather scarce so I'll wait for your tcp
implementation. Anyway you know gocode's code better than anyone so
you would know what goes best and where. For now, the exe I've
generated is enough to use within goclipse on windows with the new
plugin Graham wrote.

Thanks for the great work.

>> >
>> > Btw, can anyone drop a screenshot of gocode in goclipse? Just curious
>> > how it looks like there. :)
>> see attached.
>
> Nice :D
>

Adrian

nsf

unread,
Nov 3, 2010, 3:54:30 AM11/3/10
to gocl...@googlegroups.com
On Wed, 3 Nov 2010 11:35:19 +0500
nsf <no.smi...@gmail.com> wrote:

> Although I will make 'tcp' patch on my own.

Done. Now you can run gocode with TCP socket. There are two
command-line options for that:
-sock=tcp
-addr=":37373"

The first one, "-sock=tcp", enables TCP socket code. The second one is
optional and lets you specify an address for listen function (server
mode) or an address for connection (client mode). By default it uses
just port 37373.

----------------------------------------------------------------------
[nsf @ ~]$ gocode -sock=tcp status
Server's GOMAXPROCS == 1

Package cache contains 1 entries

Listing these entries:
name: /home/nsf/go/pkg/linux_386/unsafe.a (default alias:
unsafe) imports 9 declarations and 0 packages
this package stays in cache forever (built-in package)


[nsf @ ~]$ netstat -tl | grep 37373
tcp 0 0 *:37373 *:* LISTEN
[nsf @ ~]$ gocode -sock=tcp close
[nsf @ ~]$ netstat -tl | grep 37373
----------------------------------------------------------------------

In order to close it as you can see, you should use "close" command
with "-sock=tcp" as well.

Anyways, I guess it provides the needed functionality. Maybe I will
move these things ("sock" and "addr") to the config file in future.

gmiller

unread,
Nov 3, 2010, 9:30:32 AM11/3/10
to goclipse
Hey nsf,
Thanks for being so responsive, and helping to get this working. And
of course thanks for gocode, it's awesome.

graham

On Nov 3, 3:54 am, nsf <no.smile.f...@gmail.com> wrote:
> On Wed, 3 Nov 2010 11:35:19 +0500
>

nsf

unread,
Nov 3, 2010, 9:43:13 AM11/3/10
to gocl...@googlegroups.com
On Wed, 3 Nov 2010 06:30:32 -0700 (PDT)
gmiller <graham...@gmail.com> wrote:

> Hey nsf,
> Thanks for being so responsive, and helping to get this working. And
> of course thanks for gocode, it's awesome.
>
> graham

Sure, np.

I'm interested in gocode integration to different editors, because it
will improve its quality. Therefore I'm ready to provide necessary
assistance.

So.. if there are any questions, you know my email. I'll keep an eye on
the goclipse and that mailing list in particular for a while. ;-)

Reply all
Reply to author
Forward
0 new messages