fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16.01k stars 1.45k forks source link

<c+x><c+o> cann't autocomplete when package name not same to dir name #2280

Closed chew351 closed 5 years ago

chew351 commented 5 years ago

What did you do? (required: The issue will be closed when not provided)

main.go in dire foo

package main <--- not package foo

import "fmt"

func main() { fmt. fmt.Println("vim-go")

} func main() { fmt.Println("vim-go") fmt. } ~ ~ -- INSERT --

if package name is not same to dir, <c+x><c+o> was always match nothing that vim just goto INSERT mode if change package main to package foo under dir foo <c+x><c+o> work normally

What did you expect to happen?

when package name is not same to dir name vim-go can autocomplete via <c+x><c+o>

What happened instead?

when package name is not same to dir name vim just go to INSERT mode

Configuration (MUST fill this out):

vim-go version:

root@work:~/.vim/bundle/vim-go# git log commit c4b419db6c57125e91d6f292daa664b73b155b7b (HEAD -> master, origin/master, origin/HEAD) Author: Billie Cleek bhcleek@gmail.com Date: Mon May 6 18:33:16 2019 -0700

update CHANGELOG.md for #2269 and #2276

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc
let g:go_disable_autoinstall = 0

"let g:go_def_mode = 'godef'

let g:go_autodetect_gopath = 1

"let g:go_gocode_propose_builtins = 1
"let g:go_gocode_unimported_packages = 1
"let g:go_gocode_propose_source = 1

Vim version (first three lines from :version):

vim8.1 on ubuntu18

Go version (go version):

go1.12

Go environment

go env Output:
go version go1.12.4 linux/amd64
root@work:~/.vim/bundle/vim-go# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build097794409=/tmp/go-build -gno-record-gcc-switches"

bhcleek commented 5 years ago

This works for me. Have you updated gopls recently?

chew351 commented 5 years ago

Thanks for your reply!

I'm a fresh go programmer, I don't know how to get version of gopls, and I just git clone vim-go and GoInstallBinaries, following is the git log

commit d996b19ee77cd9c8df974510f23b0696cedf1ca1 (HEAD -> master, origin/master, origin/HEAD) Author: Dan Kortschak dan@kortschak.io Date: Thu May 9 11:10:16 2019 +0930

go/analysis/analysistest: fix word usage

Change-Id: Iec304e44375b0740b8bc594cfe6ce35637284555
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175939
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>

Regards chew

At 2019-05-10 01:09:55, "Billie Cleek" notifications@github.com wrote:

This works for me. Have you updated gopls recently?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

bhcleek commented 5 years ago

That looks like a fairly recent version of gopls. In that case, make sure your source file is below $GOPATH/src or is part of a module.

chew351 commented 5 years ago

Thank you very much for reply immediately.

move source code to $GOPATH/src, it works! and gopls can work with import relative path like import ./mypackage this can resolve issue

https://github.com/fatih/vim-go/issues/2281

Have a good night!

Regards chew

At 2019-05-10 12:15:30, "Billie Cleek" notifications@github.com wrote:

That looks like a fairly recent version of gopls. In that case, make sure your source file is below $GOPATH/src or is part of a module.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.