jose-elias-alvarez / null-ls.nvim

Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
Other
3.62k stars 792 forks source link

diagnostics source for asyncapi #1429

Open mhanberg opened 1 year ago

mhanberg commented 1 year ago

Issues

Feature description

Diagnostics source for the asyncapi CLI.

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.

          {
            name = "asyncapi",
            method = require("null-ls.methods").internal.DIAGNOSTICS,
            filetypes = { "yaml" },
            generator = null_ls.generator {
              command = "asyncapi",
              args = { "validate", "$FILENAME", "--diagnostics-format", "json" },
              format = "json_raw",
              to_stdin = false,
              ignore_stderr = true,
              to_temp_file = true,
              on_output = function(params)
                local h = require("null-ls.helpers")
                local severities = {
                  h.diagnostics.severities.error,
                  h.diagnostics.severities.warning,
                  h.diagnostics.severities.info,
                }
                params.messages = {}
                local output = vim.split(params.output, "\n", { trimempty = true })
                local json = vim.fn.join { unpack(output, 2) }
                for _, message in ipairs(vim.json.decode(json)) do
                  table.insert(params.messages, {
                    row = message.range.start.line + 1,
                    col = message.range.start.character + 1,
                    end_row = message.range["end"].line + 1,
                    end_col = message.range["end"].character + 1,
                    message = message.message,
                    severity = severities[message.severity],
                    filename = params.bufname,
                  })
                end
                return params.messages
              end,
            },
          },
mhanberg commented 1 year ago

This should have a runtime_condition config to check to see if it is actually an asyncapi document.

jose-elias-alvarez commented 1 year ago

Thanks for this, feel free to put in a PR whenever. The cfn_lint built-in may provide an example of how to check documents.

mhanberg commented 1 year ago

@jose-elias-alvarez i was hesitant to switch to null-ls from efm for a while (not sure why), but I totally regret it as I switched over to make this integration and the experience was incredible, as well as I found several other linters that i didn't know about and are amazing.

Thanks for null-ls!