Comments (3)
Beware that, unlike some other scripting languages, Lua considers both zero and the empty string as true in conditional tests.
that's the reason why I compare it to one for I've seen a post that said the same thing. So, in case the function doesn't return the standard boolean, I compare it to one.
After investigating, I discovered that my issue was not caused by the visible()
function, but by has_word_before()
. Removing it resolved the problem.
Thanks for replying anyway.
from nvim-cmp.
like the image above shows, I already triggered tab compeletion. but it won't trigger snip jump for cmp.visiable() still be true.
How can I fix this problem?? below is my setup
opts.mapping = vim.tbl_extend("force", opts.mapping, { ["<Enter>"] = function(fallback) -- Don't block <CR> if signature help is active -- https://github.com/hrsh7th/cmp-nvim-lsp-signature-help/issues/13 if not cmp.visible() or not cmp.get_selected_entry() or cmp.get_selected_entry().source.name == 'nvim_lsp_signature_help' then fallback() else cmp.confirm({ -- Replace word if completing in the middle of a word -- https://github.com/hrsh7th/nvim-cmp/issues/664 behavior = cmp.ConfirmBehavior.Replace, -- Don't select first item on CR if nothing was selected select = false, }) end end, ["<Tab>"] = cmp.mapping(function(fallback) if cmp.visible() == 1 then cmp.select_next_item() -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() -- this way you will only jump inside the snippet region elseif luasnip.expand_or_jumpable() == 1 then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }), ["<S-Tab>"] = cmp.mapping(function(fallback) if cmp.visible() == 1 then cmp.select_prev_item() elseif luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { "i", "s" }), })
I don't know where the problem is, but one part of your code confused me, the cmp.visible() function returns true or false... no need to compare it to 1 :)
:h cmp.visible()
cmp.visible ()
Return a boolean showing whether the completion menu is visible or not.
For example, I use it like this and it works
['<Left>'] = {
---> Disable in Insert Mode. <---
i = cmp.config.disable,
---> Active in Command Mode. <---
c = function(fallback)
---> If List was Open. <---
if cmp.visible() then
---> Go to Prev Item. <---
cmp.select_prev_item();
else
---> Back to Default Key. <---
fallback();
end
end
},
In Lua language, zero and one are evaluated as true.
www.lua.org:
Beware that, unlike some other scripting languages, Lua considers both zero and the empty string as true in conditional tests.
from nvim-cmp.
Beware that, unlike some other scripting languages, Lua considers both zero and the empty string as true in conditional tests.
that's the reason why I compare it to one for I've seen a post that said the same thing. So, in case the function doesn't return the standard boolean, I compare it to one. After investigating, I discovered that my issue was not caused by the
visible()
function, but byhas_word_before()
. Removing it resolved the problem. Thanks for replying anyway.
Glad your problem is solved...I don't understand...what other option than true or false can it return?
I think that such functions are usually written in such a way that in all cases, even if part of the code in other parts is incomplete, they return a Boolean answer(false)... and only if everything goes well, the answer will be true...
from nvim-cmp.
Related Issues (20)
- error when using completion with gopls language server in neovim 0.10.0
- how to config vsnip with native nvim-jdtls
- How to disable background transport HOT 5
- matcher issue HOT 1
- Markdown stylization of completion documentation throws error (pylsp)
- No actions can be done to the autocomplete window when opened HOT 4
- disallow_prefix_unmatching not working consistently with jdtls language server HOT 5
- Completion tips are returned in a different order from the `lsp` service.
- Custom Entries Error after 'get-selected' api HOT 8
- Navigation through code completion does not work anymore HOT 10
- cmp.select_next_item() gets error "attempt to perform arithmetic on local 'cursor' HOT 5
- When attempting to navigate suggestion list getting E5108 Error executing lua: .../custom_entries_view.lua:328: attempt to perform arithmetic on local 'cursor' (a nil value) HOT 3
- GLFW_PROFILE doesn't match GLFW_OPENGL_PROFILE but it does when we write GLFW_OP first HOT 1
- Update "Advanced techniques" in the Wiki HOT 1
- Improperly sized windows HOT 1
- Diagnostics window always opens from behind HOT 3
- Feature Request: complete on close HOT 3
- [Question] How would I fetch the current word that nvim cmp is completing against externally?
- preselection not working in command mode HOT 3
- Key mapping to select first snippet completion
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 nvim-cmp.