Skip to content

Commit 5f1dbb6

Browse files
authored
refactor: Replace async- and job abstractions (#356)
1 parent 8c17024 commit 5f1dbb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3660
-1880
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ for any git rev.
1818
- Git ≥ 2.31.0 (for Git support)
1919
- Mercurial (for Mercurial support)
2020
- Neovim ≥ 0.7.0
21-
- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim)
2221
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) (optional) For file icons
2322

2423
## Installation
@@ -27,13 +26,12 @@ Install the plugin with your package manager of choice.
2726

2827
```vim
2928
" Plug
30-
Plug 'nvim-lua/plenary.nvim'
31-
Plug 'sindrets/diffview.nvim'
29+
Plug "sindrets/diffview.nvim"
3230
```
3331

3432
```lua
3533
-- Packer
36-
use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' }
34+
use "sindrets/diffview.nvim"
3735
```
3836

3937
## Merge Tool

lua/diffview/actions.lua

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local async = require("diffview.async")
12
local lazy = require("diffview.lazy")
23

34
local DiffView = lazy.access("diffview.scene.views.diff.diff_view", "DiffView") ---@type DiffView|LazyModule
@@ -19,6 +20,8 @@ local Diff4 = lazy.access("diffview.scene.layouts.diff_4", "Diff4") ---@type Dif
1920
local Diff4Mixed = lazy.access("diffview.scene.layouts.diff_4_mixed", "Diff4Mixed") ---@type Diff4Mixed|LazyModule
2021

2122
local api = vim.api
23+
local await = async.await
24+
local pl = lazy.access(utils, "path") ---@type PathLib
2225

2326
local M = setmetatable({}, {
2427
__index = function(_, k)
@@ -46,11 +49,11 @@ local function prepare_goto_file()
4649
if file then
4750
---@cast file FileEntry
4851
-- Ensure file exists
49-
if not utils.path:readable(file.absolute_path) then
52+
if not pl:readable(file.absolute_path) then
5053
utils.err(
5154
string.format(
5255
"File does not exist on disk: '%s'",
53-
utils.path:relative(file.absolute_path, ".")
56+
pl:relative(file.absolute_path, ".")
5457
)
5558
)
5659
return
@@ -386,7 +389,7 @@ end
386389

387390
---@param target "ours"|"theirs"|"base"|"all"|"none"
388391
function M.conflict_choose_all(target)
389-
return function()
392+
return async.void(function()
390393
local view = lib.get_current_view() --[[@as DiffView ]]
391394

392395
if (view and view:instanceof(DiffView.__get())) then
@@ -396,21 +399,15 @@ function M.conflict_choose_all(target)
396399
local item = view:infer_cur_file(false) ---@cast item -DirData
397400
if not item then return end
398401

399-
if item.active then
400-
-- The entry is already open and the action can proceed like normal
401-
resolve_all_conflicts(view, target)
402-
else
403-
-- The entry is not open
404-
view.emitter:once("file_open_post", utils.bind(resolve_all_conflicts, view, target))
405-
402+
if not item.active then
406403
-- Open the entry
407-
view:set_file(item)
404+
await(view:set_file(item))
408405
end
409-
else
410-
resolve_all_conflicts(view, target)
411406
end
407+
408+
resolve_all_conflicts(view, target)
412409
end
413-
end
410+
end)
414411
end
415412

416413
---@param target "ours"|"theirs"|"base"|"all"|"none"

lua/diffview/api/views/diff/diff_view.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
local async = require("diffview.async")
12
local lazy = require("diffview.lazy")
23

34
local DiffView = lazy.access("diffview.scene.views.diff.diff_view", "DiffView") ---@type DiffView|LazyModule
45
local FileEntry = lazy.access("diffview.scene.file_entry", "FileEntry") ---@type FileEntry|LazyModule
56
local FilePanel = lazy.access("diffview.scene.views.diff.file_panel", "FilePanel") ---@type FilePanel|LazyModule
67
local Rev = lazy.access("diffview.vcs.adapters.git.rev", "GitRev") ---@type GitRev|LazyModule
78
local RevType = lazy.access("diffview.vcs.rev", "RevType") ---@type RevType|LazyModule
8-
local async = lazy.require("plenary.async") ---@module "plenary.async"
99
local vcs_utils = lazy.require("diffview.vcs") ---@module "diffview.vcs"
10-
local logger = lazy.require("diffview.logger") ---@module "diffview.logger"
1110
local oop = lazy.require("diffview.oop") ---@module "diffview.oop"
1211
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"
1312

13+
local logger = DiffviewGlobal.logger
14+
1415
local M = {}
1516

1617
---@class FileData
@@ -31,7 +32,7 @@ local CDiffView = oop.create_class("CDiffView", DiffView.__get())
3132
---CDiffView constructor.
3233
---@param opt any
3334
function CDiffView:init(opt)
34-
logger.info("[api] Creating a new Custom DiffView.")
35+
logger:info("[api] Creating a new Custom DiffView.")
3536
self.valid = false
3637

3738
local err, adapter = vcs_utils.get_adapter({ top_indicators = { opt.git_root } })
@@ -90,7 +91,6 @@ end
9091
---@override
9192
CDiffView.get_updated_files = async.wrap(function(self, callback)
9293
local err
93-
callback = async.void(callback)
9494

9595
repeat
9696
local ok, new_files = pcall(self.fetch_files, self)
@@ -113,9 +113,9 @@ CDiffView.get_updated_files = async.wrap(function(self, callback)
113113
until true
114114

115115
utils.err(err, true)
116-
logger.s_error(table.concat(err, "\n"))
116+
logger:error(table.concat(err, "\n"))
117117
callback(err, nil)
118-
end, 2)
118+
end)
119119

120120
function CDiffView:create_file_entries(files)
121121
local entries = {}

0 commit comments

Comments
 (0)