@@ -3,6 +3,12 @@ local log = require("null-ls.logger")
3
3
local s = require (" null-ls.state" )
4
4
local u = require (" null-ls.utils" )
5
5
6
+ --- @class NullLsDynamicCommandParams
7
+ --- @field bufnr number
8
+ --- @field root string
9
+ --- @field bufname string
10
+ --- @field command string ?
11
+
6
12
local output_formats = {
7
13
raw = " raw" , -- receive error_output and output directly
8
14
none = nil , -- same as raw but will not send error output
@@ -133,12 +139,6 @@ return function(opts)
133
139
end
134
140
end
135
141
136
- if dynamic_command == nil then
137
- dynamic_command = function (params , done )
138
- done (params .command )
139
- end
140
- end
141
-
142
142
local is_nil_table_or_func = function (v )
143
143
return v == nil or vim .tbl_contains ({ " function" , " table" }, type (v ))
144
144
end
@@ -184,7 +184,27 @@ return function(opts)
184
184
return true
185
185
end
186
186
187
+ local function get_command_async (bufnr , done )
188
+ if dynamic_command then
189
+ dynamic_command ({
190
+ bufnr = bufnr ,
191
+ bufname = vim .api .nvim_buf_get_name (0 ),
192
+ root = u .get_root (),
193
+ command = command ,
194
+ }, done )
195
+ else
196
+ done (command )
197
+ end
198
+ end
199
+
187
200
return {
201
+ setup_buffer_async = function (bufnr , done )
202
+ -- Here we invoke `get_command_async` and throw away the result. Why? If
203
+ -- the underlying `dynamic_command` is expensive to compute, it's
204
+ -- nice to immediately start computing it, rather than waiting for
205
+ -- someone to need it.
206
+ get_command_async (bufnr , done )
207
+ end ,
188
208
fn = function (params , done )
189
209
local loop = require (" null-ls.loop" )
190
210
@@ -285,7 +305,7 @@ return function(opts)
285
305
286
306
params .command = command
287
307
288
- dynamic_command (params , function (resolved_command )
308
+ get_command_async (params . bufnr , function (resolved_command )
289
309
-- if dynamic_command returns nil, don't fall back to command
290
310
if not resolved_command then
291
311
log :debug (string.format (" unable to resolve command %s; aborting" , command ))
0 commit comments