Skip to content
New issue

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

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

Already on GitHub? # to your account

Transform completion items to snippets #465

Closed
kkharji opened this issue Nov 3, 2021 · 3 comments
Closed

Transform completion items to snippets #465

kkharji opened this issue Nov 3, 2021 · 3 comments

Comments

@kkharji
Copy link

kkharji commented Nov 3, 2021

Hello there, I'd like to edit a source to return a snippet for methods that has the method name and paramters as snippet. Any ideas?

Thanks

@arpangreat
Copy link

Hello there, I'd like to edit a source to return a snippet for methods that has the method name and paramters as snippet. Any ideas?

Thanks

You can use https://github.com/L3MON4D3/LuaSnip

And define you own snippets , that can do the job too.

@kkharji
Copy link
Author

kkharji commented Nov 3, 2021

I understand, but I want to make function items from lsp auto becomes snippet e.g.

lsp return symbol , cmp <cr>, symbol() {}

@dmitmel
Copy link
Collaborator

dmitmel commented Nov 28, 2021

Not sure if this is what you want, but here's a thing that I do for Pyright to return snippets which insert the call parentheses for functions:

lspconfig['pyright'].setup({
  on_init = function(client)
    local orig_rpc_request = client.rpc.request
    function client.rpc.request(method, params, handler, ...)
      local orig_handler = handler
      if method == 'textDocument/completion' then
        -- Idiotic take on <https://github.com/fannheyward/coc-pyright/blob/6a091180a076ec80b23d5fc46e4bc27d4e6b59fb/src/index.ts#L90-L107>.
        handler = function(...)
          local err, result = ...
          if not err and result then
            local items = result.items or result
            for _, item in ipairs(items) do
              if not (item.data and item.data.funcParensDisabled) and (
                item.kind == lsp.protocol.CompletionItemKind.Function or
                item.kind == lsp.protocol.CompletionItemKind.Method or
                item.kind == lsp.protocol.CompletionItemKind.Constructor
              ) then
                item.insertText = item.label .. '($1)$0'
                item.insertTextFormat = lsp.protocol.InsertTextFormat.Snippet
              end
            end
          end
          return orig_handler(...)
        end
      end
      return orig_rpc_request(method, params, handler, ...)
    end
  end;
})

@kkharji kkharji closed this as completed Jan 13, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants