-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: explain the diagnostic parsers
- Loading branch information
Showing
2 changed files
with
56 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local h = require("null-ls.helpers") | ||
|
||
local custom_user_data = { | ||
user_data = function(entries, _) | ||
if not entries then | ||
return | ||
end | ||
|
||
local suggestions = {} | ||
for suggestion in string.gmatch(entries["_suggestions"], "[^, ]+") do | ||
table.insert(suggestions, suggestion) | ||
end | ||
|
||
return { | ||
suggestions = suggestions, | ||
misspelled = entries["_quote"], | ||
} | ||
end, | ||
} | ||
|
||
-- Finds the messages including a suggestions array, which comes from passing | ||
-- the --show-suggestions flag to cspell. | ||
-- That flag is only available when the user has registered the code action. | ||
local matcher_with_suggestions = { | ||
pattern = ".*:(%d+):(%d+)%s*-%s*(.*%((.*)%))%s*Suggestions:%s*%[(.*)%]", | ||
groups = { "row", "col", "message", "_quote", "_suggestions" }, | ||
overrides = { | ||
adapters = { | ||
h.diagnostics.adapters.end_col.from_quote, | ||
custom_user_data, | ||
}, | ||
}, | ||
} | ||
|
||
-- Finds the messages without a suggestions array. | ||
-- This will be the format used when only the cspell.nvim diagnostics are | ||
-- registered. So there's no need to pass the user_data table, since it's only | ||
-- used by the code actions. | ||
local matcher_without_suggestions = { | ||
pattern = [[.*:(%d+):(%d+)%s*-%s*(.*%((.*)%))]], | ||
groups = { "row", "col", "message", "_quote" }, | ||
overrides = { | ||
adapters = { | ||
h.diagnostics.adapters.end_col.from_quote, | ||
}, | ||
}, | ||
} | ||
|
||
-- To see the difference between the two matchers, see: | ||
-- https://github.com/davidmh/cspell.nvim/issues/32#issuecomment-1815780887 | ||
return h.diagnostics.from_patterns({ | ||
matcher_with_suggestions, | ||
matcher_without_suggestions, | ||
}) |