nvim-lua / diagnostic-nvim

A wrapper for neovim built in LSP diagnosis config
Apache License 2.0
219 stars 15 forks source link

Plugin working without calling on_attach #12

Closed gbrlsnchs closed 4 years ago

gbrlsnchs commented 4 years ago

Hello! Thanks for this nice plugin.

Currently, I have this small wrapper:

local vim = vim
local api = vim.api
-- local compl = require'completion'
-- local diagnostic = require'diagnostic'
local nvim_lsp = require'nvim_lsp'
local M = {}

local function on_attach()
    -- compl.on_attach()
    -- diagnostic.on_attach()
    api.nvim_command [[augroup LspAttachments]]
      api.nvim_command("autocmd! * <buffer>")
      -- api.nvim_command("autocmd CursorHold <buffer> lua vim.lsp.buf.hover()")
    api.nvim_command [[augroup end]]
    api.nvim_command("command! -buffer -nargs=0 LspRename call RenameSymbol()")
    api.nvim_command("command! -buffer -nargs=0 LspFormat lua vim.lsp.buf.formatting()")
end

function M.register_servers()
  -- Go
  nvim_lsp.gopls.setup{on_attach=on_attach}
  -- JavaScript & TypeScript
  nvim_lsp.tsserver.setup{on_attach=on_attach}
end

return M

And in my init.vim:

" ...
Plug 'haorenW1025/diagnostic-nvim'
" Plug 'haorenW1025/completion-nvim'
"...

lua require'lsp_config'.register_servers()

As you can see, I have commented the calls to diagnostic.on_attach, and am only importing the plugin itself via vim-plug. I was testing it by toggling comments in that call. However, even with it disabled, it still works. The on_attach call has no effect whatsover. It would be nice if the plugin only got activated when I call the on_attach function.

haorenW1025 commented 4 years ago

It should be fixed, please check!

gbrlsnchs commented 4 years ago

I have tested it, now it's only activated when calling on_attach, which is the correct behavior, however now I'm not seeing the words in the line highlighted. Do I need to configure something else now to enable highlighting all words involved in the diagnostic?

haorenW1025 commented 4 years ago

Hmm I don't think the words of diagnostic will be highlighted. Will it be highlighted in a default behavior of neovim?

gbrlsnchs commented 4 years ago

Sorry, by highlighted I meant to be underlined. After the change, words won't get underlined anymore. Everything else is still working, though.

haorenW1025 commented 4 years ago

Hmm that's weird cause it works fine on my side. Can you reproduce this using the minimal init.vim?

gbrlsnchs commented 4 years ago

I used a minimal init.vim and it's working properly. Must be something in my config. Thanks!

gbrlsnchs commented 4 years ago

If anyone is having the same problem, I found the issue: calling require'nvim_lsp'.<any_lsp>.setup{on_attach=require'diagnostic'.on_attach} BEFORE syntax enable makes the underlining to be overridden.