Skip to content

Get text from diagnostic for vimscript #3711

Answered by chemzqm
otavioschwanck asked this question in Q&A
Discussion options

You must be logged in to vote
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(

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@chemzqm
Comment options

Comment options

You must be logged in to vote
7 replies
@chemzqm
Comment options

@otavioschwanck
Comment options

@otavioschwanck
Comment options

@chemzqm
Comment options

@otavioschwanck
Comment options

Answer selected by chemzqm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants