-
This might be a little convoluted but I'll try to explain the whole picture so that if there is a better way to do it, the better. I work in C++ and for example in a source code like: int square(int num) {
return num * num;
}
int main()
{
return squaree(3);
} gcc would spit out this output:
What I wanted to do was to parse the whole error and I ended up with: local problem_matcher = require("overseer.template.vscode.problem_matcher")
local gcc_parser = problem_matcher.get_parser_from_problem_matcher(problem_matcher.resolve_problem_matcher("$gcc"))
gcc_parser[2].append = false
-- components section of the template
components = {
"defaults",
{
"on_output_parse",
parser = {
diagnostics = {
"sequence",
gcc_parser,
{ "extract_multiline", "%s+%d*%s*|(%s+.*)", "text" }
}
}
},
}, Now with this, trouble.nvim and a custom configuration for Neovim's diagnostics to show only the first line I have a comfortable setup where diagnostics are shown, I can navigate them with trouble and see the whole message form gcc within trouble. The first question here is about this: local problem_matcher = require("overseer.template.vscode.problem_matcher")
local gcc_parser = problem_matcher.get_parser_from_problem_matcher(problem_matcher.resolve_problem_matcher("$gcc"))
gcc_parser[2].append = false is this the correct way to do it? is there a better way? The second question is around post processing of the lines in the parser in order to add more information to the diagnostics: what I mean is that I wanted to parse the amount of I couldn't find a way to do it reading the documentation (or maybe I missed the needed piece) so I thought of writing a parser that would do this custom thing mimicking the implementation of https://github.com/stevearc/overseer.nvim/blob/master/lua/overseer/parser/extract.lua but one thing that I still don't understand is the role of the returned value of the Sorry for the long post 😭 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
For your first question: is there a better way to get the gcc parser? I would say yes. The way you're fetching and then mutating the problem matcher right now is quite brittle. It makes more sense to just copy the regular expression it's using and use that directly in your own parser. Here's where it's defined: overseer.nvim/lua/overseer/template/vscode/problem_matcher.lua Lines 264 to 274 in 16ac26a Using it directly would look like this: components = {
"defaults",
{
"on_output_parse",
parser = {
diagnostics = {
{
"extract",
{ append = false, regex = true },
"\\v^([^:]*):(\\d+):(\\d*):?\\s+%(fatal\\s+)?(warning|error):\\s+(.*)$",
"filename",
"lnum",
"col",
"type",
"text",
},
{ "extract_multiline", "%s+%d*%s*|(%s+.*)", "text" },
},
},
},
} For your second question: how can you count the components = {
"defaults",
{
"on_output_parse",
parser = {
diagnostics = {
{
"extract",
{ append = false, regex = true },
"\\v^([^:]*):(\\d+):(\\d*):?\\s+%(fatal\\s+)?(warning|error):\\s+(.*)$",
"filename",
"lnum",
"col",
"type",
"text",
},
{ "extract_multiline", { append = false }, "%s+%d*%s*|(%s+.*)", "text" },
{
"append",
{
postprocess = function(item)
local lines = vim.split(item.text, "\n", { plain = true, trimempty = true })
local last_line = lines[#lines]
-- Set the end_col to be the last character of the last line we parsed
item.end_col = string.len(last_line)
end,
},
},
},
},
},
} Also note that the One last point: if you haven't seen or used the parser debugger yet (documented here) I would highly recommend it. It makes writing and debugging parsers infinitely easier. |
Beta Was this translation helpful? Give feedback.
-
The first instinct was to do it like this so that I wouldn't have to copy the regex and in case that was updated I would get it updated for free but I admit that given the result it doesn't seems much of a win the way I did it.
Any info on this last question? |
Beta Was this translation helpful? Give feedback.
There's no documentation for writing your own nodes in the behavior tree parser. It's not a public API and I don't expect people to need to write their own nodes. Is there something you're still trying to accomplish that can't be done with the existing nodes?