hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.45k stars 370 forks source link

Use `get_word` so that the word is the same as in `core.confirm` #1860

Open luozhiya opened 3 months ago

luozhiya commented 3 months ago

Problem

Build a CompletionResponse in the following way:

local label = cursor_before_line .. suggestions
-- CompletionResponse
{
  label = label,
  word = label,
  textEdit = {
    range = {
      start = { line = line, character = character },
      ['end'] = { line = line, character = character },
    },
    newText = suggestions,
  },
}

When cursor_before_line is e and suggestions is mail, ghost_text will show ail and will be missing a character m. However, when you preview it from <Tab>, the mail is displayed correctly.

Solution

Use get_word so that the word is the same as in core.confirm