Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
tjex opened this issue Dec 21, 2023 · 3 comments · Fixed by zk-org/zk#397
Closed
2 tasks done

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

tjex opened this issue Dec 21, 2023 · 3 comments · Fixed by zk-org/zk#397
Labels
bug Something isn't working

Comments

@tjex
Copy link
Member

tjex commented Dec 21, 2023

Check if applicable

  • I have searched the existing issues (required)
  • I'm willing to help fix the problem and contribute a pull request

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
Copy link

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 github-actions bot added the stale label Jan 21, 2024
Copy link

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

@jurica jurica reopened this Jan 28, 2024
@jurica
Copy link
Member

jurica commented Jan 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants