Run coc.nvim on Bun, and failed #4767
Replies: 3 comments
-
It's expected. An internal method of the Line 151 in 06d5dfd |
Beta Was this translation helpful? Give feedback.
-
Some further findings forgot to share: The full error message shown after running above is: It looks like the problem lies within the neovim's node-client. So I used this program to check (borrowed from neovim node-client): const cp = require('child_process')
const attach = require('neovim').attach // replaced neovim with @chemzqm/neovim to cross check
const nvim_proc = cp.spawn('nvim', ['-u', 'NONE', '-N', '--embed'], {})
// Attach to neovim process
;(async function () {
const nvim = await attach({ proc: nvim_proc })
nvim.command('vsp')
nvim.command('vsp')
nvim.command('vsp')
const windows = await nvim.windows
// expect(windows.length).toEqual(4);
// expect(windows[0] instanceof nvim.Window).toEqual(true);
// expect(windows[1] instanceof nvim.Window).toEqual(true);
nvim.window = windows[2]
const win = await nvim.window
// expect(win).not.toEqual(windows[0]);
// expect(win).toEqual(windows[2]);
const buf = await nvim.buffer
// expect(buf instanceof nvim.Buffer).toEqual(true);
const lines = await buf.lines
// expect(lines).toEqual(['']);
await buf.replace(['line1', 'line2'], 0)
const newLines = await buf.lines
// expect(newLines).toEqual(['line1', 'line2']);
nvim.quit()
// nvim_proc.disconnect()
})() So as shown above, I ran the script with Lastly I replaced all reference of Albeit the error, Although I don't think it's actually working as none of the commands works. e.g. |
Beta Was this translation helpful? Give feedback.
-
Hey, any updates on this? |
Beta Was this translation helpful? Give feedback.
-
Hi,
Since bun has caught quite a bit of attention, I figured why not try running coc.nvim using Bun? And here is the journey and spoilers: I failed
I started with
bun esbuild.js
. It obviously worked because it just uses esbuild. However, since bun's build API is borrowed from esbuild, so making abunbuild.js
is simple enough and it also worked.So that was a good start. Next let's run the bundled js directly with
bun build/index.js
, and there is our first error:The code is inside factory.ts and reading through it, this is the extension loading mechanism. It uses Node's internal
Module._compile
API, in the newest version, it lives under lib/internal/modules/cjs/loader.js. Although depending on an internal API is not very good, but it seems others does the same: jsonpath.OK, I was about to give up: Bun says it's compatible with Node, with lots of asterisks. Understandably this is not public API since it's prefixed with
_
. But just as I was moving away from it and refresh the page. The issue got closed by a PR that adds the_compile
method: oven-sh/bun#5840! Feeling rather lucky, I ranbun upgrade --canary
, and continued...So reading the
factory.ts
, it seems that thegetProtoWithCompile
is only used to extract the_compile
method fromModule
so that it can be monkey patched in thecreateSandbox
function. I don't fully get why this approach was taken. But it seems to rely on howrequire
and_compile
works internally in Nodejs's Module implementation. I don't know if this will work in Bun as Bun uses a native implementation in Zig, and it's not attached to theprototype
Although this shouldn't stop us as we're not loading any extension yet. Let's just get this part happy, we won't hit it yet. To work around it, I just modify the top levelModuleProto
with:Re-run
bun build/index.js
now gives some text:Since coc.nvim uses stdin and stdout to communicate with neovim, this is good news, it looks like the msgPack messages. I eagerly fired up nvim with minimal config:
Importantly
let g:coc_node_args = []
is needed because bun doesn't have--no-warnings
which is the default option added to the start up args. Then error:At this point, I don't have any clue what is going on. So I figured I'll park this for now and share it just in case someone else find this interesting and want to continue
Beta Was this translation helpful? Give feedback.
All reactions