Skip to content

Commit

Permalink
[vim] use new uv.fs_stat to check if file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
antonk52 committed May 25, 2024
1 parent 76e4955 commit 372a56e
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nvim/ftplugin/dirvish.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local function add()
-- no need to escape for fn.mkdir or fn.writefile
local new_path = vim.fn.input('Enter the new node path: ', vim.fn.expand('%'), 'file')

if vim.fn.filereadable(new_path) == 1 or vim.fn.isdirectory(new_path) == 1 then
if vim.uv.fs_stat(new_path) or vim.fn.isdirectory(new_path) == 1 then
vim.notify('Already exists', vim.log.levels.WARN)
else
if vim.endswith(new_path, '/') then
Expand Down
2 changes: 1 addition & 1 deletion nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ if vim.env.WORK_PLUGIN_PATH ~= nil then
name = vim.env.WORK_PLUGIN_PATH,
config = function()
local local_init_lua = vim.fs.normalize('~/.config/local_init.lua')
if vim.fn.filereadable(local_init_lua) == 1 and not vim.g.vscode then
if vim.uv.fs_stat(local_init_lua) and not vim.g.vscode then
vim.cmd.luafile(local_init_lua)
else
vim.notify('No ~/.config/local_init.lua', vim.log.levels.ERROR)
Expand Down
4 changes: 2 additions & 2 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"nvim-lspconfig": { "branch": "master", "commit": "b972e7154bc94ab4ecdbb38c8edbccac36f83996" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
"nvim-spectre": { "branch": "master", "commit": "5690ea46baf08bbc1623980012e14b6239ce582e" },
"nvim-treesitter": { "branch": "master", "commit": "6d56c5f404d3b116bab167bc03993cfb0a83f8aa" },
"nvim-treesitter": { "branch": "master", "commit": "78e11ab7cedabe5dfb3b600c6682712271c59acf" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "3557e41418b4a6c5b85d5d64abe94c9c50fa9b14" },
"plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
"schemastore.nvim": { "branch": "main", "commit": "9a5992a881583d886bfbb46631a09f736f0fae50" },
"telescope.nvim": { "branch": "master", "commit": "5665d93988acfbb0747bdbf4f4cb583bcebc8930" },
"telescope.nvim": { "branch": "master", "commit": "c2ce039188e22288449e43b77710036e69a45a70" },
"ts-comments.nvim": { "branch": "main", "commit": "dd4424521aa097d012290126eb08f8b6bf52146a" },
"twoslash-queries.nvim": { "branch": "main", "commit": "e000134c7ca3ea44f1095df3ceea89e485b7bdd5" },
"vim-dirvish": { "branch": "master", "commit": "3851bedb7f191b9a4a5531000b6fc0a8795cc9bb" }
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/antonk52/git_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local function run_cmd_and_exit(cmd)
return function()
local buf_name = vim.api.nvim_buf_get_name(0)
if string.find(cmd, '%%') then
if vim.fn.filereadable(buf_name) == 0 then
if not vim.uv.fs_stat(buf_name) then
return vim.notify('Buffer is not a file', vim.log.levels.ERROR)
end
cmd = string.gsub(cmd, '%%', buf_name)
Expand Down
4 changes: 2 additions & 2 deletions nvim/lua/antonk52/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ M.servers = {
main = vim.fn.expand(local_prefix .. 'main.lua'),
}

local BIN = (vim.fn.filereadable(GLOBAL_BIN.bin) == 1) and GLOBAL_BIN or LOCAL_BIN
local BIN = vim.uv.fs_stat(GLOBAL_BIN.bin) and GLOBAL_BIN or LOCAL_BIN

if vim.fn.filereadable(BIN.bin) ~= 1 then
if not vim.uv.fs_stat(BIN.bin) then
vim.notify('lua-language-server is not installed or cannot be found', vim.log.levels.WARN)
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/antonk52/notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local NOTES_PATH = vim.fn.expand(vim.env.NOTES_PATH)
function M.source_rus_keymap()
local filename = 'keymap/russian-jcukenmac.vim'
local rus_keymap = vim.trim(vim.fn.globpath(vim.o.rtp, filename))
if vim.fn.filereadable(rus_keymap) then
if vim.uv.fs_stat(rus_keymap) then
vim.cmd.source(rus_keymap)
else
print('Cannot locate Russian keymap file named "' .. filename .. '" in runtime path')
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/antonk52/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
local function get_nongit_ignore_patterns()
local gitignore_path = vim.fs.joinpath(vim.uv.cwd(), '.gitignore')
-- we are not in a git repository, but we have .gitignore(mercurial)
if vim.fn.filereadable(gitignore_path) == 1 then
if vim.uv.fs_stat(gitignore_path) then
local ignore_lines = vim.fn.readfile(gitignore_path)

return vim.tbl_filter(function(line)
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/antonk52/test_js.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ local function run_jest(bufnr, bin, cwd, env)
vim.schedule(function()
local finish = vim.uv.now() - start
vim.notify('Jest took ' .. finish .. 'ms', vim.log.levels.INFO)
if vim.fn.filereadable(tmp_file) == 0 then
if not vim.uv.fs_stat(tmp_file) then
vim.notify('Output file is not readable\n' .. tmp_file, vim.log.levels.ERROR)
return
end
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/antonk52/tsc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function lookdownTSConfigDir()
for _, current_dir in ipairs(dirs_from_cwd_to_buf) do
for _, file in ipairs(TSC_ROOT_FILES) do
local filepath = vim.fs.join(current_dir, file)
if vim.fn.filereadable(filepath) == 1 then
if vim.uv.fs_stat(filepath) then
return current_dir
end
end
Expand Down

0 comments on commit 372a56e

Please sign in to comment.