zk-org / zk-nvim

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

completion only works with autocomplete, not via manual trigger (nvim-cmp) #155

Closed tjex closed 5 months ago

tjex commented 9 months ago

Check if applicable

Describe the bug

With autocomplete enabled in cmp (meaning completion will begin as soon as I start typing), lsp returns to me my notes for link creation:

~/wikis/test 1m 25s
sys > tree
.
├── 8544.md <-- "AI title"
├── 939q.md <-- "blah"
├── d
│   └── flk.md <-- "asdlf"
└── index.md
  2 # index
  1
 3   [[]] <-- triggered upon typing `[[`
 1   ╭──────────────────╮
~    │ blah     󰈇 [LSP] │
~    │ asdlf    󰈇 [LSP] │
~    │ index    󰈇 [LSP] │
~    │ AI title 󰈇 [LSP] │
~    ╰──────────────────╯

However, with autocomplete set to false, no lsp findings are returned to me:

    2 # index
    1
  3   [[]] <- triggered manually
    1  ╭───────────────╮
~      │ index 󰉿 [buf] │
~      ╰───────────────╯

Same goes if I type some characters and then trigger completion (i.e, no lsp results):

    2 # index
    1
  3   [[AI ]]
    1     ╭─────────────────────╮
~         │ pandoc~     [snip] │
~         │ simple~     [snip] │
~         │ blog post~  [snip] │
~         │ index      󰉿 [buf]  │
~         ╰─────────────────────╯

Furthermore, if keyword_length is set in nvim-cmp (which sets completion to trigger after n characters are typed`, it breaks the zk-nvim completion.

Type [[ to trigger completion:

  2 # index
  1
 3   [[]] <-- triggered upon typing `[[`
 1   ╭──────────────────╮
~    │ blah     󰈇 [LSP] │
~    │ asdlf    󰈇 [LSP] │
~    │ index    󰈇 [LSP] │
~    │ AI title 󰈇 [LSP] │
~    ╰──────────────────╯

Type A to filter towards "AI title"

  2 # index
  1
 3   [[A]] <-- triggered upon typing `[[A` (completion returns nothing)
~
~

How to reproduce?

test.tar.gz

zk configuration

[note]
filename = "{{id}}"
template = "default.md"

[extra]

[format.markdown]

hashtags = false
colon-tags = false
multiword-tags = false

[tool]

[lsp]

[lsp.diagnostics]
dead-link = "error"

[lsp.completion]
note-label = "{{title-or-path}}"

[filter]

[alias]

Neovim configuration

local key = vim.keymap.set

require("zk").setup({

    picker = "telescope",

    lsp = {
        config = {
            cmd = { "zk", "lsp" },
            name = "zk",
            on_attach = function()
                key("n", "gd", function()
                    vim.lsp.buf.definition()
                end, {})
                require("cmp_nvim_lsp").default_capabilities()
            end,
        },

        auto_attach = {
            enabled = true,
            filetypes = { "markdown" },
        },
    },
})

local cmp = require("cmp")
local lspkind = require("lspkind")

cmp.setup({
    completion = {
        autocomplete = false,
    },
    snippet = {
        expand = function(args)
            require("luasnip").lsp_expand(args.body)
        end,
    },
    window = {
        documentation = cmp.config.disable, -- disable docs popup
        completion = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
        ["<c-k>"] = cmp.mapping.select_prev_item(),
        ["<c-j>"] = cmp.mapping.select_next_item(),
        ["<c-l>"] = cmp.mapping.complete(),
        ["<c-i>"] = cmp.mapping.confirm({ select = true }), -- Accept item at top of list. Set `select` to `false` to only confirm explicitly selected items.
    }),

    sources = cmp.config.sources({
        { name = "nvim_lsp"},
        { name = "luasnip"},
        { name = "buffer"},
        { name = "nvim_lua"},
        { name = "path"},
    }),
    formatting = {
        format = lspkind.cmp_format({
            mode = "symbol",
            maxwidth = 50,
            ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
            menu = {
                buffer = "[buf]",
                nvim_lsp = "[LSP]",
                luasnip = "[snip]",
                path = "[path]",
                nvim_lua = "[api]",
            },
        }),
    },
})

Environment

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1700008891

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.4/share/nvim"

Run :checkhealth for more info
github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in the next 5 days.

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 5 days with no activity.

jurica commented 7 months ago

I can reproduce this with my neovim config as well. This is also reproducible when 'autocomplete' is on for cmp when trying to manually trigger completion after coming from normal mode. Like so:

  1. In insert mode type ie. "[[AI" so that the completion lists opens up.
  2. Enter normal mode.
  3. Enter insert mode again.
  4. Try to trigger autocompletion => no suggestions from zk lsp.