Skip to content

Commit 3cfc243

Browse files
authored
style: remove unneeded vim local, prefer vim.uv (#1724)
1 parent d8d6c48 commit 3cfc243

32 files changed

+45
-64
lines changed

lua/neo-tree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local vim = vim
21
local M = {}
32

43
--- To be removed in a future release, use this instead:

lua/neo-tree/command/parser.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local uv = vim.uv or vim.loop
12
local utils = require("neo-tree.utils")
23
local _compat = require("neo-tree.utils._compat")
34

@@ -88,8 +89,8 @@ M.resolve_path = function(path, validate_type)
8889
local expanded = vim.fn.expand(path)
8990
local abs_path = vim.fn.fnamemodify(expanded, ":p")
9091
if validate_type then
91-
local stat = vim.loop.fs_stat(abs_path)
92-
if stat and stat.type ~= validate_type then
92+
local stat = uv.fs_stat(abs_path)
93+
if not stat or stat.type ~= validate_type then
9394
error("Invalid path: " .. path .. " is not a " .. validate_type)
9495
end
9596
end
@@ -141,7 +142,7 @@ local parse_arg = function(result, arg)
141142
end
142143
-- maybe it's a path
143144
local path = M.resolve_path(value)
144-
local stat = vim.loop.fs_stat(path)
145+
local stat = uv.fs_stat(path)
145146
if stat then
146147
if stat.type == "directory" then
147148
result["dir"] = path

lua/neo-tree/events/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local vim = vim
21
local q = require("neo-tree.events.queue")
32
local log = require("neo-tree.log")
43
local utils = require("neo-tree.utils")

lua/neo-tree/git/ignored.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local Job = require("plenary.job")
2+
local uv = vim.uv or vim.loop
23

34
local utils = require("neo-tree.utils")
45
local log = require("neo-tree.log")
@@ -67,7 +68,7 @@ M.mark_ignored = function(state, items, callback)
6768
--add the trailing slash to the path manually if not on Windows.
6869
log.trace("IGNORED: Checking types of", #result, "items to see which ones are directories")
6970
for i, item in ipairs(result) do
70-
local stat = vim.loop.fs_stat(item)
71+
local stat = uv.fs_stat(item)
7172
if stat and stat.type == "directory" then
7273
result[i] = item .. sep
7374
end

lua/neo-tree/log.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
-- This library is free software; you can redistribute it and/or modify it
77
-- under the terms of the MIT license. See LICENSE for details.
88

9-
local vim = vim
109
-- User configuration section
1110
local default_config = {
1211
-- Name of the plugin. Prepended to log messages

lua/neo-tree/setup/netrw.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local uv = vim.uv or vim.loop
12
local nt = require("neo-tree")
23
local utils = require("neo-tree.utils")
34
local M = {}
@@ -36,7 +37,7 @@ M.hijack = function(path)
3637
if not utils.truthy(bufname) then
3738
bufname = path or ""
3839
end
39-
local stats = vim.loop.fs_stat(bufname)
40+
local stats = uv.fs_stat(bufname)
4041
if not stats then
4142
return false
4243
end

lua/neo-tree/sources/buffers/commands.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--This file should contain all commands meant to be used by mappings.
22

3-
local vim = vim
43
local cc = require("neo-tree.sources.common.commands")
54
local buffers = require("neo-tree.sources.buffers")
65
local utils = require("neo-tree.utils")

lua/neo-tree/sources/buffers/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--This file should have all functions that are in the public api and either set
22
--or read the state of this source.
33

4-
local vim = vim
54
local utils = require("neo-tree.utils")
65
local renderer = require("neo-tree.ui.renderer")
76
local items = require("neo-tree.sources.buffers.lib.items")

lua/neo-tree/sources/buffers/lib/items.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local vim = vim
21
local renderer = require("neo-tree.ui.renderer")
32
local utils = require("neo-tree.utils")
43
local file_items = require("neo-tree.sources.common.file-items")

lua/neo-tree/sources/common/commands.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
--This file should contain all commands meant to be used by mappings.
2-
local vim = vim
32
local fs_actions = require("neo-tree.sources.filesystem.lib.fs_actions")
43
local utils = require("neo-tree.utils")
54
local renderer = require("neo-tree.ui.renderer")

lua/neo-tree/sources/common/file-items.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
local vim = vim
21
local file_nesting = require("neo-tree.sources.common.file-nesting")
32
local utils = require("neo-tree.utils")
43
local log = require("neo-tree.log")
4+
local uv = vim.uv or vim.loop
55

66
local function sort_items(a, b)
77
if a.type == b.type then
@@ -109,7 +109,7 @@ function create_item(context, path, _type, bufnr)
109109
end
110110

111111
if _type == nil then
112-
local stat = vim.loop.fs_stat(path)
112+
local stat = uv.fs_stat(path)
113113
_type = stat and stat.type or "unknown"
114114
end
115115
local item = {
@@ -126,9 +126,9 @@ function create_item(context, path, _type, bufnr)
126126
end
127127
if item.type == "link" then
128128
item.is_link = true
129-
item.link_to = vim.loop.fs_realpath(path)
129+
item.link_to = uv.fs_realpath(path)
130130
if item.link_to ~= nil then
131-
item.type = vim.loop.fs_stat(item.link_to).type
131+
item.type = uv.fs_stat(item.link_to).type
132132
end
133133
end
134134
if item.type == "directory" then

lua/neo-tree/sources/common/filters/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---A generalization of the filter functionality to directly filter the
22
---source tree instead of relying on pre-filtered data, which is specific
33
---to the filesystem source.
4-
local vim = vim
54
local Input = require("nui.input")
65
local event = require("nui.utils.autocmd").event
76
local popups = require("neo-tree.ui.popups")

lua/neo-tree/sources/common/preview.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local vim = vim
21
local utils = require("neo-tree.utils")
32
local highlights = require("neo-tree.ui.highlights")
43
local events = require("neo-tree.events")

lua/neo-tree/sources/document_symbols/commands.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ local manager = require("neo-tree.sources.manager")
55
local inputs = require("neo-tree.ui.inputs")
66
local filters = require("neo-tree.sources.common.filters")
77

8-
local vim = vim
9-
108
local M = {}
119
local SOURCE_NAME = "document_symbols"
1210
M.refresh = utils.wrap(manager.refresh, SOURCE_NAME)

lua/neo-tree/sources/document_symbols/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--This file should have all functions that are in the public api and either set
22
--or read the state of this source.
33

4-
local vim = vim
54
local manager = require("neo-tree.sources.manager")
65
local events = require("neo-tree.events")
76
local utils = require("neo-tree.utils")

lua/neo-tree/sources/filesystem/commands.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local utils = require("neo-tree.utils")
66
local filter = require("neo-tree.sources.filesystem.lib.filter")
77
local renderer = require("neo-tree.ui.renderer")
88
local log = require("neo-tree.log")
9+
local uv = vim.uv or vim.loop
910

1011
local M = {}
1112
local refresh = function(state)
@@ -141,7 +142,7 @@ local focus_next_git_modified = function(state, reverse)
141142
end
142143

143144
local is_file = function(path)
144-
local success, stats = pcall(vim.loop.fs_stat, path)
145+
local success, stats = pcall(uv.fs_stat, path)
145146
return (success and stats and stats.type ~= "directory")
146147
end
147148

lua/neo-tree/sources/filesystem/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
--This file should have all functions that are in the public api and either set
22
--or read the state of this source.
33

4-
local vim = vim
54
local utils = require("neo-tree.utils")
65
local _compat = require("neo-tree.utils._compat")
76
local fs_scan = require("neo-tree.sources.filesystem.lib.fs_scan")

lua/neo-tree/sources/filesystem/lib/filter.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- This file holds all code for the search function.
22

3-
local vim = vim
43
local Input = require("nui.input")
54
local event = require("nui.utils.autocmd").event
65
local fs = require("neo-tree.sources.filesystem")

lua/neo-tree/sources/filesystem/lib/filter_external.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local vim = vim
21
local log = require("neo-tree.log")
32
local Job = require("plenary.job")
43
local utils = require("neo-tree.utils")

lua/neo-tree/sources/filesystem/lib/fs_actions.lua

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
-- https://github.com/mhartington/dotfiles
55
-- and modified to fit neo-tree's api.
66
-- Permalink: https://github.com/mhartington/dotfiles/blob/7560986378753e0c047d940452cb03a3b6439b11/config/nvim/lua/mh/filetree/init.lua
7-
local vim = vim
87
local api = vim.api
9-
local loop = vim.uv or vim.loop
8+
local uv = vim.uv or vim.loop
109
local scan = require("plenary.scandir")
1110
local utils = require("neo-tree.utils")
1211
local inputs = require("neo-tree.ui.inputs")
@@ -22,8 +21,8 @@ local M = {}
2221
---@param original_path string
2322
---@param destination string
2423
---@return boolean rename_is_safe
25-
local function rename_is_safe(original_path, destination)
26-
if not loop.fs_stat(destination) then
24+
local function can_safely_rename(original_path, destination)
25+
if not uv.fs_stat(destination) then
2726
return true
2827
end
2928

@@ -144,12 +143,12 @@ end
144143

145144
local function create_all_parents(path)
146145
local function create_all_as_folders(in_path)
147-
if not loop.fs_stat(in_path) then
146+
if not uv.fs_stat(in_path) then
148147
local parent, _ = utils.split_path(in_path)
149148
if parent then
150149
create_all_as_folders(parent)
151150
end
152-
loop.fs_mkdir(in_path, 493)
151+
uv.fs_mkdir(in_path, 493)
153152
end
154153
end
155154

@@ -213,7 +212,7 @@ M.move_node = function(source, destination, callback, using_root_directory)
213212
end
214213
local function move_file()
215214
create_all_parents(dest)
216-
loop.fs_rename(source, dest, function(err)
215+
uv.fs_rename(source, dest, function(err)
217216
if err then
218217
log.error("Could not move the files from", source, "to", dest, ":", err)
219218
return
@@ -362,13 +361,13 @@ M.create_directory = function(in_directory, callback, using_root_directory)
362361
return
363362
end
364363

365-
if loop.fs_stat(destination) then
364+
if uv.fs_stat(destination) then
366365
log.warn("Directory already exists")
367366
return
368367
end
369368

370369
create_all_parents(destination)
371-
loop.fs_mkdir(destination, 493)
370+
uv.fs_mkdir(destination, 493)
372371

373372
vim.schedule(function()
374373
events.fire_event(events.FILE_ADDED, destination)
@@ -420,7 +419,7 @@ M.create_node = function(in_directory, callback, using_root_directory)
420419
end
421420

422421
destination = utils.normalize_path(destination)
423-
if loop.fs_stat(destination) then
422+
if uv.fs_stat(destination) then
424423
log.warn("File already exists")
425424
return
426425
end
@@ -439,19 +438,19 @@ M.create_node = function(in_directory, callback, using_root_directory)
439438

440439
create_all_parents(destination)
441440
if is_dir then
442-
loop.fs_mkdir(destination, 493)
441+
uv.fs_mkdir(destination, 493)
443442
else
444-
local open_mode = loop.constants.O_CREAT + loop.constants.O_WRONLY + loop.constants.O_TRUNC
445-
local fd = loop.fs_open(destination, open_mode, 420)
443+
local open_mode = uv.constants.O_CREAT + uv.constants.O_WRONLY + uv.constants.O_TRUNC
444+
local fd = uv.fs_open(destination, open_mode, 420)
446445
if not fd then
447-
if not loop.fs_stat(destination) then
446+
if not uv.fs_stat(destination) then
448447
api.nvim_err_writeln("Could not create file " .. destination)
449448
return
450449
else
451450
log.warn("Failed to complete file creation of " .. destination)
452451
end
453452
else
454-
loop.fs_close(fd)
453+
uv.fs_close(fd)
455454
end
456455
end
457456
complete()
@@ -463,7 +462,7 @@ end
463462
---@param dir_path string Directory to delete.
464463
---@return boolean success Whether the directory was deleted.
465464
local function delete_dir(dir_path)
466-
local handle = loop.fs_scandir(dir_path)
465+
local handle = uv.fs_scandir(dir_path)
467466
if type(handle) == "string" then
468467
api.nvim_err_writeln(handle)
469468
return false
@@ -475,7 +474,7 @@ local function delete_dir(dir_path)
475474
end
476475

477476
while true do
478-
local child_name, t = loop.fs_scandir_next(handle)
477+
local child_name, t = uv.fs_scandir_next(handle)
479478
if not child_name then
480479
break
481480
end
@@ -488,14 +487,14 @@ local function delete_dir(dir_path)
488487
return false
489488
end
490489
else
491-
local success = loop.fs_unlink(child_path)
490+
local success = uv.fs_unlink(child_path)
492491
if not success then
493492
return false
494493
end
495494
clear_buffer(child_path)
496495
end
497496
end
498-
return loop.fs_rmdir(dir_path) or false
497+
return uv.fs_rmdir(dir_path) or false
499498
end
500499

501500
-- Delete Node
@@ -505,19 +504,20 @@ M.delete_node = function(path, callback, noconfirm)
505504

506505
log.trace("Deleting node: ", path)
507506
local _type = "unknown"
508-
local stat = loop.fs_stat(path)
507+
local stat = uv.fs_stat(path)
509508
if stat then
510509
_type = stat.type
511510
if _type == "link" then
512-
local link_to = loop.fs_readlink(path)
511+
local link_to = uv.fs_readlink(path)
513512
if not link_to then
514513
log.error("Could not read link")
515514
return
516515
end
517-
local target_file = loop.fs_stat(link_to)
516+
local target_file = uv.fs_stat(link_to)
518517
if target_file then
519518
_type = target_file.type
520519
end
520+
_type = uv.fs_stat(link_to).type
521521
end
522522
if _type == "directory" then
523523
local children = scan.scan_dir(path, {
@@ -586,7 +586,7 @@ M.delete_node = function(path, callback, noconfirm)
586586
end
587587
end
588588
else
589-
local success = loop.fs_unlink(path)
589+
local success = uv.fs_unlink(path)
590590
if not success then
591591
return api.nvim_err_writeln("Could not remove file: " .. path)
592592
end
@@ -653,7 +653,7 @@ local rename_node = function(msg, name, get_destination, path, callback)
653653
end)
654654

655655
local function fs_rename()
656-
loop.fs_rename(path, destination, function(err)
656+
uv.fs_rename(path, destination, function(err)
657657
if err then
658658
log.warn("Could not rename the files")
659659
return

0 commit comments

Comments
 (0)