ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2k stars 122 forks source link

attemp to compare string with nil #81

Closed WaveYourHands closed 2 years ago

WaveYourHands commented 2 years ago
nil
-- go.nvim setup copy from https://github.com/ray-x/go.nvim#sample-vimrc

require('go').setup({
  goimport = 'gopls', -- if set to 'gopls' will use golsp format
  gofmt = 'gopls', -- if set to gopls will use golsp format
  max_line_len = 120,
  tag_transform = false,
  test_dir = '',
  comment_placeholder = '   ',
  lsp_cfg = false, -- false: use your own lspconfig
  lsp_gofumpt = true, -- true: set default gofmt in gopls format to gofumpt
  lsp_on_attach = true, -- use on_attach from go.nvim
  dap_debug = true,
})
-- lsp-installer setup

...

    elseif server.name == "gopls" then
      -- require'go.lsp' : attemp to compare string with nil ?????
      local go_lsp_opts = require'go.lsp'.config() -- config() return the go.nvim gopls setup
      go_lsp_opts = vim.tbl_deep_extend("force", go_lsp_opts, opts)
      server:setup(go_lsp_opts)

...
gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
ray-x commented 2 years ago

If you are using lsp-installer you need to export the PATH check this: https://github.com/ray-x/go.nvim#integrate-with-nvim-lsp-installer And also make sure you are using the latest version.

WaveYourHands commented 2 years ago

another error:

"E730: using List as a String"

If you are using lsp-installer you need to export the PATH

echo $PATH
/Users/xxx/.local/share/nvim/lsp_servers/go:
/Users/xxx/.cargo/bin:
/usr/local/Caskroom/miniconda/base/envs/py39/bin:
/usr/local/Caskroom/miniconda/base/condabin:
/Users/xxx/.nvm/versions/node/v16.13.2/bin:
/Users/xxx/.jenv/shims:
/Users/xxx/.jenv/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Users/xxx/go/bin 
gopls version
golang.org/x/tools/gopls v0.7.5
    golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
-- copy from https://github.com/ray-x/go.nvim#integrate-with-nvim-lsp-installer
local path = require 'nvim-lsp-installer.path'
local install_root_dir = path.concat { vim.fn.stdpath 'data', 'lsp_servers' }

require('go').setup {
  gopls_cmd        = { install_root_dir .. '/go/gopls' },
  filstruct              = 'gopls',
  dap_debug        = true,
  dap_debug_gui = true,
}
-- lsp-installer setup
...

    elseif server.name == "gopls" then
      -- require'go.lsp' 
      local go_lsp_opts = require'go.lsp'.config() -- config() return the go.nvim gopls setup
      go_lsp_opts = vim.tbl_deep_extend("force", go_lsp_opts, opts)
      server:setup(go_lsp_opts)

...
git log --oneline
f599a5e (HEAD -> master, origin/master, origin/HEAD) gopls cmd fallback
ce29866 lsp installer path setup for version check
180e44a (grafted) handle nil
ray-x commented 2 years ago

I pushed another version to fix this issue. I am not a lsp-installer user. If you still seeing issues, please add a minimum vimrc for me to reproduce. Thanks!

WaveYourHands commented 2 years ago

It looks ok now Thanks!!!!!!

I am not a lsp-installer user. If you still seeing issues, please add a minimum vimrc for me to reproduce.

structure

# ~/.config/nvim/
.
├── ...
├── init.lua
├── lua
│   ├── ...
│   ├── go-setup.lua
│   ├── lsp-setup.lua
│   └── ...
└── ...

A

version

Available prior to this version

problem

gopls

(py39) xxx@xxx: ~  $ echo $PATH
/Users/xxx/.cargo/bin:
/usr/local/Caskroom/miniconda/base/envs/py39/bin:
/usr/local/Caskroom/miniconda/base/condabin:
/Users/xxx/.nvm/versions/node/v16.13.2/bin:
/Users/xxx/.jenv/shims:
/Users/xxx/.jenv/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Users/xxx/go/bin   (gopls)
(py39) xxx@xxx: ~  $ gopls version
golang.org/x/tools/gopls master    👈 (that time : master??? not v0.7.5)
    golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
local v = vim.fn.system("gopls version"):match("%s+v([%d%.]+)%s+")
print(v) -- nil

structure

init.lua

require 'go-setup'
require 'lsp-setup'

go-setup.lua

require('go').setup({
  goimport            = 'gopls', -- if set to 'gopls' will use golsp format
  gofmt               = 'gopls', -- if set to gopls will use golsp format
  max_line_len        = 120,
  tag_transform       = false,
  test_dir            = '',
  comment_placeholder = '   ',
  lsp_cfg             = false, -- false: use your own lspconfig
  lsp_gofumpt         = true, -- true: set default gofmt in gopls format to gofumpt
  lsp_on_attach       = true, -- use on_attach from go.nvim
  dap_debug           = true,
})

lsp-setup.lua

local lsp_installer = require 'nvim-lsp-installer'

lsp_installer.on_server_ready(function(server)
  local opts = {
    on_attach    = on_attach,
    capabilities = capabilities,
  }

  if language_servers[server.name] then
    if server.name == ... then
        -- config
        -- ...
      server:attach_buffers()
    elseif server.name == "gopls" then
      local go_lsp_opts = require'go.lsp'.config() -- config() return the go.nvim gopls setup
      go_lsp_opts = vim.tbl_deep_extend("force", go_lsp_opts, opts)
      server:setup(go_lsp_opts)
    else
        -- config
        -- ...
      server:setup(opts)
    end
  end

end)

B

version

problem

gopls

(py39) xxx@xxx: ~  $ echo $PATH
/Users/xxx/.local/share/nvim/lsp_servers/go:   (gopls)
/Users/xxx/.cargo/bin:
/usr/local/Caskroom/miniconda/base/envs/py39/bin:
/usr/local/Caskroom/miniconda/base/condabin:
/Users/xxx/.nvm/versions/node/v16.13.2/bin:
/Users/xxx/.jenv/shims:
/Users/xxx/.jenv/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Users/xxx/go/bin   (gopls)
(py39) xxx@xxx: ~  $ gopls version
golang.org/x/tools/gopls v0.7.5
    golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=

structure

init.lua

require 'go-setup'
require 'lsp-setup'

go-setup.lua

local path = require 'nvim-lsp-installer.path'
local install_root_dir = path.concat { vim.fn.stdpath 'data', 'lsp_servers' }

require('go').setup {
  gopls_cmd        = { install_root_dir .. '/go/gopls' },
  filstruct        = 'gopls',
  dap_debug        = true,
  dap_debug_gui    = true,
}

lsp-setup.lua

local lsp_installer = require 'nvim-lsp-installer'

lsp_installer.on_server_ready(function(server)
  local opts = {
    on_attach    = on_attach,
    capabilities = capabilities,
  }

  if language_servers[server.name] then
    if server.name == ... then
        -- config
        -- ...
      server:attach_buffers()
    elseif server.name == "gopls" then
      local go_lsp_opts = require'go.lsp'.config() -- config() return the go.nvim gopls setup
      go_lsp_opts = vim.tbl_deep_extend("force", go_lsp_opts, opts)
      server:setup(go_lsp_opts)
    else
        -- config
        -- ...
      server:setup(opts)
    end
  end

end)