-
Hello. I am trying to implement LSP support for go programming. // ./nvim/ftplugin/go.lua
local autocmd = vim.api.nvim_create_autocmd
autocmd("FileType", {
pattern = "go",
callback = function()
local root_dir = vim.fs.dirname(
vim.fs.find({ 'go.mod', 'go.work', '.git' }, { upward = true })[1]
)
local client = vim.lsp.start({
name = 'gopls',
cmd = { 'gopls' },
root_dir = root_dir,
})
vim.lsp.buf_attach_client(0, client)
end
})
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
hey 👋 You shouldn't create an autocommand in |
Beta Was this translation helpful? Give feedback.
hey 👋
You shouldn't create an autocommand in
ftplugin
scripts, as the scripts are sourced on filetype events.