fatih / vim-go

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

unknown directive: toolchain #3595

Closed JamesTiberiusKirk closed 11 months ago

JamesTiberiusKirk commented 11 months ago

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

What did you expect to happen?

I've seen the other issue opened suggesting to do a GoUpdateBinary. That did not seem to work for me. Also this all seems to work fine in vscode. So i suppose its not gopls or go itslef?

What happened instead?

Configuration (MUST fill this out):

return {
  {
    "fatih/vim-go",
    lazy = false,
    init = function()
      vim.cmd("let g:go_fmt_command = 'goimports'")
      vim.cmd("au BufRead,BufNewFile *.html set filetype=gohtmltmpl")
      vim.cmd("au BufRead,BufNewFile *.gohtml set filetype=gohtmltmpl")
      -- vim.cmd("au BufRead,BufNewFile *.gohtml set filetype=html")
    end,
    keys = {
      { "gtc", "<cmd>GoCoverage<cr>", desc = "Go Coverage" },
      { "gtC", "<cmd>GoCoverageClear<cr>", desc = "Go Coverage Clear" },
      { "gtt", "<cmd>GoTest<cr>", desc = "Go Test" },
      { "gtf", "<cmd>GoTestFunc<cr>", desc = "Go Test Func" },
      { "gtF", "<cmd>GoTestFile<cr>", desc = "Go Test File" },
      { "gat", "<cmd>GoAddTags<cr>", desc = "Add Go Tags (json)" },
      { "sgd", "<cmd>split<cr><cmd>GoAddTags<cr>", desc = "Add Go Tags (json)" },
      { "vgd", "<cmd>split<cr><cmd>GoAddTags<cr>", desc = "Add Go Tags (json)" },
      -- { "gaT", "<cmd>GoAddTags  lua vim.ui.input('custom tag') <cr>", desc = "Add Go Tags (custom)" },
    },
  },
}

vim-go version:

commit 1401b57

vimrc you used to reproduce:

vimrc ```vim ```

Vim version (first three lines from :version):

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1697887905

Go version (go version):

go version go1.21.3 darwin/arm64

Go environment

go env Output:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/myuser/Library/Caches/go-build'
GOENV='/Users/myuser/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/myuser/go/pkg/mod'
GONOPROXY='github.com/aviva-verde'
GONOSUMDB='github.com/aviva-verde'
GOOS='darwin'
GOPATH='/Users/myuser/go'
GOPRIVATE='github.com/aviva-verde'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.3/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/path/to/project/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/n5/f5yx76r937xfhpdlkzfn9txm0000gn/T/go-build4219877315=/tmp/go-build -gno-record-gcc-switches -fno-common'

gopls version

gopls version Output:

golang.org/x/tools/gopls v0.14.1
    golang.org/x/tools/gopls@v0.14.1 h1:XaTETpi7Q67XO8nftquJitcx+9c2bPclO8Kz2sBVvec=

vim-go configuration:

vim-go configuration
g:go_fmt_command = 'goimports'
g:go_loaded_gosnippets = 1
g:go_loaded_install = 1
g:go_jump_to_error = 1

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:ON
bhcleek commented 11 months ago

What did you do just to cause unknown directive: toolchain to show up?

What is the value of the go directive in the relevant go.mod file?

JamesTiberiusKirk commented 11 months ago

@bhcleek This is the relavant line: toolchain go1.21.0 But as I said, in vscoded for example this does not kick up a fuss at all. Running the tests in the project is no issue either.

bhcleek commented 11 months ago

I'm not sure what operation caused this error. I'll need to know that to help you more. I'll also need the output of :messages after the error appears.

JamesTiberiusKirk commented 11 months ago

What do you mean by operation? I just opened the nvim in the root directory of the project, and opening any go (and related) file gets the lsp going and it complains about this error.

this is the output of :messages (the error itself is displayed by trouble.nvim)

vim-go: initializing gopls
vim-go: initialized gopls
vim-go: Finished loading packages.
"~/path/to/go.mod" 122L, 6001B
"go.mod" 124L, 6021B

sorry if this is not vim-go related but this is the only place i could figure to ask because ive seen similar questions being asked.

bhcleek commented 11 months ago

Can you add let g:go_debug=['lsp'] to your vimrc, duplicate the error (you'll likely have to restart Vim), and paste the contents of the __GOLSP_LOG__ window here?

bhcleek commented 11 months ago

trouble.nvim seems to be about Neovim's LSP, and not about vim-go or its use of gopls. I suspect you may have two versions of gopls installed. Vim-go and Neovim's LSP may be using different binaries, and the one used by Neovim's LSP is old if that's the case.

Can you please search your system to see how many instances of gopls are on it?

Also, given that it appears this may not be vim-go related, we can be certain by alternately using only one of Neovim's LSP or vim-go. Can you modify your vimrc accordingly so we can know where the problem lies?

JamesTiberiusKirk commented 11 months ago

omfg im an idiot lol

$ where gopls
/Users/redacted/go/bin/gopls
/Users/redacted/.local/share/nvim/mason/bin/gopls
/Users/redacted/go/bin/gopls
/Users/redacted/go/bin/gopls
/Users/redacted/go/bin/gopls
/Users/redacted/go/bin/gopls

I've updated the mason gopls and it works fine now. i really need to start another config from scratch without bloat ive accumulated from Lazy.vim.

Thanks a lot for helping even though it was not vim-go related. This issue can be closed now of course.

P.S. Im curious, how would I look at the __GOLSP_LOG__ logs?

bhcleek commented 11 months ago

The logs in the __GOLSP_LOG__ window should display in a window (usually at the bottom of your terminal) when g:go_debug contains lsp.