Skip to content

Commit 695423e

Browse files
troigantotroiganto
and
troiganto
authored
refactor: replace deprecated vim.loop with vim.uv (#888)
Co-authored-by: troiganto <troiganto@proton.me>
1 parent 535701d commit 695423e

File tree

12 files changed

+40
-40
lines changed

12 files changed

+40
-40
lines changed

lua/orgmode/capture/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function Capture:refile_file_headline_to_archive(headline)
291291
if vim.fn.isdirectory(archive_directory) == 0 then
292292
vim.fn.mkdir(archive_directory, 'p')
293293
end
294-
if not vim.loop.fs_stat(archive_location) then
294+
if not vim.uv.fs_stat(archive_location) then
295295
vim.fn.writefile({}, archive_location)
296296
end
297297

lua/orgmode/files/file.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end)
4040
---@param opts OrgFileOpts
4141
---@return OrgFile
4242
function OrgFile:new(opts)
43-
local stat = vim.loop.fs_stat(opts.filename)
43+
local stat = vim.uv.fs_stat(opts.filename)
4444
local data = {
4545
filename = opts.filename,
4646
lines = opts.lines,
@@ -72,7 +72,7 @@ function OrgFile.load(filename)
7272
}))
7373
end
7474

75-
if not vim.loop.fs_stat(filename) or not utils.is_org_file(filename) then
75+
if not vim.uv.fs_stat(filename) or not utils.is_org_file(filename) then
7676
return Promise.resolve(false)
7777
end
7878

@@ -146,7 +146,7 @@ function OrgFile:is_modified()
146146
local cur_changedtick = vim.api.nvim_buf_get_changedtick(bufnr)
147147
return cur_changedtick ~= self.metadata.changedtick
148148
end
149-
local stat = vim.loop.fs_stat(self.filename)
149+
local stat = vim.uv.fs_stat(self.filename)
150150
if not stat then
151151
return false
152152
end
@@ -865,7 +865,7 @@ function OrgFile:_update_lines(lines, bufnr)
865865
if bufnr then
866866
self.metadata.changedtick = vim.api.nvim_buf_get_changedtick(bufnr)
867867
end
868-
local stat = vim.loop.fs_stat(self.filename)
868+
local stat = vim.uv.fs_stat(self.filename)
869869
if stat then
870870
self.metadata.mtime = stat.mtime.nsec
871871
end

lua/orgmode/files/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function OrgFiles:_files(skip_resolve)
376376
return false
377377
end
378378

379-
local stat = vim.loop.fs_stat(file)
379+
local stat = vim.uv.fs_stat(file)
380380
return stat and stat.type == 'file' or false
381381
end, all_files)
382382
end

lua/orgmode/notifications/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323

2424
function Notifications:start_timer()
2525
self:stop_timer()
26-
self.timer = vim.loop.new_timer()
26+
self.timer = vim.uv.new_timer()
2727
self:notify(Date.now())
2828
self.timer:start(
2929
(60 - os.date('%S')) * 1000,

lua/orgmode/utils/fs.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function M.get_real_path(filepath)
2929
if not substituted then
3030
return false
3131
end
32-
local real = vim.loop.fs_realpath(substituted)
32+
local real = vim.uv.fs_realpath(substituted)
3333
if real and filepath:sub(-1, -1) == '/' then
3434
-- make sure if filepath gets a trailing slash, the realpath gets one, too.
3535
real = real .. '/'

lua/orgmode/utils/init.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local Promise = require('orgmode.utils.promise')
2-
local uv = vim.loop
2+
local uv = vim.uv
33
local utils = {}
44
local debounce_timers = {}
55
local tmp_window_augroup = vim.api.nvim_create_augroup('OrgTmpWindow', { clear = true })
@@ -86,11 +86,11 @@ end
8686

8787
function utils.system_notification(message)
8888
if vim.fn.executable('notify-send') == 1 then
89-
vim.loop.spawn('notify-send', { args = { message } })
89+
uv.spawn('notify-send', { args = { message } })
9090
end
9191

9292
if vim.fn.executable('terminal-notifier') == 1 then
93-
vim.loop.spawn('terminal-notifier', { args = { '-message', message } })
93+
uv.spawn('terminal-notifier', { args = { '-message', message } })
9494
end
9595
end
9696

@@ -332,9 +332,9 @@ end
332332
---@param name string
333333
---@return function
334334
function utils.profile(name)
335-
local start_time = vim.loop.hrtime()
335+
local start_time = uv.hrtime()
336336
return function()
337-
return print(name, string.format('%.2f', (vim.loop.hrtime() - start_time) / 1000000))
337+
return print(name, string.format('%.2f', (uv.hrtime() - start_time) / 1000000))
338338
end
339339
end
340340

lua/orgmode/utils/treesitter/install.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Promise = require('orgmode.utils.promise')
22
local utils = require('orgmode.utils')
33
local ts_revision = 'f8c6b1e72f82f17e41004e04e15f62a83ecc27b0'
4-
local uv = vim.loop
4+
local uv = vim.uv
55
local M = {
66
compilers = { vim.fn.getenv('CC'), 'cc', 'gcc', 'clang', 'cl', 'zig' },
77
}

scripts/minimal_init.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ local nvim_root = tmp_dir .. '/nvim_orgmode'
33
local lazy_root = nvim_root .. '/lazy'
44
local lazypath = lazy_root .. '/lazy.nvim'
55

6-
for _, name in ipairs({ "config", "data", "state", "cache" }) do
7-
vim.env[("XDG_%s_HOME"):format(name:upper())] = nvim_root .. "/" .. name
6+
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
7+
vim.env[('XDG_%s_HOME'):format(name:upper())] = nvim_root .. '/' .. name
88
end
99

1010
-- Install lazy.nvim if not already installed
11-
if not vim.loop.fs_stat(lazypath) then
11+
if not vim.uv.fs_stat(lazypath) then
1212
vim.fn.system({
1313
'git',
1414
'clone',

tests/minimal_init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ function M.load_plugin(plugin_name, plugin_url)
2323
local install_destination = package_root .. plugin_name
2424
vim.opt.runtimepath:append(install_destination)
2525

26-
if not vim.loop.fs_stat(package_root) then
26+
if not vim.uv.fs_stat(package_root) then
2727
vim.fn.mkdir(package_root, 'p')
2828
end
2929

3030
-- If the plugin install path already exists, we don't need to clone it again.
31-
if not vim.loop.fs_stat(install_destination) then
31+
if not vim.uv.fs_stat(install_destination) then
3232
print(string.format('>> Downloading plugin "%s" to "%s"', plugin_name, install_destination))
3333
vim.fn.system({
3434
'git',

tests/plenary/babel/tangle_spec.lua

+17-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Tangle', function()
1212
})
1313
vim.cmd('norm ,obt')
1414
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
15-
assert.is.Nil(vim.loop.fs_stat(tangled_file))
15+
assert.is.Nil(vim.uv.fs_stat(tangled_file))
1616
end)
1717

1818
it('should tangle a file when enabled in config', function()
@@ -30,7 +30,7 @@ describe('Tangle', function()
3030
})
3131
vim.cmd('norm ,obt')
3232
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
33-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
33+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
3434
assert.are.same({
3535
'print("test first line")',
3636
'print("test first second line")',
@@ -54,7 +54,7 @@ describe('Tangle', function()
5454
})
5555
vim.cmd('norm ,obt')
5656
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
57-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
57+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
5858
assert.are.same({
5959
'print("test first line")',
6060
'print("test first second line")',
@@ -74,7 +74,7 @@ describe('Tangle', function()
7474
})
7575
vim.cmd('norm ,obt')
7676
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
77-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
77+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
7878
assert.are.same({
7979
'print("test first line")',
8080
'print("test first second line")',
@@ -91,7 +91,7 @@ describe('Tangle', function()
9191
})
9292
vim.cmd('norm ,obt')
9393
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
94-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
94+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
9595
assert.are.same({
9696
'print("test first line")',
9797
'print("test first second line")',
@@ -109,7 +109,7 @@ describe('Tangle', function()
109109
})
110110
vim.cmd('norm ,obt')
111111
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
112-
assert.is.Nil(vim.loop.fs_stat(tangled_file))
112+
assert.is.Nil(vim.uv.fs_stat(tangled_file))
113113
end)
114114
end)
115115

@@ -131,7 +131,7 @@ describe('Tangle', function()
131131
vim.cmd('norm ,obt')
132132

133133
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
134-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
134+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
135135
assert.are.same({
136136
'print("Headline first line")',
137137
'print("Headline second line")',
@@ -158,7 +158,7 @@ describe('Tangle', function()
158158
vim.cmd('norm ,obt')
159159

160160
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
161-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
161+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
162162
assert.are.same({
163163
'print("Other headline first line")',
164164
'print("Other headline second line")',
@@ -184,7 +184,7 @@ describe('Tangle', function()
184184
})
185185
vim.cmd('norm ,obt')
186186

187-
assert.is.Not.Nil(vim.loop.fs_stat(abs_path))
187+
assert.is.Not.Nil(vim.uv.fs_stat(abs_path))
188188
assert.are.same({
189189
'print("Headline first line")',
190190
'print("Headline second line")',
@@ -212,7 +212,7 @@ describe('Tangle', function()
212212
})
213213
vim.cmd('norm ,obt')
214214

215-
assert.is.Not.Nil(vim.loop.fs_stat(abs_path))
215+
assert.is.Not.Nil(vim.uv.fs_stat(abs_path))
216216
assert.are.same({
217217
'print("Headline first line")',
218218
'print("Headline second line")',
@@ -240,7 +240,7 @@ describe('Tangle', function()
240240
})
241241
vim.cmd('norm ,obt')
242242

243-
assert.is.Not.Nil(vim.loop.fs_stat(abs_path))
243+
assert.is.Not.Nil(vim.uv.fs_stat(abs_path))
244244
assert.are.same({
245245
'print("Headline first line")',
246246
'print("Headline second line")',
@@ -269,8 +269,8 @@ describe('Tangle', function()
269269
})
270270
vim.cmd('norm ,obt')
271271

272-
assert.is.Not.Nil(vim.loop.fs_stat(abs_path))
273-
assert.is.Not.Nil(vim.loop.fs_stat(single_block_abs_path))
272+
assert.is.Not.Nil(vim.uv.fs_stat(abs_path))
273+
assert.is.Not.Nil(vim.uv.fs_stat(single_block_abs_path))
274274
assert.are.same({
275275
'print("Headline first line")',
276276
'print("Headline second line")',
@@ -302,7 +302,7 @@ describe('Tangle', function()
302302
vim.cmd('norm ,obt')
303303

304304
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
305-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
305+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
306306
assert.are.same({
307307
'print("Other headline first line")',
308308
'print("Other headline second line")',
@@ -333,7 +333,7 @@ describe('Tangle', function()
333333
vim.cmd('norm ,obt')
334334

335335
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
336-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
336+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
337337
assert.are.same({
338338
'print("Other headline first line")',
339339
'print("Other headline second line")',
@@ -361,7 +361,7 @@ describe('Tangle', function()
361361
vim.cmd('norm ,obt')
362362

363363
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
364-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
364+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
365365
assert.are.same({
366366
'<<otherblock>>',
367367
'print("Headline first line")',
@@ -391,7 +391,7 @@ describe('Tangle', function()
391391
vim.cmd('norm ,obt')
392392

393393
local tangled_file = vim.fn.fnamemodify(file.filename, ':r') .. '.lua'
394-
assert.is.Not.Nil(vim.loop.fs_stat(tangled_file))
394+
assert.is.Not.Nil(vim.uv.fs_stat(tangled_file))
395395
assert.are.same({
396396
'print("Other headline first line")',
397397
'print("Other headline second line")',

tests/plenary/files/file_spec.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('OrgFile', function()
1818
assert.are.same(filename, file.filename)
1919
assert.are.same({ '* Headline 1' }, file.lines)
2020
assert.are.same('* Headline 1', file.content)
21-
local stat = vim.loop.fs_stat(filename) or {}
21+
local stat = vim.uv.fs_stat(filename) or {}
2222
assert.are.same(stat.mtime.nsec, file.metadata.mtime)
2323
assert.are.same(0, file.metadata.changedtick)
2424
end)
@@ -37,7 +37,7 @@ describe('OrgFile', function()
3737
assert.are.same(filename, file.filename)
3838
assert.are.same({ '* Headline 2' }, file.lines)
3939
assert.are.same('* Headline 2', file.content)
40-
local stat = vim.loop.fs_stat(filename) or {}
40+
local stat = vim.uv.fs_stat(filename) or {}
4141
assert.are.same(stat.mtime.nsec, file.metadata.mtime)
4242
assert.are.same(0, file.metadata.changedtick)
4343
vim.cmd('write!')

tests/plenary/state/state_spec.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('State', function()
1414
end)
1515

1616
it("should create a state file if it doesn't exist", function()
17-
local stat = vim.loop.fs_stat(cache_path)
17+
local stat = vim.uv.fs_stat(cache_path)
1818
if stat then
1919
error('Cache file existed before it should! Ensure it is deleted before each test run!')
2020
end
@@ -27,7 +27,7 @@ describe('State', function()
2727
return state._ctx.saved
2828
end, 10)
2929

30-
local stat, err, _ = vim.loop.fs_stat(cache_path)
30+
local stat, err, _ = vim.uv.fs_stat(cache_path)
3131
if not stat then
3232
error(err)
3333
end

0 commit comments

Comments
 (0)