Repository: neovim/neovim
File: runtime/lua/vim/lsp/completion.lua (Lua)

Code before:
        Context.isIncomplete = Context.isIncomplete or result.isIncomplete
        local encoding = client and client.offset_encoding or 'utf-16'
        local client_matches
        client_matches, server_start_boundary = M._convert_results(
          line,
          cursor_row - 1,
          cursor_col,
          client_id,
          word_boundary,
          nil,
          result,
          encoding
        )

        vim.list_extend(matches, client_matches)
      end
    end

    --- @type table[]
    local prev_matches = vim.fn.complete_info({ 'items', 'matches' })['items']

    --- @param prev_match table
    prev_matches = vim.tbl_filter(function(prev_match)
      local client_id = vim.tbl_get(prev_match, 'user_data', 'nvim', 'lsp', 'client_id')
      local matching = vim.tbl_get(prev_match, 'match')
      return (not client_id or responses[client_id] == nil) and matching
    end, prev_matches)

    matches = vim.list_extend(prev_matches, matches)

    local start_col = (server_start_boundary or word_boundary) + 1
    Context.cursor = { cursor_row, start_col }
    vim.fn.complete(start_col, matches)
  end)

  table.insert(Context.pending_requests, cancel_request)
end

--- @param handle vim.lsp.completion.BufHandle
local function on_insert_char_pre(handle)
  if tonumber(vim.fn.pumvisible()) == 1 then
    if Context.isIncomplete then
      reset_timer()

      local debounce_ms = next_debounce()
      local ctx = { triggerKind = protocol.CompletionTriggerKind.TriggerForIncompleteCompletions }
      if debounce_ms == 0 then
        vim.schedule(function()
          M.get({ ctx = ctx })
        end)
      else

Review comment (suggestion):
```suggestion
      if client_id and responses[client_id] ~= nil then
        return false
      end
      return vim.tbl_get(prev_match, 'match')
```

Code after:
        Context.isIncomplete = Context.isIncomplete or result.isIncomplete
        local encoding = client and client.offset_encoding or 'utf-16'
        local client_matches
        client_matches, server_start_boundary = M._convert_results(
          line,
          cursor_row - 1,
          cursor_col,
          client_id,
          word_boundary,
          nil,
          result,
          encoding
        )

        vim.list_extend(matches, client_matches)
      end
    end

    --- @type table[]
    local prev_matches = vim.fn.complete_info({ 'items', 'matches' })['items']

    --- @param prev_match table
    prev_matches = vim.tbl_filter(function(prev_match)
      local client_id = vim.tbl_get(prev_match, 'user_data', 'nvim', 'lsp', 'client_id')
      if client_id and responses[client_id] ~= nil then
        return false
      end
      return vim.tbl_get(prev_match, 'match')
    end, prev_matches)

    matches = vim.list_extend(prev_matches, matches)

    local start_col = (server_start_boundary or word_boundary) + 1
    Context.cursor = { cursor_row, start_col }
    vim.fn.complete(start_col, matches)
  end)

  table.insert(Context.pending_requests, cancel_request)
end

--- @param handle vim.lsp.completion.BufHandle
local function on_insert_char_pre(handle)
  if tonumber(vim.fn.pumvisible()) == 1 then
    if Context.isIncomplete then
      reset_timer()

      local debounce_ms = next_debounce()
      local ctx = { triggerKind = protocol.CompletionTriggerKind.TriggerForIncompleteCompletions }
      if debounce_ms == 0 then
        vim.schedule(function()
          M.get({ ctx = ctx })