Shougo / ddc-source-lsp

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

[Question] What is the `$ 0` entered when completing CSS? #25

Closed nabezokodaikon closed 2 years ago

nabezokodaikon commented 2 years ago

Problems summary

What is the $0 entered when completing CSS?

Expected

Please tell me how to erase $0.

Environment Information

Provide a minimal init.vim/vimrc with less than 50 lines (Required!)

if &compatible
    set nocompatible
endif
let $CACHE = expand('~/.cache')
if !isdirectory(expand($CACHE))
    call mkdir(expand($CACHE), 'p')
endif
let s:dein_dir = expand('$CACHE/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
    if !isdirectory(s:dein_repo_dir)
        execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
    endif
    execute 'set runtimepath^=' . s:dein_repo_dir
endif
call dein#begin(s:dein_dir, expand('<sfile>'))
call dein#add('neovim/nvim-lspconfig')
call dein#add('vim-denops/denops.vim')
call dein#add('Shougo/ddc.vim')
call dein#add('Shougo/ddc-matcher_head')
call dein#add('Shougo/ddc-sorter_rank')
call dein#add('Shougo/ddc-nvim-lsp')
call dein#end()
call dein#save_state()
if has('vim_starting') && dein#check_install()
    call dein#install()
endif
inoremap jj <ESC>
lua << EOF
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require"lspconfig".cssls.setup {
  capabilities = capabilities,
}
EOF
call ddc#custom#patch_global('sources', ['nvim-lsp'])
call ddc#custom#patch_global('sourceOptions', {
      \ '_': {
      \   'minAutoCompleteLength': 1,
      \   'matchers': ['matcher_head'],
      \   'sorters': ['sorter_rank']},
      \ 'nvim-lsp': {
      \   'forceCompletionPattern': '\:\w*' },
      \ })
call ddc#enable()

How to reproduce the problem from neovim/Vim startup (Required!)

  1. Enter html: in the CSS file.
  2. Enter {}.
  3. Enter in parentheses and select completion candidates.

Screenshot (if possible)

スクリーンショット 2021-10-15 2 19 41

Shougo commented 2 years ago

Please understand what you done.

capabilities.textDocument.completion.completionItem.snippetSupport = true

It means you have enabled snippet feature. So it is inserted. $0 is snippet marker. You need to disable snippets if you don't want to complete $0 marker.

nabezokodaikon commented 2 years ago

It was my mistake. Thank you very much.

nabezokodaikon commented 2 years ago

An error occurred when disabling capabilities.textDocument.completion.completionItem.snippetSupport.

[denops] [ddc.vim] source: nvim-lsp "gatherCandidates()" is failed
[denops] Error: Failed to call 'call' with ["luaeval","require('ddc_nvim_lsp').request_candidates(_A.arguments, _A.id)",{"arguments":{"textDocument":{"uri":"file:///Users/nabezokodaikon/ws/dev/pcars2-telemetry-browsing/public/index.css"},
"position":{"character":1,"line":12}},"id":"source/nvim-lsp/1"}]: Error: Failed to call 'nvim_call_function' with ["luaeval",["require('ddc_nvim_lsp').request_candidates(_A.arguments, _A.id)",{"arguments":{"textDocument":{"uri":"file:///U
sers/nabezokodaikon/ws/dev/pcars2-telemetry-browsing/public/index.css"},"position":{"character":1,"line":12}},"id":"source/nvim-lsp/1"}]]: [0,"Vim:E5108: Error executing lua ...epos/github.com/Shougo/ddc-nvim-lsp/lua/ddc_nvim_lsp.lua:28:
attempt to get length of local 'map' (a nil value)"]
[denops]     at Session.call (https://deno.land/x/msgpack_rpc@v3.1.4/session.ts:207:13)
[denops]     at async Service.call (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/vim-denops/denops.vim/denops/@denops-private/service.ts:97:12)
[denops]     at async Session.call (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/vim-denops/denops.vim/denops/@denops-private/service.ts:71:16)
[denops]     at async Session.dispatch (https://deno.land/x/msgpack_rpc@v3.1.4/session.ts:99:12)
[denops]     at async https://deno.land/x/msgpack_rpc@v3.1.4/session.ts:108:18
[denops]     at async Session.handleRequest (https://deno.land/x/msgpack_rpc@v3.1.4/session.ts:104:29)
[denops]     at Session.call (https://deno.land/x/msgpack_rpc@v3.1.4/session.ts:207:13)
[denops]     at async DenopsImpl.call (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/vim-denops/denops.vim/denops/@denops/denops.ts:142:12)
[denops]     at async Promise.all (index 1)
[denops]     at async Source.gatherCandidates (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc-nvim-lsp/denops/@ddc-sources/nvim-lsp.ts:61:23)
[denops]     at async callSourceGatherCandidates (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc.vim/denops/ddc/ddc.ts:780:12)
[denops]     at async file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc.vim/denops/ddc/ddc.ts:372:21
[denops]     at async Promise.all (index 0)
[denops]     at async Ddc.gatherResults (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc.vim/denops/ddc/ddc.ts:321:16)
[denops]     at async doCompletion (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc.vim/denops/ddc/app.ts:268:39)
[denops]     at async Session.onEvent (file:///Users/nabezokodaikon/.cache/dein/repos/github.com/Shougo/ddc.vim/denops/ddc/app.ts:174:7)
Shougo commented 2 years ago

OK. I get the problem. cssls only supports snippet.

nabezokodaikon commented 2 years ago

Confirmed. Thank you.

110y commented 2 years ago

@Shougo

I found that the snippets are no longer expanded after the commit a5f9c16 has been merged and the commit includes the comment that says // Note: Does not insert snippet directly. So is the behavior intentional...? Actually, I was using the snippets usefully with gopls which is a language server for Go and supports snippets.

Shougo commented 2 years ago

This is intentional behavior. ddc.vim is not snippet plugin. And snippet plugin should not be required.

Note: nvim-cmp supports the feature, but it requires snippet plugin for the reason. https://github.com/hrsh7th/nvim-cmp/issues/373

If you need to expand snippets, please install snippet plugin instead.

For example, vim-vsnip supports the snippet expansion.

110y commented 2 years ago

@Shougo

Got it, thank you for your kind explanation.