Shougo / ddc-source-lsp

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

Completion does not work well in recent commits when capabilities.textDocument.completion.completionItem.snippetSupport = true (and no snippet plugins are used?) #46

Closed haruyama closed 1 year ago

haruyama commented 1 year ago

prerequisite

Software version

Other

  1. set up golang runtime and go install golang.org/x/tools/gopls@latest
  2. prepare main.go with the following content
package main

import "fmt"

func main() {
    fmt.Println("hello")
}

Steps to reproduce

case 1

https://github.com/Shougo/ddc-source-nvim-lsp/commit/70086994e3d83e65eb4aed6888b84d4b0b2f3aeb

  1. copy https://github.com/haruyama/ddc-source-nvim-lsp-config-for-debug/tree/f1939a76a22d63085319d4693c654e99f5267f69 to ~/.config/nvim
  2. nvim main.go on console
  3. enter fmt.P in main function

no candidates are displayed from ddc.

no error messages in :messages

case 2

https://github.com/Shougo/ddc-source-nvim-lsp/commit/738b86b5c16ee8f396d9437e6aea17780e325ef1

  1. copy https://github.com/haruyama/ddc-source-nvim-lsp-config-for-debug/tree/f1939a76a22d63085319d4693c654e99f5267f69 to ~/.config/nvim
  2. comment out L53-L56 in ~/.config/nvim/dein_lazy.toml
  3. comment in L59-L62 in ~/.config/nvim/dein_lazy.toml
  4. nvim main.go on console
  5. enter fmt.P and Ctrl-N and ( in main function

fmt.( is displayed. (expected: fmt.Println()

error messages in :messages

[ddc] source: nvim-lsp "onCompleteDone()" failed                                                                                                                                                                              
[denops] (ddc) 0,CompleteDone Autocommands for "*"..function ddc#ui#native#_on_complete_done[6]..ddc#on_complete_done[1]..ddc#complete#_on_complete_done[28]..denops#request[1]..denops#server#request[4]..denops#_internal#server#chan
#request[4]..denops#_internal#rpc#nvim#request[1]..denops#callback#call, line 2: No callback function for  exist
Shougo commented 1 year ago

Minimal vimrc.

set nocompatible

set runtimepath+=~/work/denops.vim
set runtimepath+=~/work/ddc.vim
set runtimepath+=~/work/ddc-filter-matcher_head
set runtimepath+=~/work/ddc-filter-sorter_rank
set runtimepath+=~/work/ddc-ui-native
set runtimepath+=~/work/ddc-source-nvim-lsp
set runtimepath+=~/src/nvim-lspconfig

lua << EOF
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

local lspconfig = require'lspconfig'
lspconfig.gopls.setup{capabilities = capabilities}
EOF

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

call ddc#enable()
Shougo commented 1 year ago

Hi. I have tested it and empty items. (I don't reproduce your error)

It is from capabilities.textDocument.completion.completionItem.snippetSupport = true. gopls returns snippet items and it is filtered. Because you don't set snippetEngine param.

{
  label: "fmt",
  textEdit: { range: { end: [Object], start: [Object] }, newText: "fmt" },
  filterText: "fmt",
  preselect: true,
  sortText: "00000",
  kind: 9,
  detail: '"fmt"',
  documentation: { kind: "markdown", value: "" },
  insertTextFormat: 2
},

insertTextFormat: 2 means snippet.

uga-rosa commented 1 year ago

First of all, the basic premise is that a major renovation has recently taken place; please re-read the doc.

And to solve this case1, register snippetEngine (:h ddc-source-nvim-lsp-param-snippetEngine). gopls returns all candidates as a snippet if snippet=true. So, if the snippetEngine is not registered, they will be filtered. If you don't want to use the snippet plugin, one solution is to change capabilities.

local capabilities = require('ddc_nvim_lsp').make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = false
Shougo commented 1 year ago

error messages in :messages

I think the error message is from older commit. It is bug and it is already fixed. So the items are filtered.

Shougo commented 1 year ago

I have updated FAQ.

Shougo commented 1 year ago

The issue is improved. Please update.