diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-12-26 06:38:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-26 06:38:00 -0800 |
commit | f245cca8ad42c9d344b53a18c3fc1a3c6724c2d4 (patch) | |
tree | 71cf24c9888024ce02706e3d1e544187729dcf09 /lua/conform/fs.lua | |
parent | 7396fc0208539e2bd70e3e446f27529e28dba12b (diff) |
fix(injected): handle inline injections (#251)
Diffstat (limited to 'lua/conform/fs.lua')
-rw-r--r-- | lua/conform/fs.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lua/conform/fs.lua b/lua/conform/fs.lua index d303dbd..c33a2dc 100644 --- a/lua/conform/fs.lua +++ b/lua/conform/fs.lua @@ -15,4 +15,24 @@ 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 |