@@ -14,23 +14,103 @@ local user_command = require("live-command.user_command")
14
14
--- @field hl_groups livecmd.Config.HlGroups ?
15
15
--- @field commands table<string , livecmd.CommandSpec>
16
16
17
- local show_diagnostics_message = function (config )
18
- local message = [[
19
- Version 2.0 of live-command.nvim has dropped support for the "args" and "range" keys in the command specification.
20
- The following commands in your configuration are affected: %s. Please remove or modify them.
21
- See the migration guide for more information: https://github.com/smjonas/live-command.nvim/blob/main/migrate_to_v2.md
22
- ]]
17
+ local get_affected_cmd_names = function (config , is_affected_cmd_fn )
23
18
local affected_cmds = {}
24
19
for cmd_name , cmd_spec in pairs (config .commands ) do
25
- if cmd_spec . args ~= nil or cmd_spec . range ~= nil then
20
+ if is_affected_cmd_fn ( cmd_spec ) then
26
21
table.insert (affected_cmds , ' "' .. cmd_name .. ' "' )
27
22
end
28
23
end
29
- local cmd_names = table.concat (affected_cmds , " , " )
30
- local formatted_message = string.format (message , cmd_names )
24
+ return table.concat (affected_cmds , " , " ), # affected_cmds
25
+ end
26
+
27
+ local get_args_range_diagnostics_message = function (config )
28
+ local message = [[
29
+ - Dropped support for the "args" and "range" keys in the command specification:
30
+ The following commands in your configuration are affected: %s. Please remove or modify them.
31
+
32
+ ]]
33
+ local cmd_names , cmd_count = get_affected_cmd_names (config , function (cmd_spec )
34
+ return cmd_spec .args ~= nil or cmd_spec .range ~= nil
35
+ end )
36
+ if cmd_count == 0 then
37
+ return " "
38
+ end
39
+ return string.format (message , cmd_names )
40
+ end
41
+
42
+ local get_per_command_diagnostics_message = function (config )
43
+ local message = [[
44
+ - Dropped support for per-command options:
45
+ You can no longer set any of the options "enable_highlighting", "inline_highlighting" or "hl_groups" for individual commands.
46
+ The following commands are affected: %s.
47
+ Please just set the options for all commands like this:
48
+ require("live-command").setup {
49
+ enable_highlighting = ...,
50
+ inline_highlighting = ...,
51
+ hl_groups = {
52
+ ...
53
+ },
54
+ }
55
+
56
+ ]]
57
+ local cmd_names , cmd_count = get_affected_cmd_names (config , function (cmd_spec )
58
+ return cmd_spec .enable_highlighting ~= nil or cmd_spec .inline_highlighting ~= nil or cmd_spec .hl_groups ~= nil
59
+ end )
60
+ if cmd_count == 0 then
61
+ return " "
62
+ end
63
+ return string.format (message , cmd_names )
64
+ end
65
+
66
+ local get_defaults_diagnostics_message = function (config )
67
+ if config .defaults == nil then
68
+ return " "
69
+ end
70
+ return [[
71
+ - Inlined the "defaults" option:
72
+ To set any of the options "enable_highlighting", "inline_highlighting" or "hl_groups", you should no longer use the "defaults" table.
73
+ Instead, just set the options like this:
74
+ require("live-command").setup {
75
+ enable_highlighting = ...,
76
+ inline_highlighting = ...,
77
+ hl_groups = {
78
+ ...
79
+ },
80
+ }
81
+
82
+ ]]
83
+ end
84
+
85
+ local show_diagnostics_message = function (config )
86
+ local message = [[
87
+ Version 2.x of live-command.nvim has introduced some changes to the configuration:
88
+ %s%s%sSee the migration guide for more information: https://github.com/smjonas/live-command.nvim/blob/main/migrate_to_v2.md
89
+ ]]
90
+ local warning_msg_1 = get_args_range_diagnostics_message (config )
91
+ local warning_msg_2 = get_per_command_diagnostics_message (config )
92
+ local warning_msg_3 = get_defaults_diagnostics_message (config )
93
+ local formatted_message = message :format (warning_msg_1 , warning_msg_2 , warning_msg_3 )
31
94
vim .notify (formatted_message , vim .log .levels .INFO )
32
95
end
33
96
97
+ local are_unsupported_features_used = function (config )
98
+ if config .defaults ~= nil then
99
+ return true
100
+ end
101
+ for _ , cmd_spec in pairs (config .commands ) do
102
+ if
103
+ cmd_spec .args ~= nil
104
+ or cmd_spec .range ~= nil
105
+ or cmd_spec .enable_highlighting ~= nil
106
+ or cmd_spec .inline_highlighting ~= nil
107
+ or cmd_spec .hl_groups ~= nil
108
+ then
109
+ return true
110
+ end
111
+ end
112
+ end
113
+
34
114
--- @param config livecmd.Config
35
115
M .validate_config = function (config )
36
116
vim .validate {
@@ -40,16 +120,14 @@ M.validate_config = function(config)
40
120
hl_groups = { config .hl_groups , " table" },
41
121
commands = { config .commands , " table" },
42
122
}
43
- for cmd_name , cmd_spec in pairs (config .commands ) do
44
- if cmd_spec .args ~= nil or cmd_spec .range ~= nil then
45
- vim .notify (
46
- ' [live-command.nvim] Some unsupported features are used in your config. Please run ":LiveCommand diagnose" for details.' ,
47
- vim .log .levels .WARN
48
- )
49
- user_command .register_argument_handler (" diagnose" , function ()
50
- show_diagnostics_message (config )
51
- end )
52
- end
123
+ if are_unsupported_features_used (config ) then
124
+ vim .notify (
125
+ ' [live-command.nvim] Some unsupported features are used in your config. Please run ":LiveCommand diagnose" for details.' ,
126
+ vim .log .levels .WARN
127
+ )
128
+ user_command .register_argument_handler (" diagnose" , function ()
129
+ show_diagnostics_message (config )
130
+ end )
53
131
end
54
132
end
55
133
0 commit comments