null-ls.nvim icon indicating copy to clipboard operation
null-ls.nvim copied to clipboard

redocly diagnostics

Open mhanberg opened this issue 1 year ago • 1 comments

Issues

  • [X] I have checked existing issues and there are no existing ones with the same request.

Feature description

Diagnostics source using the redocly CLI for validating OpenAPI documents.

Help

Yes

Implementation help

I have an implementation of this in my personal dotfiles, so I will drop that here in case someone else wants to use it as a base for patching it into null-ls.

If not, I plan on carving out some time to add this patch.

This borrows portions of the codeclimate output handler from a different diagnostics source in null-ls.

          {
            name = "redocly",
            method = require("null-ls.methods").internal.DIAGNOSTICS,
            filetypes = { "raml" },
            generator = null_ls.generator {
              command = "redocly",
              args = { "lint", "$FILENAME", "--format", "codeclimate" },
              format = "json",
              to_stdin = false,
              ignore_stderr = true,
              to_temp_file = true,
              on_output = function(params)
                local h = require("null-ls.helpers")
                local severities = {
                  blocker = h.diagnostics.severities.error,
                  critical = h.diagnostics.severities.error,
                  major = h.diagnostics.severities.error,
                  minor = h.diagnostics.severities.warning,
                  info = h.diagnostics.severities.information,
                }
                params.messages = {}
                for _, message in ipairs(params.output) do
                  local col = nil
                  local row = message.location.lines.begin
                  if type(row) == "table" then
                    row = row.line
                    col = row.column
                  end
                  table.insert(params.messages, {
                    row = row,
                    col = col,
                    message = message.description,
                    severity = severities[message.severity],
                    filename = params.bufname,
                  })
                end
                return params.messages
              end,
            },
          },

mhanberg avatar Mar 02 '23 20:03 mhanberg