forked from sindrets/diffview.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffview.lua
57 lines (43 loc) · 1.5 KB
/
diffview.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
if vim.g.diffview_nvim_loaded or not require("diffview.bootstrap") then
return
end
vim.g.diffview_nvim_loaded = 1
local lazy = require("diffview.lazy")
---@module "diffview"
local arg_parser = lazy.require("diffview.arg_parser") ---@module "diffview.arg_parser"
local diffview = lazy.require("diffview") ---@module "diffview"
local api = vim.api
local command = api.nvim_create_user_command
-- NOTE: Need this wrapper around the completion function becuase it doesn't
-- exist yet.
local function completion(...)
return diffview.completion(...)
end
-- Create commands
command("DiffviewOpen", function(ctx)
diffview.open(arg_parser.scan(ctx.args).args)
end, { nargs = "*", complete = completion })
command("DiffviewFileHistory", function(ctx)
local range
if ctx.range > 0 then
range = { ctx.line1, ctx.line2 }
end
diffview.file_history(range, arg_parser.scan(ctx.args).args)
end, { nargs = "*", complete = completion, range = true })
command("DiffviewClose", function()
diffview.close()
end, { nargs = 0, bang = true })
command("DiffviewFocusFiles", function()
diffview.emit("focus_files")
end, { nargs = 0, bang = true })
command("DiffviewToggleFiles", function()
diffview.emit("toggle_files")
end, { nargs = 0, bang = true })
command("DiffviewRefresh", function()
diffview.emit("refresh_files")
end, { nargs = 0, bang = true })
command("DiffviewLog", function()
vim.cmd(("sp %s | norm! G"):format(
vim.fn.fnameescape(require("diffview.logger").outfile)
))
end, { nargs = 0, bang = true })