Shougo / ddc-source-lsp

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

[Question] CSS LSP input. #24

Closed nabezokodaikon closed 2 years ago

nabezokodaikon commented 2 years ago

Problems summary

I don't know the proper setting for CSS forceCompletionPattern. Completion candidates that start with a colon are not entered correctly.

Expected

Find out the proper settings for the CSS forceCompletionPattern.

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.

nvim-cmp setup

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('hrsh7th/nvim-cmp')
call dein#add('hrsh7th/cmp-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,
}
local cmp = require('cmp')
cmp.setup {
    mapping = {
        ['<C-p>'] = cmp.mapping.select_prev_item(),
        ['<C-n>'] = cmp.mapping.select_next_item(),
    },
    sources = {
        { name = 'nvim_lsp' }
    },
}
EOF

Screenshot (if possible)

ddc-nvim-lsp スクリーンショット 2021-10-14 23 24 11

nvim-cmp スクリーンショット 2021-10-14 23 41 15

nabezokodaikon commented 2 years ago

I solved it with the following settings.

call ddc#custom#patch_filetype(['css'], {
      \ 'keywordPattern': '[a-zA-Z_:\s]\w*',
      \ 'smartCase': v:true,
      \ })
nabezokodaikon commented 2 years ago

After all I couldn't do it well. The settings are as follows.

call ddc#custom#patch_filetype(['css'], {
      \ 'keywordPattern': '[a-zA-Z_:]\w*',
      \ 'smartCase': v:true,
      \ })
call ddc#custom#patch_filetype(['css'], 'sources', ['nvim-lsp'])
call ddc#custom#patch_filetype(['css'], 'sourceOptions', {
      \ 'nvim-lsp': {
      \   'forceCompletionPattern': ':\s\w*' },
      \ })

The item called Unit of LSP is not completed correctly. タイトルなし

Shougo commented 2 years ago

Your keyword pattern is wrong. You should know what is you have set.

\ 'keywordPattern': '[a-zA-Z_:]\w*', does not match 10.

You need to use \w* instead.

nabezokodaikon commented 2 years ago

I'm sorry. Could you tell me the general settings?

Shougo commented 2 years ago

What is the general? You need to configure plugins as you need.

nabezokodaikon commented 2 years ago

I'm sorry. I would like to know an example of a specific setting method.

Shougo commented 2 years ago

No magic. You need to configure by try and error.

Shougo commented 2 years ago

It means:

If you don't want to configure plugins, you don't have to use the plugin. It does not work with zero configuration. You can use other plugins.

ddc works as you configure.

nabezokodaikon commented 2 years ago

Understood.

Shougo commented 2 years ago

The default pattern is \k*. It may be better if you don't want to configure patterns. But you have changed it. It is own risk.

Shougo commented 2 years ago

I think nvim-lsp may set better pattern automatically from LSP server. But it is not my policy. It is too complicated and it is not easy to configure by users.