diff options
Diffstat (limited to 'lua/conform')
-rw-r--r-- | lua/conform/formatters/injected.lua | 5 | ||||
-rw-r--r-- | lua/conform/fs.lua | 20 |
2 files changed, 4 insertions, 21 deletions
diff --git a/lua/conform/formatters/injected.lua b/lua/conform/formatters/injected.lua index 363889e..fd67439 100644 --- a/lua/conform/formatters/injected.lua +++ b/lua/conform/formatters/injected.lua @@ -127,7 +127,10 @@ return { local errors = require("conform.errors") local log = require("conform.log") local util = require("conform.util") - local text = table.concat(lines, "\n") + -- Need to add a trailing newline; some parsers need this. + -- For example, if a markdown code block ends at the end of the file, a trailing newline is + -- required otherwise the ``` will be grabbed as part of the injected block + local text = table.concat(lines, "\n") .. "\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 diff --git a/lua/conform/fs.lua b/lua/conform/fs.lua index c33a2dc..d303dbd 100644 --- a/lua/conform/fs.lua +++ b/lua/conform/fs.lua @@ -15,24 +15,4 @@ M.join = function(...) return table.concat({ ... }, M.sep) end ----@param filepath string ----@return boolean -M.exists = function(filepath) - local stat = uv.fs_stat(filepath) - return stat ~= nil and stat.type ~= nil -end - ----@param filepath string ----@return string? -M.read_file = function(filepath) - if not M.exists(filepath) then - return nil - end - local fd = assert(uv.fs_open(filepath, "r", 420)) -- 0644 - local stat = assert(uv.fs_fstat(fd)) - local content = uv.fs_read(fd, stat.size) - uv.fs_close(fd) - return content -end - return M |