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

Also Add argument names on completing lsp snippets for functions. #479

Closed
the-fuckin-nobody opened this issue Dec 9, 2024 · 9 comments
Closed
Labels
feature New feature or request

Comments

@the-fuckin-nobody
Copy link

Feature Description

The title is pretty self explanatory.

blink-cmp does not add default argument names on completing an lsp snippet as shown below:

image

This is how nvim-cmp behaves on accepting an lsp snippet from completion menu:

image

@the-fuckin-nobody the-fuckin-nobody added the feature New feature or request label Dec 9, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 9, 2024

This is up to the LSP so you may be missing the LSP capabilities section from the installation section. Blink doesn't do anything special here

@Saghen Saghen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
@the-fuckin-nobody
Copy link
Author

This is up to the LSP so you may be missing the LSP capabilities section from the installation section. Blink doesn't do anything special here

Can you please elaborate this?

This what I set my client capabilities to be:

M.client_capabilities = function()
	return {
		textDocument = {
			completion = {
				dynamicRegistration = false,
				completionItem = {
					snippetSupport = true,
					commitCharactersSupport = true,
					deprecatedSupport = true,
					preselectSupport = true,
					tagSupport = {
						valueSet = {
							1, -- Deprecated
						},
					},
					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",
					},
				},
			},
		},
	}
end

Its been the same with nvim-cmp and blink.cmp

@the-fuckin-nobody
Copy link
Author

the-fuckin-nobody commented Dec 9, 2024

If I am getting you right, I do not think the capabilities part has anything to do with this, as I have explicitly setup my client capabilities in a separate file.

Please correct me if I am wrong

@Saghen
Copy link
Owner

Saghen commented Dec 9, 2024

Hmm your capabilities seem fine, although you should use the capabilities from blink since some of the settings (i.e. some of the keys in resolveSupport.properties) are not supported. Try logging the resolved_item in lua/blink/cmp/completion/accept/init.lua and posting it here. That should confirm whether it's an LSP issue or not

@the-fuckin-nobody
Copy link
Author

Sorry for the late response, I was trying to figure out how to do this?

Try logging the resolved_item in lua/blink/cmp/lua/completion/accept/init.lua and posting it here.

I tried printing resolved_item but it seems to be a table, and its just printing a table id(skill issue).

@Saghen
Copy link
Owner

Saghen commented Dec 9, 2024

Haha that's not your fault, I shouldn't have been so vague. You'll want to use vim.print on it rather than print

@the-fuckin-nobody
Copy link
Author

Damn!, I totally forgot about vim.print , thanks for reminding ;-)

So here's what it spewed:

{- INSERT --
  data = {
    id = 195,
    uri = "file:///home/dex/.config/nvim/init.lua"
  },
  detail = "function",
  documentation = {
    kind = "markdown",
    value = '```lua\nfunction _G.require(modname: any)\n  -> unknown\n  2. unknown|nil\n  3. unknown|nil\n  4. unkn
own|nil\n  5. unknown|nil\n  6. unknown|nil\n  7. unknown|nil\n  8. unknown|nil\n  9. unknown|nil\n 10. unknown|nil
\n```\n\n---\n\n```lua\nfunction require(modname: string)\n  -> unknown\n```\n\n---\n\n\nLoads the given module, re
turns any value returned by the given module(`true` when `nil`).\n\n[View documents](http://www.lua.org/manual/5.4/
manual.html#pdf-require)\n\n---\n\n```lua\n  _G.require = function(modname)\n    local Util = package.loaded["lazy.
core.util"]\n    if Util and not done[modname] then\n      done[modname] = true\n      Util.track({ require = modna
me })\n\n```'
  },
  insertText = "require",
  insertTextFormat = 2,
  kind = 3,
  label = "require(modname)",
  sortText = "0014"

@Saghen
Copy link
Owner

Saghen commented Dec 9, 2024

I'm not sure why but your LSP is returning just the require and blink is filling in the parenthesis, so not much I can do on my side :/

  insertText = "require", -- what to insert on accept
  insertTextFormat = 2, -- indicates it's a snippet

It's possible that nvim-cmp is implementing a hack for this, based on the label, but I'll avoid doing that, in favor of having the LSPs return better items

@the-fuckin-nobody
Copy link
Author

the-fuckin-nobody commented Dec 9, 2024

It's possible that nvim-cmp is implementing a hack for this, based on the label

Yeah , got it now.

but I'll avoid doing that, in favor of having the LSPs return better items.

No problem, not something super important but in some cases it helps me to tab my way out of the function if the parameter and argument name are same.

Atleast I learned something new today, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants