-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
feat(cpp <> pairs) auto add <> for templates,includes and templated types #407
Conversation
windpw this uses set_current_line i could migrate it to only use keys but that would make the code much less readable |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Awesome feature, I have a question on whether it would be possible to have both autopair's default |
I think that would make the code a bit messy, Because it would be language-specific code in the general confirm_done callback.
I think it would have to be manually added for each language. templates and #include have a hardcoded check for cpp. |
Thank you for the quick answer! |
So I decided to keep it stupid and wrote my simple callback: local function on_confirm_done(evt)
local entry = evt.entry
local item = entry:get_completion_item()
local types = require("cmp.types")
if evt.commit_character then
return
end
if item.label:find('<>') and vim.bo.filetype == "cs" and entry:get_kind() == types.lsp.CompletionItemKind.Class then
local keys = vim.api.nvim_replace_termcodes('<><left>', false, false, true)
vim.api.nvim_feedkeys(keys, "i", true)
return
end
if
vim.bo.filetype == "cs"
and (
entry:get_kind() == types.lsp.CompletionItemKind.Function
or entry:get_kind() == types.lsp.CompletionItemKind.Method
or entry:get_kind() == types.lsp.CompletionItemKind.Class
)
then
local keys = vim.api.nvim_replace_termcodes('()<left>', false, false, true)
vim.api.nvim_feedkeys(keys, "i", true)
return
end
end Now I can ditch nvim-autopairs as this was the only reason for me to use in the first place. |
@kuator
Also the last parameter should be false, That shouldn't matter thought.
You don't manually write pairs anywhere even for |
I tried to use auto-pair plugins multiple times throughout my vim journey starting from https://github.com/Raimondi/delimitMate and now nvim-autopairs and the behaviour ends up being more annoying than useful. It's simpler for me type the pairs myself. What I also did is I set up the luasnip snippets. One example is |
Honestly, I have no idea how feedkeys works. I did a bit more research and now instead call luasnip: local function on_confirm_done(evt)
local entry = evt.entry
local item = entry:get_completion_item()
local types = require("cmp.types")
if evt.commit_character then
return
end
if item.label:find('<>') and vim.bo.filetype == "cs" and entry:get_kind() == types.lsp.CompletionItemKind.Class then
local ls = require('luasnip')
ls.snip_expand(ls.s("trig", { ls.t"<", ls.i(1, ""), ls.t">" }) )
return
end
if
vim.bo.filetype == "cs"
and (
entry:get_kind() == types.lsp.CompletionItemKind.Function
or entry:get_kind() == types.lsp.CompletionItemKind.Method
or entry:get_kind() == types.lsp.CompletionItemKind.Class
)
then
local ls = require('luasnip')
ls.snip_expand(ls.s("trig", { ls.t"(", ls.i(1, ""), ls.t")" }) )
return
end
end |
this issue #405 inspired me to make this pr
this pr adds
cpp_pairs
to the completion pairswhich does
cpp_sort_cmp
is there to make sure templated classes are picked over constructors for templated classeswithout this we wouldn't detect templated classes