aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-10-02 10:31:04 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-10-02 10:31:04 -0700
commit501319eed2ff26f856ea91b5456bef1d00f77df7 (patch)
tree4f4a2fa93a53d724916385be5b08eba895d6fe5d /lua/conform
parent5563df7966e244cdd0d8ec50a81cfeb2d8358d9f (diff)
fix: injected formatter operates on input lines
Diffstat (limited to 'lua/conform')
-rw-r--r--lua/conform/formatters/injected.lua9
1 files changed, 6 insertions, 3 deletions
diff --git a/lua/conform/formatters/injected.lua b/lua/conform/formatters/injected.lua
index bc4016c..5ba8e0a 100644
--- a/lua/conform/formatters/injected.lua
+++ b/lua/conform/formatters/injected.lua
@@ -55,17 +55,20 @@ return {
local conform = require("conform")
local log = require("conform.log")
local util = require("conform.util")
- local ok, parser = pcall(vim.treesitter.get_parser, ctx.buf)
+ local text = table.concat(lines, "\n")
+ local buf_lang = vim.treesitter.language.get_lang(vim.bo[ctx.buf].filetype)
+ local ok, parser = pcall(vim.treesitter.get_string_parser, text, buf_lang)
if not ok then
callback("No treesitter parser for buffer")
return
end
+ parser:parse()
local root_lang = parser:lang()
local regions = {}
- for lang, child_lang in pairs(parser:children()) do
+ for lang, child_tree in pairs(parser:children()) do
local formatter_names = conform.formatters_by_ft[lang]
if formatter_names and lang ~= root_lang then
- for _, tree in ipairs(child_lang:trees()) do
+ for _, tree in ipairs(child_tree:trees()) do
local root = tree:root()
local start_lnum = root:start() + 1
local end_lnum = root:end_()