Shougo / ddc-source-lsp

lsp source for ddc.vim
Other
66 stars 20 forks source link

lsp completions not appearing #20

Closed ryan0270 closed 2 years ago

ryan0270 commented 2 years ago

I'm trying to migrate from deoplete to ddc but can't get lsp completions to work. As minimal example, create this file

struct Foo {
  int aaaa;
  double bbbb;
};

int main(int, char **) {
  Foo f;
  f.aaaa = 1;
  return 0;
}

If I start adding f.bb I get the around source completion but not lsp (a better example is to move Foo to a separate file and there are no completions). I can confirm that lsp is working by simply adding a syntax error to the file and seeing the lsp error messages appear.

Here is my init.vim

if &compatible
  set nocompatible               " Be iMproved
endif

set runtimepath+=~/.cache/dein/repos/github.com/Shougo/dein.vim

if dein#load_state('~/.cache/dein')
  call dein#begin('~/.cache/dein')

  " Let dein manage dein
  call dein#add('~/.cache/dein/repos/github.com/Shougo/dein.vim')

  " Add or remove your plugins here:
  call dein#add('Shougo/ddc.vim')
  call dein#add('Shougo/ddc-around')
  call dein#add('Shougo/ddc-matcher_head')
  call dein#add('Shougo/ddc-sorter_rank')
  call dein#add('neovim/nvim-lspconfig')
  call dein#add('vim-denops/denops.vim')

  " Required:
  call dein#end()
  call dein#save_state()
endif

" If you want to install not installed plugins on startup.
if dein#check_install()
  call dein#install()
endif
let g:dein#auto_recache=1

syntax on
syntax enable

call ddc#custom#patch_global('sources', ['around', 'nvim-lsp'])
call ddc#custom#patch_global('sourceOptions', {
      \ '_': {
        \   'matchers': ['matcher_head'],
        \   'sorters': ['sorter_rank']
        \},
      \ 'around': {'mark': 'A'},
      \ 'nvim-lsp': {
        \   'mark': 'lsp',
    \   'forceCompletionPattern': '\.\w*|:\w*|->\w*'
        \}
      \})
call ddc#custom#patch_global('sourceParams', {
      \ 'nvim-lsp': { 'kindLabels': { 'Class': 'c' } },
      \ })

call ddc#enable()

lua require 'init'

and the referenced init.lua

local nvim_lsp = require('lspconfig')

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

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  local opts = { noremap=true, silent=true }

  buf_set_keymap('n', 'gc', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
end

nvim_lsp.clangd.setup{
  cmd={
    'clangd',
    '-cross-file-rename',
    '-j=2',
    '--header-insertion=never',
    '--background-index',
    '--pch-storage=disk'
  };
  on_attach = on_attach;
  flags = {debounce_text_changes=150};
}
Shougo commented 2 years ago

Really? I will test it.

Shougo commented 2 years ago

It works for me. It seems your configuration problem.

Shougo commented 2 years ago

This is the minimal vimrc. Closing.

if &compatible
  set nocompatible
endif

set runtimepath^=~/work/ddc.vim
set runtimepath+=~/work/denops.vim

if has('nvim')
  set runtimepath+=~/src/nvim-lspconfig
  set runtimepath^=~/work/ddc-nvim-lsp

  lua << EOF
  require'lspconfig'.clangd.setup{}
EOF
endif

filetype plugin indent on
syntax enable

call ddc#custom#patch_global('sourceOptions', {
      \ '_': {
      \   'matchers': ['matcher_head'],
      \   'sorters': ['sorter_rank'],
      \ },
      \ 'nvim-lsp': {'mark': 'nvimlsp', 'forceCompletionPattern': '\.|:|->|"\w*/'},
      \ })

call ddc#custom#patch_filetype(['c'], 'sources', ['nvim-lsp'])

call ddc#enable()

スクリーンショット_2021-10-06_09-58-23

ryan0270 commented 2 years ago

Even with your init.vim it's still not working for me. The only thing I changed was the paths:

set runtimepath^=~/.cache/dein/repos/github.com/Shougo/ddc.vim                                                 
set runtimepath+=~/.cache/dein/repos/github.com/vim-denops/denops.vim           

if has('nvim')    
  set runtimepath+=~/.cache/dein/repos/github.com/neovim/nvim-lspconfig     
  set runtimepath^=~/.cache/dein/repos/github.com/Shougo/ddc-nvim-lsp     

  lua << EOF    
  require'lspconfig'.clangd.setup{}    
EOF    
endif

Is there a way I can generate debug output? Also, I forgot mention before that I'm on nvim version 0.5.1 if that matters.

Shougo commented 2 years ago

You can debug it. It is open source and you can reproduce the problem. It is easy way if I am you.

I cannot debug it. I have not ESP skill.

You should check nvim-lsp source is really called.

diff --git a/denops/@ddc-sources/nvim-lsp.ts b/denops/@ddc-sources/nvim-lsp.ts
index 838642d..6683547 100644
--- a/denops/@ddc-sources/nvim-lsp.ts
+++ b/denops/@ddc-sources/nvim-lsp.ts
@@ -88,6 +88,7 @@ export class Source extends BaseSource<Params> {
   async gatherCandidates(
     args: GatherCandidatesArguments<Params>,
   ): Promise<Candidate[]> {
+    console.log(args.context.input);
     const escaped = escapeVimAutoloadNameCached(this.name);
     const prevInput = await vars.g.get(
       args.denops,
Shougo commented 2 years ago

I can confirm that lsp is working by simply adding a syntax error to the file and seeing the lsp error messages appear.

LSP works does not mean ddc-nvim-lsp works.

ryan0270 commented 2 years ago

Sorry, but I have no experience in debugging (neo)vim plugins so I can't do much without guidance. It took me 30mins just to find how I can see the output of console.log.

I confirmed that right now it is NOT being called. I tried downgrading neovim to version 0.5.0 and everything works; that log line is being called and I see the lsp completions. So it appears something changed in version 0.5.1.

Shougo commented 2 years ago

I use neovim HEAD. It works.

Shougo commented 2 years ago

I don't know why neovim 0.5.1 does not work.

Shougo commented 2 years ago

I get the reason. neovim 0.5.1 contains LSP breaking changes.