Repository: neovim/neovim
File: test/functional/plugin/lsp/completion_spec.lua (Lua)

Code before:
      { label = 'foo', textEdit = { newText = 'foo', range = range0 } },
      { label = 'bar', textEdit = { newText = 'bar', range = range0 } },
    }
    local result = complete('fo|', completion_list)
    local expected = {
      {
        abbr = 'foo',
        word = 'foo',
      },
      {
        abbr = 'bar',
        word = 'bar',
      },
    }
    result = vim.tbl_map(function(x)
      return {
        abbr = x.abbr,
        word = x.word,
      }
    end, result.items)
    local sorter = function(a, b)
      return a.word > b.word
    end
    table.sort(expected, sorter)
    table.sort(result, sorter)
    eq(expected, result)
  end)

  it('uses exists highlight group for kind', function()
    local completion_list = {
      { label = 'Text', kind = 1 },
      { label = 'Method', kind = 2 },
      { label = 'Function', kind = 3 },
      { label = 'Constructor', kind = 4 },
      { label = 'Field', kind = 5 },
      { label = 'Variable', kind = 6 },
      { label = 'Class', kind = 7 },
      { label = 'Interface', kind = 8 },
      { label = 'Module', kind = 9 },
      { label = 'Property', kind = 10 },
      { label = 'Unit', kind = 11 },
      { label = 'Value', kind = 12 },
      { label = 'Enum', kind = 13 },
      { label = 'Keyword', kind = 14 },
      { label = 'Snippet', kind = 15 },
      { label = 'Color', kind = 16 },
      { label = 'File', kind = 17 },
      { label = 'Reference', kind = 18 },
      { label = 'Folder', kind = 19 },
      { label = 'EnumMember', kind = 20 },
      { label = 'Constant', kind = 21 },

Review comment (bug):
is this list meant to be exhaustive (i.e. does it need to cover ALL highlight group examples), or could it be reduced to cover various kinds of edge cases

Code after:
      { label = 'foo', textEdit = { newText = 'foo', range = range0 } },
      { label = 'bar', textEdit = { newText = 'bar', range = range0 } },
    }
    local result = complete('fo|', completion_list)
    local expected = {
      {
        abbr = 'foo',
        word = 'foo',
      },
    }
    result = vim.tbl_map(function(x)
      return {
        abbr = x.abbr,
        word = x.word,
      }
    end, result.items)
    local sorter = function(a, b)
      return a.word > b.word
    end
    table.sort(expected, sorter)
    table.sort(result, sorter)
    eq(expected, result)
  end)

  it('generate "■" symbol with highlight group for CompletionItemKind.Color', function()
    local completion_list = {
      { label = 'text-red-300', kind = 16, documentation = 'color: rgb(252, 165, 165)' },
    }
    local result = complete('|', completion_list)
    result = vim.tbl_map(function(x)
      return {
        word = x.word,
        kind_hlgroup = x.kind_hlgroup,
        kind = x.kind,
      }
    end, result.items)
    eq({ { word = 'text-red-300', kind_hlgroup = '@lsp.color.fca5a5', kind = '■' } }, result)
  end)

  ---@param prefix string
  ---@param items lsp.CompletionItem[]
  ---@param expected table[]
  local assert_completion_matches = function(prefix, items, expected)
    local result = complete(prefix .. '|', items)
    result = vim.tbl_map(function(x)
      return {
        abbr = x.abbr,
        word = x.word,
      }
    end, result.items)
    local sorter = function(a, b)