Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Insert vs. Replace accept behaviour #58

Closed
nmiguel opened this issue Oct 9, 2024 · 2 comments
Closed

Expose Insert vs. Replace accept behaviour #58

nmiguel opened this issue Oct 9, 2024 · 2 comments

Comments

@nmiguel
Copy link

nmiguel commented Oct 9, 2024

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",
						},
					},
				},
			})
@Saghen Saghen closed this as completed in a7e1acc Oct 9, 2024
@stefanboca
Copy link
Collaborator

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
Copy link
Owner

Saghen commented Oct 9, 2024

Sounds like a different issue, but it should be fixed by fc348da

lopi-py pushed a commit to lopi-py/blink.cmp that referenced this issue Oct 10, 2024
closes Saghen#58
This behavior wasn't obvious and wasn't consistent since it only applied
to LSPs which didn't pass textEdits. This may be re-introduced behind a
flag in the future
lopi-py pushed a commit to lopi-py/blink.cmp that referenced this issue Oct 10, 2024
closes Saghen#58
This behavior wasn't obvious and wasn't consistent since it only applied
to LSPs which didn't pass textEdits. This may be re-introduced behind a
flag in the future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants