1
1
local M = {}
2
2
3
3
local actions = { ' build' , ' serve' , ' prod' }
4
+ local runners = require (' static.runners' )
5
+ local runnerNames = vim .tbl_keys (runners .runners )
4
6
5
7
local execute = function (args )
6
8
-- action == build, serve, prod
7
9
local arguments = args .fargs
8
- local action = arguments [ 1 ]
9
- -- remove the first argument which is the action
10
- table.remove ( arguments , 1 )
10
+ local runnerName
11
+ local runner
12
+ local action
11
13
12
- local _ , runner = require (' static.runners' ).find ()
14
+ -- If the second argument is the name of a runner
15
+ -- e.g. :Static astro build
16
+ if vim .tbl_contains (runnerNames , arguments [1 ]) then
17
+ runnerName = arguments [1 ]
18
+ action = arguments [2 ]
19
+
20
+ table.remove (arguments , 2 )
21
+ table.remove (arguments , 1 )
22
+ else
23
+ action = arguments [1 ]
24
+ table.remove (arguments , 1 )
25
+ end
26
+
27
+ _ , runner = runners .find (runnerName )
13
28
14
29
if not runner then
15
30
vim .notify (' Could not determine the correct runner.' , vim .log .levels .WARN )
16
31
return
17
32
end
18
33
34
+ if not action then
35
+ vim .notify (' Could not determine the action.' , vim .log .levels .WARN )
36
+ return
37
+ end
38
+
19
39
local command = runner [action ]
20
40
21
41
if command == nil then
@@ -34,9 +54,35 @@ function M.setup(opts)
34
54
config .setup (opts )
35
55
36
56
vim .api .nvim_create_user_command (' Static' , execute , {
37
- nargs = ' *' ,
38
- complete = function ()
39
- return actions
57
+ nargs = ' +' ,
58
+ complete = function (_ , line )
59
+ local parts = vim .split (vim .trim (line ), ' %s+' )
60
+
61
+ if parts [1 ]:find (' Static' ) then
62
+ table.remove (parts , 1 )
63
+ end
64
+
65
+ if line :sub (- 1 ) == ' ' then
66
+ parts [# parts + 1 ] = ' '
67
+ end
68
+
69
+ table.remove (parts , 1 )
70
+
71
+ if # parts > 0 then
72
+ return actions
73
+ end
74
+
75
+ local merged = {}
76
+
77
+ for _ , value in pairs (actions ) do
78
+ table.insert (merged , value )
79
+ end
80
+
81
+ for _ , value in pairs (runnerNames ) do
82
+ table.insert (merged , value )
83
+ end
84
+
85
+ return merged
40
86
end ,
41
87
})
42
88
end
0 commit comments