Last active
May 29, 2021 00:05
-
-
Save chemzqm/e22ddf489ec24c7d21bbcb047f4b3f86 to your computer and use it in GitHub Desktop.
repl with coc.nvim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the file to ~/.vim/coc-extensions | |
// Usage: xmap <silent> <TAB> <Plug>(coc-repl-sendtext) | |
const {commands, workspace} = require('coc.nvim') | |
exports.activate = context => { | |
let {nvim} = workspace | |
let terminal | |
context.subscriptions.push(commands.registerCommand('repl.openTerminal', async () => { | |
let filetype = await nvim.eval('&filetype') | |
let prog = '' | |
if (filetype == 'javascript') { | |
prog = 'node' | |
} else if (filetype == 'typescript') { | |
prog = 'ts-node' | |
} else if (filetype == 'python') { | |
prog = 'python' | |
} | |
terminal = await workspace.createTerminal({ | |
name: prog || 'terminal' | |
}) | |
if (prog) { | |
terminal.sendText(prog, true) | |
} | |
})) | |
context.subscriptions.push(commands.registerCommand('repl.showTerminal', async () => { | |
if (terminal) { | |
terminal.show() | |
} | |
})) | |
context.subscriptions.push(commands.registerCommand('repl.disposeTerminal', async () => { | |
if (terminal) { | |
terminal.dispose() | |
} | |
})) | |
context.subscriptions.push(workspace.registerKeymap(['x'], 'repl-sendtext', async () => { | |
await nvim.call('eval', 'feedkeys("\\<esc>", "in")') | |
let doc = workspace.getDocument(workspace.bufnr) | |
if (!doc) return | |
let visualmode = await nvim.call('visualmode') | |
let range = await workspace.getSelectedRange(visualmode, doc) | |
if (!range) return | |
let text = doc.textDocument.getText(range) | |
if (text && terminal) terminal.sendText(text, true) | |
}, {sync: false, silent: true})) | |
} |
No idea, the log is not complete.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After issuing
:CocCommand repl.openTerminal
vim freezes, get control back when I hit Ctrl-c.
VIM - Vi IMproved version 8.2.1897
(ubuntu wsl2)
Linux DESKTOP-8D 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
I also get when attempt to edit the file.
Theses r only settting on my init.vim for `/.js'
Thank you,