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

Code before:
        {
          label = 'div.foo',
          insertTextFormat = 2,
          textEdit = {
            newText = '<div class="foo">$0</div>',
            range = { start = { line = 0, character = 0 }, ['end'] = { line = 0, character = 7 } },
          },
        },
      },
    }
    local completion_list2 = {
      isIncomplete = false,
      items = {
        {
          insertTextFormat = 1,
          label = 'foo',
        },
      },
    }
    exec_lua(function()
      vim.o.completeopt = 'menu,menuone,noinsert'
    end)
    local id1 = create_server('dummy', completion_list, { trigger_chars = { '.' } })
    local id2 = create_server('dummy2', completion_list2, { trigger_chars = { '.' } })
    create_server('dummy3', { isIncomplete = false, items = {} })
    local retry_then_match = function(expect)
      retry(nil, nil, function()
        eq(
          1,
          exec_lua(function()
            return vim.fn.pumvisible()
          end)
        )
      end)
      feed('<C-Y>')
      eq(expect, n.api.nvim_get_current_line())
    end
    feed('Adiv.foo<C-x><C-O>')
    retry_then_match('<div class="foo"></div>')
    eq({ 1, 17 }, n.api.nvim_win_get_cursor(0))
    -- detach a client
    exec_lua('vim.lsp.buf_detach_client(0, ' .. id1 .. ')')
    feed('<ESC>Sdiv.')
    retry_then_match('div.foo')
    exec_lua('vim.lsp.buf_detach_client(0, ' .. id2 .. ')')
    feed('<ESC>Sdiv.')
    retry(nil, nil, function()
      eq(
        0,
        exec_lua(function()
          return vim.fn.pumvisible()

Review comment (suggestion):
reviewing the existing tests i see there isn't really a "basic" test where the "detach" functionality would fit. would it make sense to lift this function into `assert_cleanup_after_detach` and call that from a few tests (doesn't need to be all of them)? 

it is just a basic part of the lifecycle. so testing it after several scenarios makes more sense than having a dedicated test, or creating N different extra tests for it.

Code after:
    end)
    local client_id = create_server('dummy', completion_list)
    feed('Adiv.foo<C-x><C-O>')
    retry(nil, nil, function()
      eq(
        1,
        exec_lua(function()
          return vim.fn.pumvisible()
        end)
      )
    end)
    feed('<C-Y>')
    eq('<div class="foo"></div>', n.api.nvim_get_current_line())
    eq({ 1, 17 }, n.api.nvim_win_get_cursor(0))
    assert_cleanup_after_detach(client_id)
  end)

  it('does not empty server start boundary', function()
    local completion_list = {
      isIncomplete = false,
      items = {
        {
          label = 'div.foo',
          insertTextFormat = 2,
          textEdit = {
            newText = '<div class="foo">$0</div>',
            range = { start = { line = 0, character = 0 }, ['end'] = { line = 0, character = 7 } },
          },
        },
      },
    }
    local completion_list2 = {
      isIncomplete = false,
      items = {
        {
          insertTextFormat = 1,
          label = 'foo',
        },
      },
    }
    exec_lua(function()
      vim.o.completeopt = 'menu,menuone,noinsert'
    end)
    create_server('dummy', completion_list)
    create_server('dummy2', completion_list2)
    create_server('dummy3', { isIncomplete = false, items = {} })
    feed('Adiv.foo<C-x><C-O>')
    retry(nil, nil, function()
      eq(
        1,
        exec_lua(function()