nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.03k stars 134 forks source link

omni completion source does not work with coc-omni #64

Closed ihasdapie closed 3 years ago

ihasdapie commented 3 years ago

Describe the bug

I haven't found the time to migrate over the nvim's built in lsp & nvim-compe and so I'm trying to use coc-omni with orgmode.nvim. However it doesn't work. Is the problem with this plugin or on coc-omni's side?

Steps to reproduce

  1. Have orgmode.nvim & coc.nvim w/ coc-omni installed
  2. Try to trigger completion from within an org file

Expected behavior

Omni func is callable & works?

Emacs functionality

No response

Screenshots and recordings

image

OS / Distro

Manjaro

Neovim version/commit

0.5

Additional context

No response

kristijanhusak commented 3 years ago

Does omni without the coc work fine for you? If yes, it's most likely issue with coc.

ihasdapie commented 3 years ago

Omni works fine without coc, so maybe the problem is on coc's end. Still I find it odd that there's an unknown function error.

kristijanhusak commented 3 years ago

I pushed a small change. Can you give it a test?

ihasdapie commented 3 years ago
function! org#complete(findstart, base) abort
  let l:cmd = printf("orgmode.omni(%s, '%s')", a:findstart, a:base)
  return luaeval(l:cmd)
endfunction

setlocal omnifunc=org#complete

^ This workaround works perfectly with coc-omni.

Looking into coc-omni the it seems to be an upstream problem with coc.nvim's workspace not picking up on v:lua variables. I think I'll also open up an issue on the coc.nvim repo to see if this is the case.

// coc-sources/packages/omni/index.js
    doComplete: async function (opt) {
      let {nvim} = workspace
      let func = await nvim.eval('&omnifunc') // here
      if (!func) return null
      let {line, colnr, col} = opt
      let startcol = col
      try {
        startcol = await nvim.call(func, [1, ''])

The above wrapper function would enable orgmode.nvim to work with coc.nvim out of the box, which is important to people like me who use coc.nvim for it's maturity & relative feature richness.

However I understand that wrapping it in a viml function would go against the "write vim plugins in lua and keep it that way" philosophy, and that the above solution is really just a janky patch

kristijanhusak commented 3 years ago

I did something similar in last commit https://github.com/kristijanhusak/orgmode.nvim/commit/9b412b3a8356d15423f953f90d56c38b8917f290, isn't it working for you?

ihasdapie commented 3 years ago

Oh I didn't see that, let me try

ihasdapie commented 3 years ago

Yup, works great. Thanks!