@@ -23,65 +23,44 @@ function M.now()
23
23
return vim .loop .hrtime () / 1000000
24
24
end
25
25
26
- --- Echo string with multiple lines.
27
26
--- @param msg string | string[]
28
- --- @param hl ? string Highlight group name.
29
27
--- @param schedule ? boolean Schedule the echo call.
30
- function M .echo_multiln (msg , hl , schedule )
28
+ --- @param level integer
29
+ function M .notify (msg , level , schedule )
31
30
if schedule then
32
- vim .schedule (function () M .echo_multiln (msg , hl , false ) end )
31
+ vim .schedule (function () M .notify (msg , level , false ) end )
32
+ return
33
+ end
34
+ if type (msg ) == " table" then
35
+ msg = table.concat (msg , " \n " )
36
+ end
37
+ if msg == " " then
33
38
return
34
39
end
35
40
36
- if type (msg ) ~= " table" then msg = { msg } end
41
+ if level == vim .log .levels .ERROR then
42
+ logger :error (msg )
43
+ end
37
44
38
- local text = table.concat (msg , " \n " )
39
- api .nvim_echo ({ { text , hl } }, true , {})
45
+ vim .notify (msg , level , { title = " diffview.nvim" })
40
46
end
41
47
42
48
--- @param msg string | string[]
43
49
--- @param schedule ? boolean Schedule the echo call.
44
50
function M .info (msg , schedule )
45
- if type (msg ) ~= " table" then
46
- msg = { msg }
47
- end
48
- if not msg [1 ] or (msg [1 ] == " " and # msg == 1 ) then
49
- return
50
- end
51
- msg = M .vec_slice (msg )
52
- msg [1 ] = " [Diffview.nvim] " .. msg [1 ]
53
- M .echo_multiln (msg , " DiagnosticInfo" , schedule )
51
+ M .notify (msg , vim .log .levels .INFO , schedule )
54
52
end
55
53
56
54
--- @param msg string | string[]
57
55
--- @param schedule ? boolean Schedule the echo call.
58
56
function M .warn (msg , schedule )
59
- if type (msg ) ~= " table" then
60
- msg = { msg }
61
- end
62
- if not msg [1 ] or (msg [1 ] == " " and # msg == 1 ) then
63
- return
64
- end
65
- msg = M .vec_slice (msg )
66
- msg [1 ] = " [Diffview.nvim] " .. msg [1 ]
67
- M .echo_multiln (msg , " WarningMsg" , schedule )
57
+ M .notify (msg , vim .log .levels .WARN , schedule )
68
58
end
69
59
70
60
--- @param msg string | string[]
71
61
--- @param schedule ? boolean Schedule the echo call.
72
62
function M .err (msg , schedule )
73
- if type (msg ) ~= " table" then
74
- msg = { msg }
75
- end
76
- if not msg [1 ] or (msg [1 ] == " " and # msg == 1 ) then
77
- return
78
- end
79
- msg = M .vec_slice (msg )
80
-
81
- logger :error (table.concat (msg , " \n " ))
82
-
83
- msg [1 ] = " [Diffview.nvim] " .. msg [1 ]
84
- M .echo_multiln (msg , " ErrorMsg" , schedule )
63
+ M .notify (msg , vim .log .levels .ERROR , schedule )
85
64
end
86
65
87
66
--- Call the function `f`, ignoring most of the window and buffer related
0 commit comments