Comments (21)
Currently that specific feature is not possible.
I may decide to add the feature in the future.
from ultimate-autopair.nvim.
If anyone wants this feature before I implement it:
local cmp=require('cmp')
local Kind=cmp.lsp.CompletionItemKind
cmp.event:on(
'confirm_done',
function (evt)
if vim.tbl_contains({Kind.Function,Kind.Method},evt.entry:get_completion_item().kind) then
vim.api.nvim_feedkeys('()'..vim.api.nvim_replace_termcodes('<Left>',true,true,true),'n',false)
end
end)
from ultimate-autopair.nvim.
I modified @altermo's temporary solution to exclude lua_ls
and rust_analyzer
, since they already create pairs themselves.
The pcall
is to catch any null pointer exception when doing event.entry.source.source.client.config.name
.
local cmp = require('cmp')
local ind = cmp.lsp.CompletionItemKind
local function ls_name_from_event(event)
return event.entry.source.source.client.config.name
end
-- Add parenthesis on completion confirmation
cmp.event:on('confirm_done', function(event)
local ok, ls_name = pcall(ls_name_from_event, event)
if ok and vim.tbl_contains({ 'rust_analyzer', 'lua_ls' }, ls_name) then
return
end
local completion_kind = event.entry:get_completion_item().kind
if vim.tbl_contains({ ind.Function, ind.Method }, completion_kind) then
local left = vim.api.nvim_replace_termcodes('<Left>', true, true, true)
vim.api.nvim_feedkeys('()' .. left, 'n', false)
end
end)
from ultimate-autopair.nvim.
Looking forward to this useful feature!
from ultimate-autopair.nvim.
It will take some time until I come up with a good design, so in the meantime, I created an experimental version.
To use it:
require'ultimate-autopair'.init({
require'ultimate-autopair'.extend_default{
--Normal config goes here
},
{profile=require'ultimate-autopair.experimental.cmpair'.init},
})
from ultimate-autopair.nvim.
Yes, use require'ultimate-autopair.maps.cr'.cmpnewline()
like so:
cmp.mapping(function()
if cmp.get_active_entry() then
cmp.confirm()
else
require'ultimate-autopair.maps.cr'.cmpnewline()
end
end)
from ultimate-autopair.nvim.
Hello, I'm still looking forward to this useful feature
from ultimate-autopair.nvim.
Yes sir. This is the last reason I still use nvim-autopairs.
from ultimate-autopair.nvim.
Hi again, thanks for the help! I might have missed something, but I couldn't make it work with your code snippet. In case my request didn't go through: I was asking whether it is possible to add a pair of parenthesis to a cmp completion item which is a function. This was accomplishable by nvim-autopairs
as shown in the link I provided above. I am not good at reading lua code or nvim apis, but I didn't see the part related to check whether the completion item is a function and adding the parenthesis etc. in the cmpnewline
function. I would appreciate your help again!
from ultimate-autopair.nvim.
This is a gif showing the effect that I want to achieve:
from ultimate-autopair.nvim.
This feature is indeed very useful, looking forward to it 😄
from ultimate-autopair.nvim.
Sorry, currently don't find the resources, but doesn't nvim-cmp
support inserting parenthesis after the completion by itself?
from ultimate-autopair.nvim.
If it does then I can't figure out how to. I just switched from LazyVim to Kickstart and I tried getting the function completion to work like lazy had.and lazy doesn't use the cmp:on_event trick but I have no idea how it gets function completion to work otherwise.
from ultimate-autopair.nvim.
Okay, it seems like this is a feature of the LSP completion where some servers provide this feature by using snippets. Sorry.
from ultimate-autopair.nvim.
Very wholesome, very useful feature. In the meantime try and configure the LSP you use to send snippets for completion. This varies per LSP. That's how I got around it so far. Clangd, jdtls, luals, and pyright all support it. So thats all I need for now.
from ultimate-autopair.nvim.
I was actually thinking about exactly such a solution. Probably just need to make it a liiiittle more advanced, so it does not interfere with server which do actually send additional snippets to add them too.
from ultimate-autopair.nvim.
@altermo This works great, but I found that it doesn't work on JavaScript/TypeScript arrow functions:
const foo = (bar, baz) => bar + baz;
I realize that this is trickier, but is this something that would be possible to support?
from ultimate-autopair.nvim.
How would it work exactly?
What would the trigger be for the auto parentheses?
from ultimate-autopair.nvim.
As I was typing out a response to this I realize that it's probably too difficult :)
from ultimate-autopair.nvim.
Hi @mawkler, thanks a lot , I have used your config with pylsp very well
from ultimate-autopair.nvim.
Is there an official response why something like this isn't implemented in cmp-nvim directly? Or at least a snippet like this for those that don't want to rely on per-autopair plugin implementation. I don't think that any autopair plugin actually needs to insert that parenthesis pair in a special way. Unless it does?
P.S. I started searching here after I stumbled upon hrsh7th/nvim-cmp#1672. I also had to include tinymist
in the list.
from ultimate-autopair.nvim.
Related Issues (20)
- Feature request: Rust lifetime syntax support HOT 19
- [Question] How to ignore a specific parser? HOT 1
- Builtin C-style block comment support HOT 2
- [Question] - JSX Support HOT 4
- alpha extension unexpected behavior HOT 2
- Support for lua `[=[...]=]` string? HOT 4
- [Performance] Holding on space in large markdown files freeze the editor HOT 3
- [Bug] Incorrect pair exiting behavior HOT 1
- [BUG] Wrong behavior when deleting asterisk in makdown files HOT 1
- Healthcheck fails saying parser is missing for 'lua' HOT 4
- [Feature Request] Specify pairs by regular expression HOT 2
- Way to prevent autocomplete if Esc is pressed? HOT 13
- Delete comma after pair HOT 6
- Undo mappings in insert mode don't work as expected HOT 3
- [BUG] Installing ultimate-autopair causes luasnip to malfunction HOT 2
- Parenths don't auto close in swift files with swift string interpolation HOT 5
- Feature request: fastwarp for left parenthesis
- Suround vs Surround HOT 2
- Bug: `in_string()` errors in `ftplugin/lua.lua` HOT 4
- [Bug] Pairing in Select mode doesn't work when LSP server loads HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultimate-autopair.nvim.