Shougo / ddc-source-lsp

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

Last typed word remain as completion matcher even after deleting it #38

Closed azufr closed 1 year ago

azufr commented 1 year ago

Warning: I will close the issue without the minimal init.vim and the reproduction instructions.

Problems summary

Last typed character or word? remain as completion matcher even after deleting it using backspace. As a result, only completion candidates that matched with last typed word are returned

Expected

After deleting word or character, completion matcher should be reset to empty string and all completion candidates should be return

Environment Information

Run :checkhealth for more info


## Provide a minimal init.vim/vimrc without plugin managers (Required!)

```lua
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/denops.vim' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/ddc.vim' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/ddc-around' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/ddc-fuzzy' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/ddc-ui-pum' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/pum.vim' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/ddc-source-nvim-lsp' })
vim.opt.runtimepath:append({ '~/.local/share/nvim/lazy/nvim-lspconfig' })

vim.opt.completeopt = { 'menu', 'menuone', 'noinsert' }
vim.fn['pum#set_option']('use_complete', false)
vim.fn['pum#set_option']('scrollbar_char', '')
local ddc_opts = {
    ui = 'pum',
    autoCompleteEvents = { 'InsertEnter', 'TextChangedI', 'TextChangedP', 'CmdlineChanged', 'CmdlineEnter' },
    sources = { 'nvim-lsp', 'around' },
    sourceOptions = {
        _ = {
            matchers = { 'matcher_fuzzy' },
            sorters = { 'sorter_fuzzy' }
        },
        ['nvim-lsp'] = {
            mark = '[lsp]',
            dup = 'keep',
            forceCompletionPattern = [[\.\w*|:\w*|->\w*]],
            minAutoCompleteLength = 2,
            maxItems = 1000,
            ignoreCase = true,
        },
        ['around'] = {
            mark = '[A]'
        }
    }
}

vim.fn['ddc#custom#patch_global'](ddc_opts)
vim.fn['ddc#enable']()

vim.keymap.set('i', '<C-y>', '<cmd>call pum#map#confirm()<cr>')
vim.keymap.set('i', '<C-e>', '<cmd>call pum#map#cancel()<cr>')
vim.keymap.set('i', '<C-n>', '<cmd>call pum#map#insert_relative(+1)<cr>')
vim.keymap.set('i', '<C-p>', '<cmd>call pum#map#insert_relative(-1)<cr>')

-- Setup language servers.
local lspconfig = require('lspconfig')
lspconfig.pyright.setup({
    cmd = { '/opt/language-servers/bin/pyright-langserver', '--stdio' }
})

-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
    group = vim.api.nvim_create_augroup('UserLspConfig', {}),
    callback = function(ev)
        -- Enable completion triggered by <c-x><c-o>
        vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'

        -- Buffer local mappings.
        -- See `:help vim.lsp.*` for documentation on any of the below functions
        local opts = { buffer = ev.buf }
        vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
        vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
        vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
        vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
        vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
        vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
        vim.keymap.set('n', '<space>wl', function()
            print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
        end, opts)
        vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
        vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
        vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
        vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
        vim.keymap.set('n', '<space>f', function()
            vim.lsp.buf.format { async = true }
        end, opts)
    end,
})

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

following steps are for python/pyright languange server. this problem also happened with lua/lua-ls.

  1. open .py file
  2. type the following
    import os
    os.path
  3. delete .path part
  4. type . and only candidate match with path are returned.
  5. It should be reset and return all completion candidates from os module

Screenshot (if possible)

last-word-delete-remain

Upload the log messages by :redir and :message (if errored)

No Error

Shougo commented 1 year ago

You need to set backspaceCompletion option.

                *ddc-option-backspaceCompletion*
backspaceCompletion
        If it is enabled, ddc.vim will complete even when backspace is
        typed.
        Note: It is disabled by default since backspace completion
        will cause completion flicker.

        Default: v:false
azufr commented 1 year ago

It was fixed by this. Thanks.