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

Lsp snippets complete #193

Closed
2 tasks done
basilgood opened this issue Jan 11, 2023 · 16 comments
Closed
2 tasks done

Lsp snippets complete #193

basilgood opened this issue Jan 11, 2023 · 16 comments
Labels
feature-request Request for a feature to existing module mini.completion

Comments

@basilgood
Copy link

Contributing guidelines

Module(s)

mini.completion

Description

Hi! I really like this plugin.
It is simple and effective.
It's fast and has everything I need except for one thing:

  • lsp snippets completion.

If cssls or cssmodules_ls is active, the server snippets it delivers expand but do
not stop at the placeholder.

RecApp-2023-01-11-10.20.54.mp4

This is my minimal config:

local install_path = vim.fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.fn.system({'git', 'clone', '--depth=1', 'https://github.com/savq/paq-nvim.git', install_path})
end

require('paq')({
  'savq/paq-nvim',
  'echasnovski/mini.completion',
  'neovim/nvim-lspconfig',
  'williamboman/mason.nvim',
})

-- completion
require('mini.completion').setup({
  lsp_completion = {
    source_func = 'omnifunc',
    auto_setup = false,
  },
})
vim.keymap.set('i', '<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]], { remap = true, expr = true })
vim.keymap.set('i', '<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]], { remap = true, expr = true })

-- lsp
local lspconfig = require('lspconfig')
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
local on_attach = function(_, bufnr)
  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.MiniCompletion.completefunc_lsp')
end

require('mason').setup()

local servers = { 'tsserver', 'cssls', 'cssmodules_ls', 'html' }
for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup({
    on_attach = on_attach,
    capabilities = capabilities,
    init_options = { usePlaceholders = true },
  })
end

Without mini.completion using omnifunc <C-x><C-o>
and this setting: vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
it works.
My request is if you can help me achieve this result with mini completion plugin.
Thank you very much for your beautiful work.

@basilgood basilgood added the feature-request Request for a feature to existing module label Jan 11, 2023
@echasnovski
Copy link
Owner

Thanks for the issue!

Sorry, but this is not supported and, probably, won't be supported until there is a 'mini.snippets' module. The main reason is because it is hard to implement this functionality right.

Seems like the reason why you see this in your setup is because you LSP server (cssls or cssmodules_ls) doesn't mark these completion items as "Snippet", using "Property" instead. All completion suggestions that are marked by LSP server as "Snippet" are filtered out in 'mini.completion' (with default settings).

Without mini.completion using omnifunc <C-x><C-o> and this setting: vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") it works.

I am not sure what you mean here by "it works". I tried it with 'sumneko_lua' and it does indeed suggest "Snippet" entries which don't expand properly. You'd need snippet engine for that (like L3MON4D3/LuaSnip.

@basilgood
Copy link
Author

basilgood commented Jan 11, 2023

Thank you for quick response.
About "it works", if I change in the above minimal init config:

--local on_attach = function(_, bufnr)
--  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.MiniCompletion.completefunc_lsp')
--end
local on_attach = function()
  vim.opt_local.omnifunc = 'v:lua.vim.lsp.omnifunc'
end

I can get suggestions with <C-x><C-o> and expand them with <CR> properly.

RecApp-2023-01-11-14.38.50.mp4

@echasnovski
Copy link
Owner

Hmm... This might be due to (not so recently) added built-in snippet parsing using vim.lsp.util.parse_snippet().

I am hesitant to add this, as snippets are not currently supported at all. I'll think about it.

@basilgood
Copy link
Author

Ok! Thanks again for ❤️ mini plugins. If you want you can close issue.

@echasnovski
Copy link
Owner

Yes, I think I'll close this, as 'mini.completion' is not designed (yet, maybe?) to support snippets and this example does seem to come from a misbehaved LSP server (returning snippet-like completion entry as "Property").

@GitMurf
Copy link

GitMurf commented Mar 25, 2024

@echasnovski thank you for your amazing work. Checking in on this as I just started using mini.completion. But I am a bit confused as every LSP I have tried so far when selecting a function will provide placeholder "snippet" locations for function parameters / arguments. Most notably Lua and TypeScript.

Am I doing something wrong or is this expected and I need to manually go remove / fill in each parameter replacing the (${1:param}, ...) everytime I select a function with mini.completion?

image

Is there a way that I could at least just finish the function and not have the placeholders added at all? even if for foo(a, b, c) if I select foo if it just actually returns foo or foo() without any parameters that would be much better than needing to delete everytime.

I have luasnip installed as well but cannot get it to work with it either. Maybe I am just doing something wrong? Thanks again for great work :-)

@echasnovski
Copy link
Owner

Am I doing something wrong or is this expected and I need to manually go remove / fill in each parameter replacing the (${1:param}, ...) everytime I select a function with mini.completion?

Ideally, it should not place those placeholders inside parenthesis. I can not reproduce with my setup, so could you please somehow share how you set up both 'mini.completion' and LSP for Lua? Preferably in a minimal reproduction 'init.lua' which only contains code enough to reproduce the issue.

@GitMurf
Copy link

GitMurf commented Mar 25, 2024

@echasnovski as I am diving into this I believe this could be a windows issue and compatibility with the required jsregexp from luarocks.

See here from luasnip: https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#transformations

See here from kickstart where they essentially say that they could not figure out how to make it windows compatible: nvim-lua/kickstart.nvim#611 (comment)

And here is an issue in luasnip repo about windows: L3MON4D3/LuaSnip#986

This all being said, what options do I have assuming we are stuck with the function parameter snippet syntax coming through? is there a callback/hook we can utilize on selection of a completion item where I could either parse myself, or just clear out the function (params) and just return function() or function? Honestly the parsing should be quite simple for function(${n:name}, ${n:name}) as can just take what is between :xyz} which will be the parameter names and just end up with function(abc, xyz) which is much easier to deal with to replace after accepting completion.

@echasnovski thoughts?

@echasnovski
Copy link
Owner

I am not sure how LuaSnip is relevant here, as 'mini.completion' does not integrate with any snippet engines (right now).

So if this result is from 'mini.completion', then it has to come from LSP server. And currently I am not sure what config can reproduce this issue (preferably on Linux, as I don't have access to Windows).

@GitMurf
Copy link

GitMurf commented Mar 25, 2024

I am not sure how LuaSnip is relevant here, as 'mini.completion' does not integrate with any snippet engines (right now).

I was under the assumption that LuaSnip actually hooked itself into the LSP and essentially "intercepted" and did something with handling of LSP function snippets. But that is likely a poor assumption.

@GitMurf
Copy link

GitMurf commented Mar 25, 2024

@echasnovski maybe it would help if I knew what it is supposed to look like simply with Lua as the LSP source when you are autocompleting lets say vim.api.nvim_buf_set_option() (since that was the example I used in the screenshot above. Here is a quick video showing how it looks on my end to make sure everything else appears as expected (to validate I am not doing / expecting something else weird).

WindowsTerminal.-.PowerShell_yUODEAn5jU_2024-03-25_14-43-52.mp4

@echasnovski
Copy link
Owner

echasnovski commented Mar 26, 2024

I was under the assumption that LuaSnip actually hooked itself into the LSP and essentially "intercepted" and did something with handling of LSP function snippets. But that is likely a poor assumption.

I don't think it does that.

@echasnovski maybe it would help if I knew what it is supposed to look like simply with Lua as the LSP source when you are autocompleting lets say vim.api.nvim_buf_set_option() (since that was the example I used in the screenshot above.

It should work more or less the same but without adding parenthesis (with their contents) when navigating through the completion suggestions. For hands-on example, you disable 'mini.completion' (not load in 'init.lua') and instead have vim.o.omnifunc = 'v:lua.vim.lsp.omnifunc'. To have a list of completion suggestions, press <C-x><C-o>.

For this to be more productive, at least some reproducible setup (OS, Neovim version, config, and exact steps) would indeed help.

@GitMurf
Copy link

GitMurf commented Mar 27, 2024

@echasnovski is it sufficient to tell you i am on windows 11, using nightly nvim and can reproduce with kickstart? I believe you know tj and i'm sure are familiar with the project? I cloned this in a fresh nvim: https://github.com/nvim-lua/kickstart.nvim

And then simply disabled nvim-cmp and added mini.completion with the default setup config.

Here is a branch straight from kickstart with just 2 commits to disable cmp and add mini.completion: https://github.com/GitMurf/kickstart.nvim/tree/2024_03/mini.completion-troubleshoot

@echasnovski
Copy link
Owner

Sorry it took so long to look at.

A quick search for "completion" in the 'init.lua' showed me that lua-language-server is configured that way in the Kickstart. I was finally able to reproduce this by also setting Lua.completion.callSnippet = 'Replace' in my config. Removing those lines should fix the issue.

@GitMurf
Copy link

GitMurf commented Mar 31, 2024

A quick search for "completion" in the 'init.lua' showed me that lua-language-server is configured that way in the Kickstart. I was finally able to reproduce this by also setting Lua.completion.callSnippet = 'Replace' in my config. Removing those lines should fix the issue.

Thanks for investigating! Makes sense. But the weird thing is my typescript lsp is doing the same thing and I did not change any configuration for it. Any ideas of why typescript may be? Could it be doing the "replace" out of the box?

@echasnovski
Copy link
Owner

Thanks for investigating! Makes sense. But the weird thing is my typescript lsp is doing the same thing and I did not change any configuration for it. Any ideas of why typescript may be? Could it be doing the "replace" out of the box?

Typescript language server is a bit of a mystery to me, to be honest. I think I saw an instance or two when completion item was declared as not having "Snippet" kind but expanded into a snippet.

All in all, I am fairly certain that this is an issue with LSP server (either how it is set up or its internals) and not 'mini.completion' itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.completion
Projects
None yet
Development

No branches or pull requests

3 participants