How to repeat the action on the last list item? #3228
-
I'm using a list called coc-tasks: https://github.com/voldikss/coc-tasks. My workflow:
Ideally I'd like to do the last two steps in one if there is a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You can't, there's only repeat support for CocCommand |
Beta Was this translation helpful? Give feedback.
-
My suggestion is write some script to run your build on save, so no need to run the command yourself, my esbuild extension: // run esbuild on file change
const {spawn} = require('child_process')
const {workspace, Mutex, window} = require('coc.nvim')
const path = require('path')
const fs = require('fs')
const debounce = require('debounce')
const languageIds = ['javascript', 'typescript', 'javascriptreact', 'typescriptreact']
exports.activate = async context => {
let mutex = new Mutex()
let statusItem = window.createStatusBarItem(0, {progress: true})
context.subscriptions.push(statusItem)
async function runEsbuild(filepath) {
let release = await mutex.acquire()
let d = Date.now()
let cp = spawn('node', ['esbuild.js'], {cwd: path.dirname(filepath)})
statusItem.text = 'Running node esbuild.js'
statusItem.show()
cp.on('error', e => {
window.showErrorMessage(`Error: ${e.message}`)
statusItem.hide()
release()
})
cp.stderr.on('data', chunk => {
window.showErrorMessage(`Esbuild error: ${chunk.toString()}`)
})
cp.on('exit', (code) => {
statusItem.hide()
if (code == 0) {
window.showMessage(`Build finished ${Date.now() - d}ms`, 'more')
}
release()
})
}
let run = debounce(runEsbuild, 200)
workspace.onDidSaveTextDocument(doc => {
if (!languageIds.includes(doc.languageId)) return
let cwd = workspace.cwd
let filepath = path.join(cwd, 'esbuild.js')
if (fs.existsSync(filepath)) {
run(filepath)
}
}, null, context.subscriptions)
} |
Beta Was this translation helpful? Give feedback.
You can't, there's only repeat support for CocCommand
:h <plug>(coc-command-repeat)
, so it has to be registered as command.