I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
hrsh7th / cmp-omni Goto Github PK
View Code? Open in Web Editor NEWnvim-cmp source for omnifunc
License: MIT License
nvim-cmp source for omnifunc
License: MIT License
I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
One thing many legacy omnicomplete functions do is return a position for the start of the completion as well as an array of possible items. I've taken a few stabs at wiring up a legacy omni complete function to cmp without much luck. I got pretty close by setting keyword_patterm = [[.*]]
and stuffing everything that the complete function can touch into vim's iskeyword
setting, but it's still clunky.
According to this comment the textEdit
property might offer a solution, but I have no idea where to start.
It seems to me like this plugin should offer a way to shim the two so that omni complete functions can be a dropin source even if they return results that don't start at the beginning of the current keyword (which seems to be cmp's assumption).
When I use the builtin python omnifunc, the first letter of the selection is not inserted:
When I go in a .tex file, I want omni completion so I can use vimtex omni suggestions to my advantage. When I type \a for example, the suggestions are correct and I get this:
However with some letters, some completion is missing. For example if I type \b I get:
Which is missing a LOT of omni completions. For example \beta, or \backslash. If I type <c-x><c-o>
with \b I get:
And I dont get any of that with nvim-cmp
I have noticed the same problem with \s, \e, and a lot of other letters. For example \p does include all the options from the omni completion, but this varies from time to time.
This is my init.vim:
call plug#begin()
Plug 'lervag/vimtex'
Plug 'hrsh7th/nvim-cmp'
Plug 'SirVer/ultisnips'
"nvim-cmp sources
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-omni'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
call plug#end()
lua <<EOF
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = {
['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
},
sources = cmp.config.sources({
{ name = 'ultisnips' },
{ name = 'omni' },
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
EOF ```
First, I'm not sure if this is best suited for this module or the ultisnips module I am using.
Expected Behavior
When a snippet expands into some text that would normally trigger the completion window to open, the completion window should open.
Example
I am mainly working with tex documents. I have a snippet which automatically triggers when I type cite
which expands to ~\cite{|}
with the cursor marked with the pipe character. Without the snippet, if I type ~\cite{
the completion window appears with citation entries populated by the associated bibtex file (note: I am using the configuration from here).
This is how it has worked for me in the past when I used, e.g., deoplete.
Sorry about my bad description. More about this issue, please have a look at the screen recording. When I type a character, then a completion is selected immediately, and also there are two popup.
Minimal init.lua
to Reproduce this issue:
require("packer").startup({
{
"wbthomason/packer.nvim",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-omni",
"neovim/nvim-lspconfig",
},
})
local cmp = require("cmp")
local cmp_lsp = require("cmp_nvim_lsp")
local lspconfig = require("lspconfig")
lspconfig.sumneko_lua.setup {
cmd = { "lua-language-server" },
settings = {
Lua = {
telemetry = { enable = false },
},
},
capabilities = cmp_lsp.default_capabilities(),
}
cmp.setup {
sources = cmp.config.sources({
{ name = "nvim_lsp" },
}, {
{ name = "omni" },
})
}
The omnifunc can provide a number of items for displaying in the completion-menu, as seen here: https://neovim.io/doc/user/insert.html#complete-items
Adding these entries shouldnt be too hard, see lervag/vimtex#2215 (comment), but it doesn't really look good. I suggest adding a new key to the items
table, e.g. called menu
.
This could be passed in the nvim-cmp/lua/cmp/source.lua
file somewhere here: https://github.com/hrsh7th/nvim-cmp/blob/092fb66b6ddb4b12b9b542d105d7af40e4fbd9f2/lua/cmp/source.lua#L309.
I am willing to help if you think this is a good idea @hrsh7th.
I have opened the PR for supporting the Kind info like LSP. Please review and let me know if anything missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.