Saghen / blink.cmp

Performant, batteries-included completion plugin for Neovim
MIT License
631 stars 26 forks source link

Expose Insert vs. Replace accept behaviour #58

Closed nmiguel closed 1 day ago

nmiguel commented 2 days ago

Some LSP's like gopls and lua_ls are replacing instead of inserting when a completion is accepted. In Lua_ls' case this was not happening with nvim-cmp, so at least for Lua it seems to be caused by the plugin.

To exemplify what I mean: if I place my cursor at the beginning of the word foo and get a completion for bar, I'd expect to get barfoo, but get only bar.

Here is my config for blink and some LSP stuff just to make sure the problem is not there.

    opts = {
        nerd_font_variant = "normal",
        trigger = { signature_help = { enabled = true } },
        keymap = {
            accept = "<C-y>",
            select_next = "<C-n>",
            select_prev = "<C-p>",
            snippet_forward = "<Tab>",
            snippet_backward = "<S-Tab>",
        },
        accept = {
            create_undo_point = false,

        },
        windows = {
            autocomplete = {
                border = "single",
            },
            documentation = {
                border = "single",
            },
            signature_help = {
                border = "single",
            },
        },
    },
            local capabilities = vim.lsp.protocol.make_client_capabilities()
            capabilities.textDocument = {
                textDocument = {
                    completion = {
                        dynamicRegistration = true,
                        completionItem = {
                            snippetSupport = true,
                            commitCharactersSupport = false,
                            deprecatedSupport = true,
                            preselectSupport = false,
                            insertReplaceSupport = true,
                            resolveSupport = {
                                properties = {
                                    "documentation",
                                    "detail",
                                    "additionalTextEdits",
                                    "sortText",
                                    "filterText",
                                    "insertText",
                                    "textEdit",
                                    "insertTextFormat",
                                    "insertTextMode",
                                },
                            },
                            insertTextModeSupport = {
                                valueSet = {
                                    1, -- asIs
                                    2, -- adjustIndentation
                                },
                            },
                            labelDetailsSupport = true,
                        },
                        contextSupport = true,
                        insertTextMode = 1,
                        completionList = {
                            itemDefaults = {
                                "commitCharacters",
                                "editRange",
                                "insertTextFormat",
                                "insertTextMode",
                                "data",
                            },
                        },
                    },
                },
            }
            lspconfig.lua_ls.setup({
                capabilities = capabilities,
                settings = {
                    Lua = {
                        workspace = {
                            checkThirdParty = false,
                        },
                        codeLens = {
                            enable = true,
                        },
                        completion = {
                            callSnippet = "Insert",
                        },
                        doc = {
                            privateName = { "^_" },
                        },
                        hint = {
                            enable = true,
                            setType = false,
                            paramType = true,
                            paramName = "Disable",
                            semicolon = "Disable",
                            arrayIndex = "Disable",
                        },
                    },
                },
            })
stefanboca commented 1 day ago

I'm not sure if this is the same issue but I'm still facing something similar.

Consider (in lua):

local foo = { bar = {} }

When I type

foo.

and I select and accept bar from the completion menu, the entire line is replaced, so rather than foo.bar I now have just bar. This is incorrect because as a field of foo, inserting bar should not remove foo.

If instead I type

foo.b

and then accept bar from the completion menu, the completion is correctly applied and the line becomes foo.bar.

You can see this behavior in the following video:

https://github.com/user-attachments/assets/f2bcacb2-412e-466a-b1e4-c9169fa785a9

As a side note, when I type

foo.

the completion menu also displays snippets, such as if and date. This is also visible in the above video. Accepting a snippet instead of a field replaces the entire line as well, which I believe is the correct behavior.

Saghen commented 1 day ago

Sounds like a different issue, but it should be fixed by https://github.com/Saghen/blink.cmp/commit/fc348dac16f190042d20aee62ea61b66c7c1380a