Skip to content

nvim-cmp support #6

@eloycoto

Description

@eloycoto

Hi!

Do you have plans to support nvim-cmp? At the moment is a bit intrusive(Because of the LSP), and it will be good to have the support natively, I'm struggling with cmp-tabnine on multi-line, and official support will be great.

The interface to add support is pretty easy, like:

local cmp = require('cmp')

local Source = {
}

function Source.new()
  last_instance = setmetatable({}, { __index = Source })
  last_instance:on_exit(0)
  return last_instance
end

function Source.is_available(self)
  return true
end

function Source.get_debug_name()
  return 'TabNine'
end


function Source.complete(self, ctx, callback)
  local input = string.sub(ctx.context.cursor_before_line, ctx.offset - 1)
  local prefix = string.sub(ctx.context.cursor_before_line, 1, ctx.offset - 1)

  local items = {}
  ---  Do tabnine magic here
  table.insert(items, {
    filterText = "TabNine magic here"
    label = "TabNine magic here",
    textEdit = {
      newText = "Tabnine magic here" ,
      range = {
        start = {
          line = ctx.context.cursor.row - 1,
          character = ctx.context.cursor.col - 1 - #input,
        },
        ['end'] = {
          line = ctx.context.cursor.row - 1,
          character = ctx.context.cursor.col - 1,
        },
      },
    },
  })


  callback({
    items = items,
    isIncomplete = true,
  })
end

cmp.register_source('cmp_tabnine', M.tabnine_source)

Here is an example video:
https://www.youtube.com/watch?v=gAsYolNrjtQ

And the code:
https://github.com/wincent/wincent/blob/91ebe56f414748078c93d011f5774553bddf3537/aspects/nvim/files/.config/nvim/lua/wincent/cmp/handles.lua

My idea is to have nvim with tabnine and LSP playing nice :-)

Happy to do contribution in a branch, and beta-testing :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions