Coder Social home page Coder Social logo

gocode's Introduction

An autocompletion daemon for the Go programming language

IMPORTANT: This project is not maintained anymore, consider using https://pkg.go.dev/golang.org/x/tools/gopls, a tool which provides similar functionality and more, created and maintained by Go team.

Gocode is a helper tool which is intended to be integrated with your source code editor, like vim, neovim and emacs. It provides several advanced capabilities, which currently includes:

  • Context-sensitive autocompletion

It is called daemon, because it uses client/server architecture for caching purposes. In particular, it makes autocompletions very fast. Typical autocompletion time with warm cache is 30ms, which is barely noticeable.

Also watch the demo screencast.

Gocode in vim

Gocode in emacs

Setup

  1. You should have a correctly installed Go compiler environment and your personal workspace ($GOPATH). If you have no idea what $GOPATH is, take a look here. Please make sure that your $GOPATH/bin is available in your $PATH. This is important, because most editors assume that gocode binary is available in one of the directories, specified by your $PATH environment variable. Otherwise manually copy the gocode binary from $GOPATH/bin to a location which is part of your $PATH after getting it in step 2.

    Do these steps only if you understand why you need to do them:

    export GOPATH=$HOME/goprojects

    export PATH=$PATH:$GOPATH/bin

  2. Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:

    go get -u github.com/nsf/gocode (-u flag for "update")

    Windows users should consider doing this instead:

    go get -u -ldflags -H=windowsgui github.com/nsf/gocode

    That way on the Windows OS gocode will be built as a GUI application and doing so solves hanging window issues with some of the editors.

  3. Next steps are editor specific. See below.

Vim setup

Vim manual installation

Note: As of go 1.5 there is no $GOROOT/misc/vim script. Suggested installation is via vim-go plugin.

In order to install vim scripts, you need to fulfill the following steps:

  1. Install official Go vim scripts from $GOROOT/misc/vim. If you did that already, proceed to the step 2.

  2. Install gocode vim scripts. Usually it's enough to do the following:

    2.1. vim/update.sh

    update.sh script does the following:

    #!/bin/sh
    mkdir -p "$HOME/.vim/autoload"
    mkdir -p "$HOME/.vim/ftplugin/go"
    cp "${0%/*}/autoload/gocomplete.vim" "$HOME/.vim/autoload"
    cp "${0%/*}/ftplugin/go/gocomplete.vim" "$HOME/.vim/ftplugin/go"
    

    2.2. Alternatively, you can create symlinks using symlink.sh script in order to avoid running update.sh after every gocode update.

    symlink.sh script does the following:

    #!/bin/sh
    cd "${0%/*}"
    ROOTDIR=`pwd`
    mkdir -p "$HOME/.vim/autoload"
    mkdir -p "$HOME/.vim/ftplugin/go"
    ln -s "$ROOTDIR/autoload/gocomplete.vim" "$HOME/.vim/autoload/"
    ln -s "$ROOTDIR/ftplugin/go/gocomplete.vim" "$HOME/.vim/ftplugin/go/"
    
  3. Make sure vim has filetype plugin enabled. Simply add that to your .vimrc:

    filetype plugin on

  4. Autocompletion should work now. Use <C-x><C-o> for autocompletion (omnifunc autocompletion).

Using Vundle in Vim

Add the following line to your .vimrc:

Plugin 'nsf/gocode', {'rtp': 'vim/'}

And then update your packages by running :PluginInstall.

Using vim-plug in Vim

Add the following line to your .vimrc:

Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }

And then update your packages by running :PlugInstall.

Other

Alternatively take a look at the vundle/pathogen friendly repo: https://github.com/Blackrush/vim-gocode.

Neovim setup

Neovim manual installation

Neovim users should also follow Vim manual installation, except that you should goto gocode/nvim in step 2, and remember that, the Neovim configuration file is ~/.config/nvim/init.vim.

Using Vundle in Neovim

Add the following line to your init.vim:

Plugin 'nsf/gocode', {'rtp': 'nvim/'}

And then update your packages by running :PluginInstall.

Using vim-plug in Neovim

Add the following line to your init.vim:

Plug 'nsf/gocode', { 'rtp': 'nvim', 'do': '~/.config/nvim/plugged/gocode/nvim/symlink.sh' }

And then update your packages by running :PlugInstall.

Emacs setup

In order to install emacs script, you need to fulfill the following steps:

  1. Install auto-complete-mode

  2. Copy emacs/go-autocomplete.el file from the gocode source distribution to a directory which is in your 'load-path' in emacs.

  3. Add these lines to your .emacs:

    (require 'go-autocomplete)
    (require 'auto-complete-config)
    (ac-config-default)
    

Also, there is an alternative plugin for emacs using company-mode. See emacs-company/README for installation instructions.

If you're a MacOSX user, you may find that script useful: https://github.com/purcell/exec-path-from-shell. It helps you with setting up the right environment variables as Go and gocode require it. By default it pulls the PATH, but don't forget to add the GOPATH as well, e.g.:

(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize)
  (exec-path-from-shell-copy-env "GOPATH"))

Options

You can change all available options using gocode set command. The config file uses json format and is usually stored somewhere in ~/.config/gocode directory. On windows it's stored in the appropriate AppData folder. It's suggested to avoid modifying config file manually, do that using the gocode set command.

gocode set lists all options and their values.

gocode set <option> shows the value of that option.

gocode set <option> <value> sets the new value for that option.

  • propose-builtins

    A boolean option. If true, gocode will add built-in types, functions and constants to autocompletion proposals. Default: false.

  • lib-path

    A string option. Allows you to add search paths for packages. By default, gocode only searches $GOPATH/pkg/$GOOS_$GOARCH and $GOROOT/pkg/$GOOS_$GOARCH in terms of previously existed environment variables. Also you can specify multiple paths using ':' (colon) as a separator (on Windows use semicolon ';'). The paths specified by lib-path are prepended to the default ones.

  • autobuild

    A boolean option. If true, gocode will try to automatically build out-of-date packages when their source files are modified, in order to obtain the freshest autocomplete results for them. This feature is experimental. Default: false.

  • force-debug-output

    A string option. If is not empty, gocode will forcefully redirect the logging into that file. Also forces enabling of the debug mode on the server side. Default: "" (empty).

  • package-lookup-mode

    A string option. If go, use standard Go package lookup rules. If gb, use gb-specific lookup rules. See https://github.com/constabulary/gb for details. Default: go.

  • close-timeout

    An integer option. If there have been no completion requests after this number of seconds, the gocode process will terminate. Defaults to 1800 (30 minutes).

  • unimported-packages

    A boolean option. If set to true, gocode will try to import certain known packages automatically for identifiers which cannot be resolved otherwise. Currently only a limited set of standard library packages are supported. Default: false.

  • partials

    A boolean option. If set to false, gocode will not filter autocompletion results based on entered prefix before the cursor. Instead it will return all available autocompletion results viable for a given context. Whether this option is set to true or false, gocode will return a valid prefix length for output formats which support it. Setting this option to a non-default value may result in editor misbehaviour. Default: true.

  • ignore-case

    A boolean option. If set to true, gocode will perform case-insensitive matching when doing prefix-based filtering. Default: false.

  • class-filtering

    A boolean option. Enables or disables gocode's feature where it performs class-based filtering if partial input matches corresponding class keyword: const, var, type, func, package. Default: true.

Debugging

If something went wrong, the first thing you may want to do is manually start the gocode daemon with a debug mode enabled and in a separate terminal window. It will show you all the stack traces, panics if any and additional info about autocompletion requests. Shutdown the daemon if it was already started and run a new one explicitly with a debug mode enabled:

gocode close

gocode -s -debug

Please, report bugs, feature suggestions and other rants to the github issue tracker of this project.

Developing

There is Guide for IDE/editor plugin developers.

If you have troubles, please, contact me and I will try to do my best answering your questions. You can contact me via email. Or for short question find me on IRC: #go-nuts @ freenode.

Misc

  • It's a good idea to use the latest git version always. I'm trying to keep it in a working state.
  • Use go install (not go build) for building a local source tree. The objects in pkg/ are needed for Gocode to work.

gocode's People

Contributors

adamfaulkner avatar antifuchs avatar bad-ptr avatar bradwright avatar contextualist avatar danielmorsing avatar dougm avatar ebfe avatar fumiyas avatar ghiden avatar kodx avatar mattn avatar mikelikespie avatar mk0x9 avatar myitcv avatar negronjl avatar nhooyr avatar nicot avatar nrvnrvn avatar nsf avatar purcell avatar ryboe avatar sergey-shambir avatar syohex avatar tiziano88 avatar vanackere avatar wilfred avatar wmji avatar yasuyk avatar zchee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocode's Issues

Anonymous field as a child don't get proposed

If a type contains an anonymous field, methods of that field are being proposed, but not the field itself.

Example:
var hosts struct {
sync.Mutex
data map[string][]string
time int64
path string
}

Methods of sync.Mutex are being proposed, but not the Mutex field itself. It is legal to access that field directly, e.g.: hosts.Mutex.Lock()

gocode compile error

hi all!
i get error when i try to make install gocode:

gocode$ make install
8g -o go.8 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
gocode.go:288: undefined: os.ProcAttr
gocode.go:289: not enough arguments in call to os.StartProcess
autocompletefile.go:239: lastCursorAfter.List undefined (type ast.CaseClause has no field or method List)
autocompletefile.go:240: lastCursorAfter.List undefined (type *ast.CaseClause has no field or method List)
make: *
* [go.8] Error 1

go$ hg identify
b84e614e2516 weekly/weekly.2011-03-28

2.6.35-25-generic #44-Ubuntu

help plz!

GOPATH support?

Hello,

You've got support in gocode for setting a lib-path in a config file, and support
for automatically picking up GOROOT and piecing together the path to the
pkg/${GOOS}_${GOARCH} directory.

I was wondering if you've considered adding in support for GOPATH, the new
variable used by goinstall to allow the separation of the go src tree from local
packages?

For example, gocode might check for lib-path, then fall back to checking for
GOPATH, and finally fall back to checking for GOROOT.

Jim

Compilation Error

OS: Ubutnu 10.10 amd64
COMPILER: 6g version release.r57.2 8306

I got this error

6g -o go.6 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
os_posix.go:14: undefined: os.Signal
os_posix.go:19: undefined: os.SIGINT
os_posix.go:19: undefined: os.SIGTERM
make: *** [go.6] Error 1

Autocompletion ignores unexported anonymous fields

A good example for that is reflect.*Value types. Autocompletion proposal on these doesn't include corresponding Value interface.

This bug is related to the type embedding. It caused by the fact that I intentionally ignore all unexported fields in imported modules (should fix that).

Doesn't compile

GOARCH=amd64
GOOS=linux

gocode version: aad94f
go version:
$ 6v -V
6g version 5777+

$ make install
gomake -C goremote
make[1]: Entering directory /home/temoto/src/gocode/goremote' /home/temoto/bin/6g -o _go_.6 goremote.go /home/temoto/bin/6l -o goremote _go_.6 make[1]: Leaving directory/home/temoto/src/gocode/goremote'
./goremote/goremote server.go > rpc.go
gomake -C goconfig
make[1]: Entering directory /home/temoto/src/gocode/goconfig' /home/temoto/bin/6g -o _go_.6 configfile.go configfile.go:307: cannot use perm (type uint32) as type int in function argument make[1]: *** [_go_.6] Error 1 make[1]: Leaving directory/home/temoto/src/gocode/goconfig'
make: *** [configfile.a] Error 2

Could you tag and/or branch against go release tags?

Would you consider tagging your repository with names that match the go tags?

I know that the go source is in hg and gocode is in git, but if you could have some indication which release you've built against, that would be really helpful.

Type detection for :=

Could it be possible to detect the type with :=?

a := myfunc() should be form the type of return of the function.

Regards

config.go compilation problem.

config.go:107: invalid operation: nm == name (mismatched types reflect.StructTag and string)
config.go:179: cannot use name (type reflect.StructTag) as type string in function argument

Go's been updated so that tags on fields are not simple strings, but encoded key-value pairs.

type Foo struct {
bar int "This is not a description"
baz int "desc": "This is a correct tag"
}

The first tag cannot be retrieved from the reflection API.

Using gocode from command-line

Hi,

I'm interested in providing autocomplete support for the SciTE editor. Passing the current cursor position and file, and parsing the output for a drop-down is not likely to be difficult. But I have hit an immediate snag: I always get a panic in the server by invoking 'gocode autocomplete full-path-to.go cursor-pos' directly.

This appears in ripper.go, line 40, presumably out of range on the slice there.

(Using the latest Go release )

steve d.

vim as submodule

Feel free to ignore this suggestion, but many people use things like pathogen to manage their vim bundles and it helps to be able to point a git submodule to a folder that has just the vim code. It would be nice if your vim folder was a submodule of a branch of gocode so that people can submodule gocode into their vim bundles without having to change anything.

I did an example of what I mean in my fork:
https://github.com/doug/gocode

Which as an example I submodule into something like this:
https://github.com/doug/vimfiles

If there is a better way to do this I'm all ears.

Compilation problem

I am trying to compile the code, but once I download gocode, I get an error:

$ cd gocode
$ make
Makefile:1: /src/Make.inc: No such file or directory
Makefile:24: /src/Make.cmd: No such file or directory
make: *** No rule to make target `/src/Make.cmd'. Stop.

How can I compile the code?

build problem

Hi,
in your last commit you changed the following:

_, err = os.ForkExec(path, args, os.Environ(), "", []_os.File{nil, nil, nil})
to:
_, err = os.StartProcess(path, args, os.Environ(), "", []_os.File{nil, nil, nil})

Now i get a error at line 270:
gocode.go:270: undefined: os.StartProcess

I still works with the old pice of code.

Moddus

Splitting vim configuration out of gocode

I would find it useful for the vim configuration to be installable by pathogen. I believe the vim/ directory just needs to be split out to a top level directory.

Regards,
Ryan

PANIC PANIC PANIC

In following code, and cursor at //

package main

type Foo struct {
    Boo func();
    Baz string;
}

func foo() *Foo {
    return &Foo {}
}

func main() {
    foo(). // type CTRL-X CTRL-O in vim
}

it make candidate PANIC PANIC PANIC

Broken for weekly.2011-04-27

It is broken, and it cannot be fixed with gofix. I don't have time to do that. What's more sadly, it's broken because of the change in packages format, my parser simply cannot parse Go's libraries anymore. Suddenly in interfaces there are entries like:

"reflect".common() *"reflect".commonType

And it doesn't make sense to me. Frankly, I don't want to know, since I don't use Go anymore.

Feel free to fix it by yourself or better fork gocode and maintain it.

PANIC when completing in vim

Hi,

First of all I'd like to say I'm completely new to go, so apologies if this report is stupid. I just find your package so nice that I really want to use it!

Anyways, I get "PANIC" as the only suggestion when completing from vim. Using gocode -s gives the following trace:

[joel@mouton test]$ gocode -s
panic: expected "@", got String ("""")
1(runtime.panic): /build/src/release-build/src/pkg/runtime/proc.c:1235
2(main.(_gcParser).error): /home/joel/workspace/gocode/package.go:256
3(main.(_gcParser).errorf): /home/joel/workspace/gocode/package.go:260
4(main.(_gcParser).expect): /home/joel/workspace/gocode/package.go:267
5(main.(_gcParser).parseExportedName): /home/joel/workspace/gocode/package.go:331
6(main.(_gcParser).parseConstDecl): /home/joel/workspace/gocode/package.go:648
7(main.(_gcParser).parseDecl): /home/joel/workspace/gocode/package.go:803
8(main.(_gcParser).parseExport): /home/joel/workspace/gocode/package.go:832
9(main.(_PackageFileCache).processPackageData): /home/joel/workspace/gocode/package.go:131
10(main.(*PackageFileCache).updateCache): /home/joel/workspace/gocode/package.go:89
11(main._func_008): /home/joel/workspace/gocode/autocompletecontext.go:283
12(runtime.goexit): /build/src/release-build/src/pkg/runtime/proc.c:246

panic: One of the package cache updaters panicked
1(runtime.panic): /build/src/release-build/src/pkg/runtime/proc.c:1235
2(main.updatePackages): /home/joel/workspace/gocode/autocompletecontext.go:291
3(main.(_AutoCompleteContext).updateCaches): /home/joel/workspace/gocode/autocompletecontext.go:159
4(main.(_AutoCompleteContext).Apropos): /home/joel/workspace/gocode/autocompletecontext.go:209
5(main.Server_AutoComplete): /home/joel/workspace/gocode/server.go:82
6(main.(_RPCRemote).RPCServer_AutoComplete): /home/joel/workspace/gocode/rpc.go:27
7(reflect.internalValue.call): /build/src/release-build/src/pkg/reflect/value.go:583
8(reflect.Value.Call): /build/src/release-build/src/pkg/reflect/value.go:433
9(rpc.(_service).call): /build/src/release-build/src/pkg/rpc/server.go:341
10(runtime.goexit): /build/src/release-build/src/pkg/runtime/proc.c:246

I'm using go r60 as packaged by Arch Linux, and the git version of your package. Any idea what might be wrong?

Compile error

$GOOS = linux
$GOARCH = 386

The error:

~/src/gocode$ make install
gomake -C goremote
make[1]: Entering directory /home/ali/src/gocode/goremote' 8g -o _go_.8 goremote.go goremote.go:19: undefined: reflect.Typeof make[1]: *** [_go_.8] Error 1 make[1]: Leaving directory/home/ali/src/gocode/goremote'
make: *** [goremote/goremote] Error 2

And compiler version:

~/src/gocode$ 8g -V
8g version weekly.2011-04-13 8238

Unicode characters are not handled properly

I am using gocode via GoSublime, but I've tested this out by running gocode manually as well.

Consider the following program:

package main

import (
  "os"
)

// U+03C0: π
func main() {
  os.
}

If I ask gocode for autocomplete suggestions at position 65 (right after 'os.') it returns
[2, [{"class": "package", "name": "os", "type": ""}]]

If I ask gocode for autocomplete suggestions at position 66 (the next line, right before the '}') it returns everything from the os package. If the 'π' is replaced by any ASCII character the autocomplete returns all of this at position 65 as expected.

lib-path

lib-path merely overrides path to library.
adding path to packages would be great.
something like

$gocode set lib-path "/my/package/A/path;my/package/B/path" etc.

and just adding this paths to the search.

Unable to install using goinstall

Trying to install gocode using goinstall, one gets the following error message:

$ goinstall github.com/nsf/gocode
goinstall: : path "~/configfile" not inside a GOPATH

make install fails on Mac OS X 10.66

When running make install, I am getting

make install
6g -o go.6 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
config.go:4: import /Users/Jacob/gocode/configfile.a: object is [darwin amd64 release.r56 7666] expected [darwin amd64 release.2011-03-07 7666]
make: *** [go.6] Error 1

I updated the go compiler to the latest version as well as the gocode source.
I am not so keen on make files. Can someone help me out?

compilation fails with release.2010-12-15.1

~/gocode$ make install
gomake -C goremote
make[1]: Entering directory /home/xxx/gocode/goremote' 6g -o _go_.6 goremote.go goremote.go:221: undefined: token.NewFileSet goremote.go:222: cannot use nil as uint goremote.go:222: cannot convert nil to type uint goremote.go:222: cannot use nil as type uint in function argument goremote.go:222: too many arguments to function call make[1]: *** [_go_.6] Error 1 make[1]: Leaving directory/home/xxx/gocode/goremote'
make: *** [goremote/goremote] Error 2

I can use gocode with vim

Hi friend:

I been following all of steps for configure gocode with editor vim , and it not works.

only shows i.e. if I write "pack" then presents "package",

but if write "fmt." (not shows nothing)

any idea?

Can't build on Mac OS X 10.6.4

Hi,
when I run make, I get this:
make
gomake -C goremote
6l -o goremote go.6
panic: asmand: bad address (GS)
panic: asmand: bad address (GS)
schedinit: asmand: bad address 8(GS)
schedinit: asmand: bad address 8(GS)
schedinit: asmand: bad address 8(GS)
goexit: asmand: bad address (GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
nextgandunlock: asmand: bad address 8(GS)
mstart: asmand: bad address (GS)
mstart: asmand: bad address 8(GS)
mstart: asmand: bad address 8(GS)
mstart: asmand: bad address 8(GS)
too many errors
make[1]: *** [goremote] Error 1
make: *** [goremote/goremote] Error 2

I'm running Mac OS X 10.6.4, with the latest go from the repository.

two suggestions(Sorry,didn't find a place to post suggestions)

First of all,thank you for fantastic work.
Eclipse+gocode is used here.Two suggestions:
1,After picking a suggested entry,parentheses should be added automatically.
2,Handle case issue.I mean,when type 'p',both suggestions that begins with 'P' and 'p' should be shown,of course,sorting them.And if no suggestions begins with 'p',show entries begins with 'P'...

Makefile only works with GNU make

OK, this actually is not a bug, but it would be great if you could mention it in the README file somehow - there are systems out there, where make is not the GNU one (e. g. FreeBSD). On these systems, gmake install would be the correct invocation.

Compiler error when installing gocode on Mac Os X

I get the following error message when trying to compile gocode on Mac Os X, 10.6 snow leopard, mac book pro.

6g -o go.6 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
gocode.go:288: undefined: os.ProcAttr
gocode.go:289: not enough arguments in call to os.StartProcess
autocompletefile.go:239: lastCursorAfter.List undefined (type ast.CaseClause has no field or method List)
autocompletefile.go:240: lastCursorAfter.List undefined (type *ast.CaseClause has no field or method List)
make: *
* [go.6] Error 1

I have checked the paths etc.

Error 'undefined: os.ProcAttr' running make install.

I get the following error when running make install.

8g -o go.8 goremote.go
8l -o goremote go.8
make[1]: Leaving directory /home/dave/gocode/goremote' ./goremote/goremote server.go | gofmt > rpc.go gomake -C goconfig make[1]: Entering directory/home/dave/gocode/goconfig'
8g -o go.8 configfile.go
rm -f _obj/configfile.a
gopack grc _obj/configfile.a go.8
make[1]: Leaving directory `/home/dave/gocode/goconfig'
cp goconfig/_obj/configfile.a .
8g -o go.8 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
gocode.go:288: undefined: os.ProcAttr
gocode.go:289: not enough arguments in call to os.StartProcess
autocompletefile.go:239: lastCursorAfter.List undefined (type ast.CaseClause has no field or method List)
autocompletefile.go:240: lastCursorAfter.List undefined (type *ast.CaseClause has no field or method List)
make: *
* [go.8] Error 1

I'm using GNU make 3.81. Fresh install of go.

Let me know if you need any more information.

Panic in filePackageName when directory has `.go` extension

While doing autocomplete within certain files, sometimes it would fail by just supplying PANIC as the only completion. Here is an example with fmt:
package main

import (
    "fmt"
)

func main() {
    fmt.PANIC
    println("Hello, world!")
}

Here is the error as reported by gocode -s:
panic: runtime error: invalid memory address or nil pointer dereference
1(runtime.panic): /Users/sday/go/src/pkg/runtime/proc.c:1010
2(runtime.panicstring): /Users/sday/go/src/pkg/runtime/runtime.c:86
3(runtime.sigpanic): /Users/sday/go/src/pkg/runtime/darwin/thread.c:460
4(main.filePackageName): /Users/sday/go/gocode/autocompletecontext.go:398
5(main.findOtherPackageFiles): /Users/sday/go/gocode/autocompletecontext.go:387
6(main.getOtherPackageFiles): /Users/sday/go/gocode/autocompletecontext.go:332
7(main._AutoCompleteContext·updateCaches): /Users/sday/go/gocode/autocompletecontext.go:153
8(main._AutoCompleteContext·Apropos): /Users/sday/go/gocode/autocompletecontext.go:208
9(main.Server_AutoComplete): /Users/sday/go/gocode/server.go:85
10(main._RPCRemote·RPCServer_AutoComplete): /Users/sday/go/gocode/rpc.go:25
11(reflect._FuncValue·Call): /Users/sday/go/src/pkg/reflect/value.go:817
12(rpc.*service·call): /Users/sday/go/src/pkg/rpc/server.go:335
13(runtime.goexit): /Users/sday/go/src/pkg/runtime/proc.c:142

The problem arises when one has a directory named with the extension .go in the current directory:

$ ls -l
total 8
drwxr-xr-x  2 sday  staff  68 Dec  5 12:36 somedir.go
-rw-r--r--  1 sday  staff  73 Dec  5 12:36 test.go

In this case, parser.ParseFile returns nil, with an error and the daemon panics when trying to dereference the nil value. A simple fix like this solved the problem:
diff --git a/autocompletecontext.go b/autocompletecontext.go
index 7e3b8dd..aeb9a0b 100644
--- a/autocompletecontext.go
+++ b/autocompletecontext.go
@@ -395,7 +395,13 @@ func findOtherPackageFiles(filename, packageName string) []string {
}

 func filePackageName(filename string) string {
-       file, _ := parser.ParseFile(filename, nil, parser.PackageClauseOnly)
+       file, err := parser.ParseFile(filename, nil, parser.PackageClauseOnly)
+
+    if err != nil {
+        fmt.Printf("Error parsing %s: %v\n", filename, err)
+        return ""
+    }
+
        return file.Name.Name
 }

However, you may want to not even pass directories to this function.

don't handle Chinese correctly

I am not sure whether this is a gocode issue.I am using eclipse+goclipse.
I have a struct

type Struct1 struct {
Content string
Action string
}


1 s:=new(Struct1)
2 s.Content="花大把时间精力,金钱学习Oracle" <----Chinese
3 s.Action="SUPPORT"


For above code snippet(same package with Struct1),in line 3,"s."---->ctrl+space,nothing got popuped,but if switch line3 with line2,everything works fine.I have checked,in a page(or a go file),not only a function,once Chinese comes up,gocode doesn't work after this line.

Got errors when make install

I use “8g version weekly.2011-03-15 7807” to make the gocode.
But I got:

8g -o go.8 gocode.go autocompletefile.go package.go autocompletecontext.go server.go rpc.go decl.go apropos.go scope.go ripper.go config.go declcache.go os_posix.go
autocompletefile.go:230: undefined: ast.TypeCaseClause
autocompletefile.go:232: undefined: ast.TypeCaseClause
autocompletefile.go:246: typechecking loop
make: *** [go.8] error 1

allow gorun hashbang

it would be cool if gocode could ignore the
#!/usr/bin/gorun
line, so that it works with gorun scripts.
As there exists an alternative to gorun maybe it would be good just to ignore #!/bin/ when it's in the first line.

Does not compile

6g version weekly.2011-04-04 8081
GOOS=darwin
GOARCH=amd64

6g -o go.6 configfile.go
configfile.go:256: too many arguments in call to os.Open
configfile.go:307: undefined: os.O_CREAT
configfile.go:307: too many arguments in call to os.Open
make[1]: *** [go.6] Error 1
make: *** [configfile.a] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.