以 webpack 为例:
const {commands, workspace, Disposable} = require('coc.nvim')
const path = require('path')
const patternWebpack = /ERROR\sin\s(?<filename>\S+)\s(?<line>\d+):(?<col>\d+)/
const errorPattern = /ERROR\sin\s(?<filename>[^(]+)\((?<line>\d+),(?<col>\d+)\)/
exports.activate = context => {
let {nvim} = workspace
let statusItem = workspace.createStatusBarItem(1, {progress: true})
let task = workspace.createTask('WEBPACK')
let cwd
async function check() {
let running = await task.running
if (running) {
statusItem.isProgress = false
statusItem.text = '?'
statusItem.show()
} else {
statusItem.hide()
}
}
check().catch(_e => {
// noop
})
task.onExit(code => {
if (code != 0) {
workspace.showMessage(`Webpack exit with code ${code}`, 'warning')
}
statusItem.hide()
})
task.onStdout(lines => {
let i = 0
let items = []
for (let line of lines) {
if (line.indexOf('ERROR') !== -1) {
let res = patternWebpack.exec(line)
if (res == null) {
res = errorPattern.exec(line)
}
if (res != null) {
let {filename} = res.groups
if (!path.isAbsolute(filename)) {
filename = path.join(cwd, filename)
}
items.push({
filename,
lnum: parseInt(res.groups.line),
col: parseInt(res.groups.col),
text: lines[i + 1].trim(),
type: 'E'
})
}
}
i++
}
nvim.call('setqflist', [items], true)
statusItem.text = items.length == 0 ? '✓' : '✗'
statusItem.isProgress = false
})
task.onStderr(lines => {
for (let line of lines) {
if (line.match(/webpack\sis\swatching/)) {
statusItem.text = 'watching'
}
}
})
context.subscriptions.push(Disposable.create(() => {
task.dispose()
}))
context.subscriptions.push(commands.registerCommand('webpack.watch', async () => {
cwd = workspace.cwd
task.start({
cmd: 'webpack',
args: ['--watch', '--no-color'],
cwd: workspace.cwd
})
statusItem.show()
}))
}
将文件保存为 $VIMCONFIG/coc-extensions/webpack.js
,设置自定义 Webpack 命令 ( vim 中执行 :echo $VIMCONFIG
查看 $VIMCONFIG )
command! -nargs=0 Webpack :call CocAction('runCommand', 'webpack.watch')
webpack --watch
, 而不是保存完重现构建,效率高一些tsserver.watchBuild
命令执行 tsc --watch
构建 1
weixiangzhe 2019-06-25 12:13:34 +08:00
支持下楼主,coc 解决好多问题,
|
2
yuuko 2019-06-25 12:16:35 +08:00
滋瓷,是不是可以搞成一个通用的列出 package.json 的 script command
|
4
lancelock 2019-06-25 16:42:44 +08:00
vim 可以打断点 debug 吗? gdb 之类的用不来
|
5
ivechan 2019-06-25 18:13:11 +08:00
|
6
Taigacute 2019-06-27 12:40:38 +08:00
👍
|