Last active
July 20, 2025 15:42
-
-
Save baruch/9f8d7a8c3dfe6f3a0f38fc964a677a7d to your computer and use it in GitHub Desktop.
Use D-Scanner as a diagnostics LSP in Neovim LazyVim with none-ls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Put the following in your ~/.config/nvim/init.lua (after the config.lazy init) | |
| -- Setup dscanner as an nvim-lint command | |
| -- use pattern, get severity and better code handling | |
| local dscanner_pattern = "{filepath}:{line}:{column}:{endColumn}:{type}:{name}:{message}" | |
| local pattern = "([^:]+):(%d+):(%d+):(%d+):([^:]+):([^:]+):(.*)" | |
| local groups = { "file", "lnum", "col", "endcol", "severity", "code", "message" } | |
| local severity_map = { | |
| warn = vim.diagnostic.severity.WARN, | |
| error = vim.diagnostic.severity.ERROR, | |
| } | |
| local parser = require("lint.parser").from_pattern(pattern, groups, severity_map, { | |
| source = "dscanner", | |
| }) | |
| require("lint").linters.dscanner = { | |
| name = "dscanner", | |
| cmd = "~/bin/dscanner", | |
| stdin = false, -- or false if it doesn't support content input via stdin. In that case the filename is automatically added to the arguments. | |
| append_fname = true, -- Automatically append the file name to `args` if `stdin = false` (default: true) | |
| args = { "lint", "--errorFormat=" .. dscanner_pattern }, -- list of arguments. Can contain functions with zero arguments that will be evaluated once the linter is used. | |
| stream = "stdout", -- ('stdout' | 'stderr' | 'both') configure the stream to which the linter outputs the linting result. | |
| ignore_exitcode = true, -- set this to true if the linter exits with a code != 0 and that's considered normal. | |
| env = nil, -- custom environment table to use with the list_extendl process. Note that this replaces the *entire* environment, it is not additive. | |
| parser = parser, | |
| } | |
| require("lint").linters_by_ft = { | |
| d = { "dscanner" }, | |
| } | |
| vim.api.nvim_create_autocmd({ "BufWritePost" }, { | |
| callback = function() | |
| -- try_lint without arguments runs the linters defined in `linters_by_ft` | |
| -- for the current filetype | |
| require("lint").try_lint() | |
| -- You can call `try_lint` with a linter name or a list of names to always | |
| -- run specific linters, independent of the `linters_by_ft` configuration | |
| --require("lint").try_lint("cspell") | |
| end, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment