Closed LennyLizowzskiy closed 4 months ago
TODO: In the final version --edition=2021
should be removed. It's here now only for tests
@xiaoshihou514 can you help, please?
@xiaoshihou514 can you help, please?
Sure, what's the problem?
@xiaoshihou514 can you help, please?
Sure, what's the problem?
As I previously mentioned, I don't know how to check if it's working. I attached my config to the first message
Hmm, unfourtunately I don't have a pc right now, here's what I would suggest :)
I checked and yes, linter is outputting stuff to stderr. Is there any way I can get this string in guard?
Unfourtunately the stderr is not passed to the parse function right now. @glepnir seems to be busy contributing to neovim core :( Maybe check clippy and see if there's a cmdline option for that?
Unfortunately, clippy-driver
's API is very minimal because it's meant to be used as cargo clippy
that checks all files in the project altogether (while clippy-driver
is able to check a single file; also, clippy
implementation in rust-analyzer
doesn't support checking unsaved buffers for that exact reason). There's no way I can manually forward the output to the stdout
I see, in that case it's not possible to leverage clippy-driver with guard. Feel free to make prs to guard.nvim itself though! Some of the vim.uv code was tricky but you may want to give it a try.
I'm not using Neovim anymore, so I won't be able to complete this PR.
I'm posting this formatter as plain text in case if I delete the PR branch (I'm not really sure if the changes I made will be saved otherwise in this case).
local lint = require('guard.lint')
local function trim(s)
return s:gsub('^%s*(.-)%s*$', '%1')
end
return {
cmd = 'clippy-driver',
args = { '-', '--error-format=json', '--edition=2021' },
stdin = true,
parse = lint.from_json({
get_diagnostics = function(result, bufnr)
if result == '' then
return {}
end
local res = '{' .. result:gsub('({[^\n]+})\n', '%1,\n') .. '}'
return vim.json.decode(res)
end,
attributes = {
lnum = 'spans.line_start',
end_lnum = 'spans.line_end',
code = function(json)
-- concat all 'spans.text[n].text'
local str = ''
for k, v in pairs(json.spans.text) do
str = str .. trim(v.text)
if k ~= #json.spans.text then -- add " | " if current iteration is not last
str = str .. ' | '
end
end
return str
end,
col = 'spans.column_start',
end_col = 'spans.column_end',
severity = 'level',
message = 'message',
},
severities = {
lint.severities.info,
lint.severities.warning,
lint.severities.error,
},
}),
}
Checklist (adding a new tool):
Need help with testing this
At first I forgot to change branches in my Neovim config, but now I fixed it and checked everything but there's no output from the plugin.
Example input:
Config: