shun / ddc-source-vim-lsp

vim-lsp source for ddc.vim
MIT License
44 stars 13 forks source link

Position for completions calculated by vim-lsp is not used #19

Closed dotdash closed 1 year ago

dotdash commented 1 year ago

vim-lsp calculates where a completion should be positioned, and ddc-source-vim-lsp should implement getCompletePosition to provide this value to ddc, otherwise ddc might insert the completion at the wrong position because it uses ddc-option-keywordPattern which isn't always correct.

For example with PHP code as follows:

    $nodes = [$r

and getting a completion, the result is:

    $nodes = [$$root

because ddc does not consider replacing $, while vim-lsp wants it to be replaced.

shun commented 1 year ago

@dotdash Could you give me your minimal settings ? How about this behavior ? Please see the video.

https://github.com/shun/ddc-source-vim-lsp/assets/212602/f953cea8-ef2d-49ad-b681-a03402110ec4

vim: 9.0.1600 ddc: v3.5.1 my minimal settings is below.

set encoding=utf-8
scriptencoding utf-8
set nocp
set signcolumn=yes

let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_logiPat = 1
let g:loaded_spellfile_plugin = 1
let g:loaded_rrhelper = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1

let s:dein_repo_dir = expand('~/.cache/vim.min/repos/github.com/Shougo/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

if dein#load_state('~/.cache/vim.min/')
    call dein#begin('~/.cache/vim.min/')
    call dein#add('prabirshrestha/vim-lsp')
    call dein#add('mattn/vim-lsp-settings')
    call dein#add('vim-denops/denops.vim')
    call dein#add('Shougo/ddc.vim')
    call dein#add('Shougo/ddc-ui-pum')
    call dein#add('Shougo/pum.vim')
    call dein#add('Shougo/ddc-filter-matcher_head')
    call dein#add('Shougo/ddc-filter-sorter_rank')
    call dein#add('shun/ddc-source-vim-lsp')
    call dein#end()
    call dein#save_state()
endif

if dein#check_install()
    call dein#install()
endif
filetype plugin indent on
syntax enable

call ddc#custom#patch_global('ui', 'pum')
call ddc#custom#patch_global('sources', ['vim-lsp'])
call ddc#custom#patch_global('sourceOptions', {
  \ '_': {
  \   'ignoreCase': v:true,
  \   'matchers': ['matcher_head'],
  \   'sorters': ['sorter_rank'],
  \ },
  \ 'vim-lsp': {
  \     'mark': 'LSP',
  \     'forceCompletionPattern': '\$|\.|:|->|"\w+/*',
  \     'minAutoCompleteLength': 1,
  \ },
  \ })
call pum#set_option({ 'use_complete': v:true })
call ddc#enable()

inoremap <silent><expr> <TAB> ddc#map#manual_complete()
inoremap <C-n>   <Cmd>call pum#map#select_relative(+1)<CR>
inoremap <C-p>   <Cmd>call pum#map#select_relative(-1)<CR>
inoremap <C-y>   <Cmd>call pum#map#confirm()<CR>
inoremap <C-o>   <Cmd>call pum#map#confirm_word()<CR>
let g:lsp_log_file = expand('/tmp/vim-lsp.log')
shun commented 1 year ago

Let me close this issue, because of no reaction.

basilgood commented 1 year ago

Hello! I want to create a vim config with ddc and lsp. I want vim and not neovim. With neovim + ddc and plugins all works perfectly. But in vim with exactly your above config I obtain something unusable. First time I press Tab for manual complete and after that <C-y> to confirm. Second time I press Tab for manual complete and after that <C-o> to confirm_word. Here's what i get:

https://github.com/shun/ddc-source-vim-lsp/assets/16057481/95c7ea12-99cd-4c18-bd88-e63741bdd117

basilgood commented 1 year ago

After this commit https://github.com/Shougo/ddc.vim/commit/4f19a82f216f706e51cfa5c37a95c29649a78830 this plugin doesn't work anymore

Shougo commented 1 year ago

@basilgood #20 fixes the problem. Please test.

And you should create new issue with the minimal vimrc like this. https://github.com/shun/ddc-source-vim-lsp/issues/19#issuecomment-1593290640

And your video is broken. I cannot look it.

Shougo commented 1 year ago

First time I press Tab for manual complete and after that <C-y> to confirm. Second time I press Tab for manual complete and after that <C-o> to confirm_word.

You should explain more detailed.

Both expected behavior and actual behavior needed.

basilgood commented 1 year ago

I apologize for the inconvenience. Facing the problem that ddc-source-vim-lsp doesn't work in vim, I found this issue and it seemed to me that it fits my problem. I took the minimal vimrc exemplified above by @shun https://github.com/shun/ddc-source-vim-lsp/issues/19#issuecomment-1593290640 and I tested. After seeing that it doesn't work, I recorded my desktop to show that the example provided by @shun is not good either. For this reason I didn't opened a new issue. But now I realized that in fact the problem is maybe because of ddc.vim. I'm sorry if you can't see the video but in my browser it's visible. I'm testing now again with above minimal vimrc and and come with the answer. Thank you for the quick response.

basilgood commented 1 year ago

I continue here because it's related to example that @shun provided above. minimal vimrc it's https://github.com/shun/ddc-source-vim-lsp/issues/19#issuecomment-1593290640 with ddc.vim updated with latest changes. In insert mode I type nn after that I press Tab key for manual complete. The completion appeared and with <C-n> I chose nnoremap. After that I press <C-y> to confirm completion. It's inserted nnnnoremap and that is the actual behavior. The expected behavior: to insert nnoremap I tested with and without: 'forceCompletionPattern': '\$|\.|:|->|"\w+/*', but also with another one with modification: 'forceCompletionPattern': '\.\w*|:\w*|->\w*', My question is: is there still a need for forceCompletionPattern ? And second one: It's not expected that the autocompletion from vim-lsp will open automatically without pressing tab key ? Please provide a minimal and functional vimrc. I also tested in a javascript file but there the behavior it's worse.

https://github.com/shun/ddc-source-vim-lsp/assets/16057481/95a1cdac-3057-433f-86ff-22a582c5d2cb

Shougo commented 1 year ago

My question is: is there still a need for forceCompletionPattern ?

It is not needed if you want to complete manually.

basilgood commented 1 year ago

this is with forceCompletionPattern and with example above

https://github.com/shun/ddc-source-vim-lsp/assets/16057481/2569a498-8a6f-4d94-a9af-d649c81a98aa

Shougo commented 1 year ago
set encoding=utf-8
scriptencoding utf-8
set nocp
set signcolumn=yes

let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_logiPat = 1
let g:loaded_spellfile_plugin = 1
let g:loaded_rrhelper = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1

set rtp+=~/src/vim-lsp
set rtp+=~/src/vim-lsp-settings
set rtp+=~/work/denops.vim
set rtp+=~/work/ddc.vim
set rtp+=~/work/ddc-ui-pum
set rtp+=~/work/pum.vim
set rtp+=~/work/ddc-filter-matcher_head
set rtp+=~/work/ddc-filter-sorter_rank
set rtp+=~/src/ddc-source-vim-lsp

filetype plugin indent on
syntax enable

call ddc#custom#patch_global('ui', 'pum')
call ddc#custom#patch_global('sources', ['vim-lsp'])
call ddc#custom#patch_global('sourceOptions', {
  \ '_': {
  \   'ignoreCase': v:true,
  \   'matchers': ['matcher_head'],
  \   'sorters': ['sorter_rank'],
  \ },
  \ 'vim-lsp': {
  \     'mark': 'LSP',
  \     'forceCompletionPattern': '\$|\.|:|->|"\w+/*',
  \     'minAutoCompleteLength': 1,
  \ },
  \ })
call pum#set_option({ 'use_complete': v:true })
call ddc#enable()

inoremap <silent><expr> <TAB> ddc#map#manual_complete()
inoremap <C-n>   <Cmd>call pum#map#select_relative(+1)<CR>
inoremap <C-p>   <Cmd>call pum#map#select_relative(-1)<CR>
inoremap <C-y>   <Cmd>call pum#map#confirm()<CR>
inoremap <C-o>   <Cmd>call pum#map#confirm_word()<CR>
let g:lsp_log_file = expand('/tmp/vim-lsp.log')

I have tested the vimrc. I have used Vim and edit the vimrc.

In insert mode I type nn after that I press Tab key for manual complete.
The completion appeared and with <C-n> I chose nnoremap.
After that I press <C-y> to confirm completion.
It's inserted nnnnoremap and that is the actual behavior.

I don't reproduce the behavior. Have you tested the version https://github.com/shun/ddc-source-vim-lsp/pull/20?

Shougo commented 1 year ago

Ah, I get it. It is fixed by #20. current main branch is reproduced.

basilgood commented 1 year ago

Oh yes it works with https://github.com/shun/ddc-source-vim-lsp/pull/20 Thank you very much for all your beautiful work :heart: