@@ -5,68 +5,104 @@ local opts
5
5
OPTION_DEFAULTS = {
6
6
create_keymaps = true ,
7
7
filetypes = {
8
- [" lua" ] = { " print('" , " ')" },
9
- [" vim" ] = { ' echo "' , ' "' },
8
+ [" lua" ] = {
9
+ left = " print('" ,
10
+ right = " ')" ,
11
+ mid_var = " ' .. vim.inspect(" ,
12
+ right_var = " ))" ,
13
+ },
14
+ [" vim" ] = {
15
+ left = ' echo "' ,
16
+ right = ' "' ,
17
+ mid_var = ' " .. ' ,
18
+ right_var = " " ,
19
+ },
10
20
},
11
21
}
12
22
13
23
local counter = 0
14
24
15
- local debuginfo = function ()
25
+ local debuginfo = function (variable_name )
16
26
local current_line = vim .api .nvim_win_get_cursor (0 )[1 ]
17
27
counter = counter + 1
18
28
19
- return " DEBUG: "
29
+ local line = " DEBUG: "
20
30
.. vim .fn .expand (" %:t" )
21
31
.. " :"
22
32
.. current_line
23
33
.. " ["
24
34
.. counter
25
35
.. " ]"
36
+
37
+ if variable_name ~= nil then
38
+ line = line .. " : " .. variable_name .. " ="
39
+ end
40
+
41
+ return line
26
42
end
27
43
28
44
local get_fix = function (filetype )
29
45
if vim .tbl_contains (vim .tbl_keys (opts .filetypes ), filetype ) then
30
- return opts .filetypes [filetype ][ 1 ], opts . filetypes [ filetype ][ 2 ]
46
+ return opts .filetypes [filetype ]
31
47
else
32
48
vim .notify (
33
49
" Don't have debugprint configuration for filetype " .. filetype ,
34
50
vim .log .levels .WARN
35
51
)
36
- return nil , nil
52
+ return nil
37
53
end
38
54
end
39
55
40
- M .debugprint = function (above )
56
+ M .debugprint = function (o )
57
+ local funcopts = vim .tbl_deep_extend (
58
+ " force" ,
59
+ { above = false , variable = false },
60
+ o or {}
61
+ )
62
+
63
+ vim .validate ({
64
+ above = { funcopts .above , " boolean" },
65
+ })
66
+
41
67
local current_line = vim .api .nvim_win_get_cursor (0 )[1 ]
42
68
local filetype = vim .api .nvim_get_option_value (" filetype" , {})
43
69
local indent = string.rep (" " , vim .fn .indent (current_line ))
44
- local prefix , postfix = get_fix (filetype )
70
+ local fixes = get_fix (filetype )
45
71
46
- if prefix == nil or postfix == nil then
72
+ if fixes == nil then
47
73
return
74
+ end
75
+
76
+ local line_to_insert
77
+ local line_to_insert_on
78
+
79
+ if funcopts .variable then
80
+ local variable_name = vim .fn .input (" Variable name: " )
81
+
82
+ line_to_insert = indent
83
+ .. fixes .left
84
+ .. debuginfo (variable_name )
85
+ .. fixes .mid_var
86
+ .. variable_name
87
+ .. fixes .right_var
48
88
else
49
- local line_to_insert = indent .. prefix .. debuginfo () .. postfix
50
-
51
- local line_to_insert_on
52
-
53
- if above then
54
- line_to_insert_on = current_line - 1
55
- else
56
- line_to_insert_on = current_line
57
- end
58
-
59
- vim .api .nvim_buf_set_lines (
60
- 0 ,
61
- line_to_insert_on ,
62
- line_to_insert_on ,
63
- true ,
64
- { line_to_insert }
65
- )
89
+ line_to_insert = indent .. fixes .left .. debuginfo () .. fixes .right
66
90
end
67
- end
68
91
69
- M .debugprintvar = function (above ) end
92
+ if funcopts .above then
93
+ line_to_insert_on = current_line - 1
94
+ else
95
+ line_to_insert_on = current_line
96
+ end
97
+
98
+ vim .api .nvim_buf_set_lines (
99
+ 0 ,
100
+ line_to_insert_on ,
101
+ line_to_insert_on ,
102
+ true ,
103
+ { line_to_insert }
104
+ )
105
+ end
70
106
71
107
M .setup = function (o )
72
108
opts = vim .tbl_deep_extend (" force" , OPTION_DEFAULTS , o or {})
@@ -77,16 +113,16 @@ M.setup = function(o)
77
113
78
114
if opts .create_keymaps then
79
115
vim .keymap .set (" n" , " dqp" , function ()
80
- M .debugprint (false )
116
+ M .debugprint ()
81
117
end )
82
118
vim .keymap .set (" n" , " dqP" , function ()
83
- M .debugprint (true )
119
+ M .debugprint ({ above = true } )
84
120
end )
85
121
vim .keymap .set (" n" , " dQp" , function ()
86
- M .debugprintvar ( false )
122
+ M .debugprint ({ variable = true } )
87
123
end )
88
124
vim .keymap .set (" n" , " dQP" , function ()
89
- M .debugprintvar ( true )
125
+ M .debugprint ({ above = true , variable = true } )
90
126
end )
91
127
end
92
128
0 commit comments