tzachar / cmp-tabnine

TabNine plugin for hrsh7th/nvim-cmp
MIT License
287 stars 28 forks source link

it doesn't work #1

Closed paulzhang5511 closed 3 years ago

paulzhang5511 commented 3 years ago

image

Environment

Windows10 wsl(Ubuntu 20.04)
nvim 0.5 

configuration

lua <<EOF

  -- nvim-cmp setup
  local cmp = require 'cmp'
  cmp.setup {
    snippet = {
      expand = function(args)
        -- You must install `vim-vsnip` if you use the following as-is.
        vim.fn['vsnip#anonymous'](args.body)
      end,
    },
    mapping = {
      ['<C-p>'] = cmp.mapping.select_prev_item(),
      ['<C-n>'] = cmp.mapping.select_next_item(),
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
    },
    sources = {
      { name = 'cmp_tabnine' },
      { name = 'nvim_lsp' },
      { name = 'buffer' },
    },
  }

  -- auto pairs
  require('nvim-autopairs').setup{}
  require("nvim-autopairs.completion.cmp").setup({
    map_cr = true, --map <CR> on insert mode
    map_complete = true, --it will auto insert `(` after select function or method item
  })

  -- tabnine
  local tabnine = require('cmp_tabnine.config')
  tabnine:setup({
    max_lines = 1000;
    max_num_results = 20;
    sort = true;
  })

  -- nvim lsp config
  local nvim_lsp = require('lspconfig')
  -- Use an on_attach function to only map the following keys
  -- after the language server attaches to the current buffer
  local on_attach = function(client, bufnr)
    local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
    local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

    -- Enable completion triggered by <c-x><c-o>
    buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- Mappings.
    local opts = { noremap=true, silent=true }

    -- See `:help vim.lsp.*` for documentation on any of the below functions
    buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
    buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
    buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
    buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
    buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
    buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
    --buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
    --buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
    buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
    buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
    buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
    buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
    buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
    buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
    buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
    buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
    buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  end

  -- Add additional capabilities supported by nvim-cmp
  local capabilities = vim.lsp.protocol.make_client_capabilities()
  capabilities.textDocument.completion.completionItem.snippetSupport = true
  capabilities.textDocument.completion.completionItem.preselectSupport = true
  capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
  capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
  capabilities.textDocument.completion.completionItem.deprecatedSupport = true
  capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
  capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
  capabilities.textDocument.completion.completionItem.resolveSupport = {
    properties = {
      'documentation',
      'detail',
      'additionalTextEdits',
    },
  }

  -- lsp install 
  require'lspinstall'.setup() -- important
  local servers = require'lspinstall'.installed_servers()
  for _, server in pairs(servers) do
    nvim_lsp[server].setup{
      on_attach = on_attach,
      flags = {
        debounce_text_changes = 150,
      },
      capabilities = capabilities,
    }
  end

EOF

Result

Tabnine doesn't work

tzachar commented 3 years ago

As you can see in the install.sh script, Windows is not supported on my end as I have no way of testing it. If you can create an appropriate install script / fix the existing one, please create a pull request.

viniciusmuller commented 3 years ago

I think the WSL Ubuntu environment should be pretty much the same thing as native ubuntu. It is also not working on NixOS, I thought It could be because of linking errors, but apparently, the TabNine binaries are statically linked.

viniciusmuller commented 3 years ago

I also think that maybe adding a way to let the user provide a TabNine binary path would be nice.

paulzhang5511 commented 3 years ago

image

Tabnine binaries can be downloaded normally. But it dont's also work.

This is the full configuration.

https://github.com/paulzhang5511/my-vimrc.git

tzachar commented 3 years ago

The problem with TabNine is that it expects a very specific directory layout, as TabNine auto updates itself. Allowing users to supply their own path would probably netage the auto update and end up with TabNine trying endlessly to update itself (been there).

To further try and unserstand why it is not working in your setup, lets try the following: 1) check if the TabNine binary is there 2) after opening nvim, check if there is a TabNine process: ps -aef | grep -i TabNine 3) add the following to you cmp config:

formatting = {
  format = function(entry, vim_item)
    -- set a name for each source
    vim_item.menu = ({
      buffer = "[Buffer]",
      nvim_lsp = "[LSP]",
      cmp_tabnine = "[T9]",
    })[entry.source.name]
    return vim_item
  end,
},

and see if you get [T9] in the completion menu

tzachar commented 3 years ago

b.t.w, if you run the TabNine binary by hand does it work?

paulzhang5511 commented 3 years ago

@tzachar Yeah. it work.

tzachar commented 3 years ago

Well, I got a windows machine, installed wsl ubuntu 20.04, and everything works for me out of the box:

Screenshot 2021-08-28 123434

here is my config, try and see if it works: https://github.com/tzachar/conf/blob/master/.config/nvim/lua/cmp_setup.lua

viniciusmuller commented 3 years ago

The problem with TabNine is that it expects a very specific directory layout, as TabNine auto updates itself. Allowing users to supply their own path would probably netage the auto update and end up with TabNine trying endlessly to update itself (been there).

I've been thinking about how to package this for Nixpkgs, since builds don't have internet connection during buildPhase, so the install.sh script won't work, also I couldn't get to this point yet, but if the tabnine binary modifies itself in the directory it would fail due to the /nix/store directory being readonly. Is it possible to provide a different location for the tabnine folder? Such as XDG_DATA_HOME?

tzachar commented 3 years ago

The problem with TabNine is that it expects a very specific directory layout, as TabNine auto updates itself. Allowing users to supply their own path would probably netage the auto update and end up with TabNine trying endlessly to update itself (been there).

I've been thinking about how to package this for Nixpkgs, since builds don't have internet connection during buildPhase, so the install.sh script won't work, also I couldn't get to this point yet, but if the tabnine binary modifies itself in the directory it would fail due to the /nix/store directory being readonly. Is it possible to provide a different location for the tabnine folder? Such as XDG_DATA_HOME?

These are two separate issues: 1) you need to install the plugin while there is no network connectivity 2) tabnine modifies itself during runtime.

I'll start with (2). You can't get past this, as the tabnine process downloads a model from the net when it is executed for the first time. without this model, tabnine will not work. You can solve both (1) and (2) with the same approach; instead of going through the normal install process, 'freeze' a working version of the binaries and use them, making use of the same directory structure the plugin creates. You would also have to copy the ~/.config/TabNine and ~/.local/share/TabNine folders, as they are. This should then help you solve both issues.

As for TabNine trying to update itself, there's not much I can help, this is something you need to take with the TabNine team. Maybe there is a configuration option to disable it.

paulzhang5511 commented 3 years ago

image

It works

tzachar commented 3 years ago

What was the problem in the end?

paulzhang5511 commented 3 years ago

I don't know. I updated the code. 9da5a5f. it work.