zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
530 stars 42 forks source link

On attach not working #33

Closed danymat closed 2 years ago

danymat commented 2 years ago

Hello again !

I'm trying to hide diagnostics for zk, and I came up with this snippet:

                require("zk").setup({
                    picker = "telescope",
                    lsp = {
                        config = {
                            on_attach = function(_, buffer)
                                                                print(buffer)
                                vim.diagnostic.hide(nil, buffer)
                            end,
                        },
                    },
                })

However, it seems that the on_attach function is never called, as I never go into the print. Am I missing something here ?

kabouzeid commented 2 years ago

I just checked. It is definitely called, but for some reason print() doesn't work here. Very weird. Maybe on_attach() is called on a background thread and print isn't supported there or something. Not sure if it's a Neovim bug, or maybe this behavior is documented somewhere.

danymat commented 2 years ago

Oh okay, my bad ! Still, vim.diagnostic.hide(nil, buffer) does not seem to be working, even though it works well when I do it in command mode.

kabouzeid commented 2 years ago

at that point the server probably hasn't yet sent the diagnostics. vim.diagnostic.hide(nil, buffer) will only hide the diagnostics that are currently displayed.

danymat commented 2 years ago

true, I used vim.diagnostic.disable instead and it works perfectly ! I can now jump between the ZK links super easily lol

kabouzeid commented 2 years ago

What diagnostics are you getting anyways? I don't get any diagnostics.

You can disable diagnostics like so in your .zk/config.toml:

[lsp.diagnostics]
# Report titles of wiki-links as hints.
wiki-title = "none"
# Warn for dead links between notes.
dead-link = "none"
danymat commented 2 years ago

I'm using:

[lsp]

[lsp.diagnostics]
# Each diagnostic can have for value: none, hint, info, warning, error

# Report titles of wiki-links as hints.
wiki-title = "hint"

So that I can jump in each wiki title with goto_next and goto_prev. I wanted to disable diagnostics so I don't have the virtual text, but still have the jumping enabled, somehow it's working

kabouzeid commented 2 years ago

weird that goto_next and goto_prev are still working with diagnostics disabled. something seems off about this.

by the way I'd rather use the following snippet which will only disable the diagnostics that are coming from zk.

local zk_lsp_client = require("zk.lsp").client()
if zk_lsp_client then
  local zk_diagnostic_namespace = vim.lsp.diagnostic.get_namespace(zk_lsp_client.id)
  vim.diagnostic.disable(0, zk_diagnostic_namespace)
end

Or better yet, just disable virtual text for zk diagnostics:

local zk_lsp_client = require("zk.lsp").client()
if zk_lsp_client then
  local zk_diagnostic_namespace = vim.lsp.diagnostic.get_namespace(zk_lsp_client.id)
  vim.diagnostic.config({virtual_text = false}, zk_diagnostic_namespace)
end