Add this to your Neovim config.
lua << EOF
if pcall(require, "nvim-treesitter.parsers") then
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.printf = {
install_info = {
url = "https://github.com/pstuifzand/tree-sitter-printf",
files = { "src/parser.c" },
},
filetype = "printf",
}
end
EOF
Example of how to inject the printf grammar into the Go grammar.
(call_expression
function:
(selector_expression field: (field_identifier) @_method)
(#match? @_method "^Sprintf|Printf|Fprintf|Fatalf$")
arguments: (argument_list . (interpreted_string_literal) @printf)
)
Highlight the formats. This will highlight the format with one color.
(format) @printf
Peter Stuifzand