Skip to content

Commit

Permalink
Support v:lua omnifunc.
Browse files Browse the repository at this point in the history
Fix #6
  • Loading branch information
hrsh7th committed Nov 16, 2022
1 parent cec8d46 commit 01f0f66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions autoload/cmp_omni.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function! cmp_omni#invoke(func, ...) abort
if a:func =~# '^v:lua\.'
return luaeval(printf('%s(_A[1], _A[2], _A[3])', matchstr(a:func, '^v:lua\.\zs.*')), a:000)
endif
return nvim_call_function(a:func, a:000)
endfunction

6 changes: 4 additions & 2 deletions lua/cmp_omni/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source.new = function()
end

source.is_available = function()
return vim.bo.omnifunc ~= ''
return vim.bo.omnifunc ~= '' and vim.api.nvim_get_mode().mode == 'i'
end

source.get_position_encoding_kind = function()
Expand Down Expand Up @@ -67,7 +67,7 @@ end
source._invoke = function(_, func, args)
local prev_pos = vim.api.nvim_win_get_cursor(0)
local _, result = pcall(function()
return vim.api.nvim_call_function(func, args)
return vim.fn['cmp_omni#invoke'](func, args)
end)
local next_pos = vim.api.nvim_win_get_cursor(0)
if prev_pos[1] ~= next_pos[1] or prev_pos[2] ~= next_pos[2] then
Expand All @@ -76,5 +76,7 @@ source._invoke = function(_, func, args)
return result
end



return source

5 comments on commit 01f0f66

@hiberabyss
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit not work. Test with dap-repl window.

@hrsh7th
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I can confirm the behavior with v:lua.vim.lsp.omnifunc.

@hiberabyss
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dap-repl omnifunc is:
v:lua.require'dap.repl'.omnifunc

@hrsh7th
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed .Could you re-test latest main?

@hiberabyss
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works now.

Please sign in to comment.