Skip to content

Link completion duplicates closing brackets #278

@viktomas

Description

@viktomas

This is re-opening of #270

oxide-bug.mp4

Steps to reproduce

  1. two files, A.md and B.md
  2. type in [[B]] in the A.md file
  3. trigger completion after the B character ([[B<here trigger>]])
  4. select the offered B completion
  5. See the closing brackets duplicated ]]]]

Expected behaviour

only one pair of brackets shows

Actual behaviour

duplicated brackets

Root cause

When we provide completion, we always end the wikilink replacement text with ]] regardless of the line content

It's possible that nvim-cmp somehow handles this, but simple completion plugins don't.

Minimum reproduction scenario

Create an empty directory (e.g. test), and the following script in the directory and run it

#!/bin/bash

## Heavily inspired by https://github.com/folke/lazy.nvim/wiki/Minimal-%60init.lua%60-to-Reproduce-an-Issue

# Clean up previous runs
rm -rf .repro A.md B.md

# Create directory structure
mkdir -p .repro/plugins/start

# Download plugins
echo "📦 Downloading plugins..."
git clone --quiet --depth=1 https://github.com/neovim/nvim-lspconfig.git .repro/plugins/start/nvim-lspconfig
git clone --quiet --depth=1 https://github.com/echasnovski/mini.completion.git .repro/plugins/start/mini.completion

# Create repro.lua for instant minimal environment
cat > repro.lua << 'EOF'
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- Setup plugins
require('mini.completion').setup()
require('lspconfig').markdown_oxide.setup({
    -- cmd = {vim.fn.expand('~/path/to/markdown-oxide')},  -- Uncomment to use custom binary
})
vim.keymap.set('i', '<C-Space>', '<C-x><C-u>')
EOF

# Create test files
cat > A.md << 'EOF'
# Test File A

Link to B: [[B]]
EOF

cat > B.md << 'EOF'
# Test File B

Target file for completion testing.
EOF

echo "✅ Created repro.lua"
echo "🧪 MANUAL TEST:"
echo "1. Run: nvim -u repro.lua A.md"
echo "2. Position cursor after 'B' inside [[B]]"
echo "3. Enter insert mode (i)"
echo "4. Press Ctrl-Space to trigger completion"
echo "5. Accept completion and check for duplicate ]]"
echo "Everything installs to ./.repro/ directory"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions