epwalsh / epwalsh/obsidian.nvim

nvim_cmp: can't cycle through suggestions

Open
#440 12 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Lua
Stars
6.2k
Forks
250
PR merge metrics
No merged PRs in 30d

Description

### 🐛 Describe the bug

I can't seem to cycle through suggestions. My keybinding will only let me choose one, and then I see a flicker.

See the attached video for more context:

https://github.com/epwalsh/obsidian.nvim/assets/37928/9d32996f-e449-409f-a13e-098167e4021f

### Config

Obsidian.nvim config:
```lua
{
"epwalsh/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
lazy = true,
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
"hrsh7th/nvim-cmp",
"nvim-telescope/telescope.nvim",
"nvim-treesitter/nvim-treesitter",
},
opts = {
workspaces = {
{
name = "Remote Second Brain",
path = "~/Documents/Remote Second Brain/",
},
},
notes_subdir = "30 Areas/31 Inbox",
new_notes_location = "notes_subdir",
templates = {
subdir = "50 Resources/54 Templates",
date_format = "%Y-%m-%d",
time_format = "%H:%M",
},
daily_notes = {
folder = "40 Journal/41 Daily Notes/2024",
date_format = "%Y-%m-%d",
time_format = "%H:%M",
template = "OTPL Daily Note.md",
},
-- Optional, set to true to force ':ObsidianOpen' to bring the app to the foreground.
open_app_foreground = true,
-- Optional, by default when you use `:ObsidianFollowLink` on a link to an external
-- URL it will be ignored but you can customize this behavior here.
---@param url string
follow_url_func = function(url)
-- Open the URL in the default web browser.
vim.fn.jobstart({ "open", url }) -- Mac OS
-- vim.fn.jobstart({"xdg-open", url}) -- linux
end,
note_id_func = function(title)
return title
end,
note_frontmatter_func = function(note)
-- Add the title of the note as an alias.
if note.title then
note:add_alias(note.title)
end

local out = { aliases = note.aliases, tags = note.tags }

-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end

return out
end,
-- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
---@return string
image_name_func = function()
-- Prefix image names with timestamp.
return string.format("%s-", os.time())
end,
attachments = {
-- The default folder to place images in via `:ObsidianPasteImg`.
-- If this is a relative path it will be interpreted as relative to the vault root.
-- You can always override this per image by passing a full path to the command instead of just a filename.
-- img_folder = "50 Resources/51 Attachments",
img_folder = "TestAttachments",
},
},
keys = {
{
"nb",
"ObsidianBacklinks",
desc = "Show backlinks for current note",
},
{
"nd",
"ObsidianToday",
desc = "Open new Daily Note",
},
{
"nf",
"ObsidianFollowLink",
desc = "Follow link",
},
{
"nn",
"ObsidianNew",
desc = "Create new note",
},
{
"no",
"ObsidianOpen",
desc = "Open note in Obsidian",
},
{
"nll",
"ObsidianLink",
desc = "Link selection",
},
{
"nln",
"ObsidianLinkNew",
desc = "Create and link new note",
},
{
"nq",
"ObsidianQuickSwitch",
desc = "Switch to another note",
},
{
"ns",
"ObsidianSearch",
desc = "Search notes",
},
{
"nt",
"ObsidianTemplate",
desc = "Insert template",
},
{
"ny",
"ObsidianYesterday",
desc = "Open yesterday's Daily Note",
},
},
},
```

nvim-cmp config:
```lua
return {
completion = {
completeopt = "menu,menuone,noinsert,noselect",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},

-- These mappings are based on the latest kickstart.nvim changes.
-- @see https://github.com/nvim-lua/kickstart.nvim/pull/635

-- For an understanding of why these mappings were
-- chosen, you will need to read `:help ins-completion`
mapping = cmp.mapping.preset.insert({
-- Select the [n]ext item
[""] = cmp.mapping.select_next_item(),

-- Select the [p]revious item
[""] = cmp.mapping.select_prev_item(),

-- Accept ([y]es) the completion.
-- This will auto-import if your LSP supports it.
-- This will expand snippets if the LSP sent a snippet.
[""] = cmp.mapping.confirm({ select = true }),

-- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display
-- completions whenever it has completion options available.
[""] = cmp.mapping.complete(),

-- Think of as moving to the right of your snippet expansion.
-- So if you have a snippet that's like:
-- function $name($args)
-- $body
-- end
--
-- will move you to the right of each of the expansion locations.
-- is similar, except moving you backwards.
[""] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { "i", "s" }),
[""] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { "i", "s" }),

[""] = cmp.mapping.abort(),
[""] = cmp.mapping.scroll_docs(-4),
[""] = cmp.mapping.scroll_docs(4),
}),
formatting = {
format = function(_, item)
local icons = require("azvim.core.helpers").icons.kinds

if icons[item.kind] then
item.kind = icons[item.kind] .. item.kind
end

return item
end,
},
sources = cmp.config.sources({
{ name = "nvim_lsp", priority = 1000 },
{ name = "luasnip", priority = 800 },
{ name = "git", priority = 600 },
{ name = "copilot", priority = 600 },
{ name = "buffer", priority = 400 },
{ name = "path", priority = 250 },
}),
}
```

### Environment

```
❯ nvim --version

NVIM v0.10.0-dev-2255+g4c9119461-Homebrew
Build type: Release
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info

dotfiles on  main [!]
❯ nvim --headless -c 'lua require("obsidian").info()' -c q

Plugins:
[obsidian.nvim (v3.5.3)] Commit SHA: 9ede6c86b1f47afe00442a6e84fa1f5b00153742
[plenary.nvim] Commit SHA: 4f71c0c4a196ceb656c824a70792f3df3ce6bb6d
[nvim-cmp] Commit SHA: 04e0ca376d6abdbfc8b52180f8ea236cbfddf782
[telescope.nvim] Commit SHA: 2e1e382df42467029b493c143c2e727028140214
Tools:
[rg] ripgrep 14.0.3
Environment:
[OS] Darwin⏎
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported completion behavior with the provided nvim-cmp mappings, especially and , using the listed Neovim and obsidian.nvim versions. Compare the behavior with the supplied Obsidian.nvim configuration and determine whether the flicker is caused by the plugin integration or nvim-cmp. Done means completion suggestions can be cycled without selecting only one item or flickering.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.