Get text from diagnostic for vimscript #3711
Answered
by
chemzqm
otavioschwanck
asked this question in
Q&A
Replies: 2 comments 8 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
const {diagnosticManager, workspace, Position, commands, TextEdit} = require('coc.nvim')
exports.activate = async context => {
let {nvim} = workspace
context.subscriptions.push(commands.registerCommand('rubocop.comment', async () => {
let [pos, line, bufnr] = await nvim.eval('[coc#util#cursor(),getline("."),bufnr("%")]')
let diagnostics = await diagnosticManager.getCurrentDiagnostics()
if (diagnostics.some(d => d.message.includes('Inconsistent indentation'))) {
// add comment
let doc = workspace.getDocument(bufnr)
let edit = TextEdit.insert(Position.create(pos.line, line.length), '# rubocop:disable Layout/IndentationConsistency')
await doc.applyEdits([edit])
}
}))
} Save the javascript to a js file in your |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
chemzqm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
at first, thanks for your attention.
I want to build a feature that get the text on the diagnostic, parse and insert at the end.
Example:
I want to pick the [Layout/IndentationConsistency] from the tooltip and insert at the end of the line with some text. At final:
I have no clue of how to do this on vimscript. Im a ex emacs user and have this on my configuration.
Thanks for your attetion!
Beta Was this translation helpful? Give feedback.
All reactions