37
37
38
38
M .analyze_stacktrace = function ()
39
39
local trace = fn .getreg (" *" )
40
- if trace :len () > 0 then
40
+ if trace and trace :len () > 0 then
41
41
execute_command ({ command = " metals.analyze-stacktrace" , arguments = { trace } })
42
42
else
43
43
log .warn_and_show (" No text found in your register." )
@@ -126,28 +126,30 @@ end
126
126
-- floating window.
127
127
M .info = function ()
128
128
local config = conf .get_config_cache ()
129
- if not util .has_bins (conf .metals_bin ()) and config .settings .metals .useGlobalExecutable then
129
+ if not util .has_bins (conf .metals_bin ()) and config and config .settings .metals .useGlobalExecutable then
130
130
log .error_and_show (messages .use_global_set_but_cant_find )
131
- elseif not util .has_bins (conf .metals_bin ()) and config .settings .metals .metalsBinaryPath then
131
+ elseif not util .has_bins (conf .metals_bin ()) and config and config .settings .metals .metalsBinaryPath then
132
132
log .error_and_show (messages .binary_path_set_but_cant_find )
133
133
elseif not util .has_bins (conf .metals_bin ()) then
134
134
log .warn_and_show (messages .metals_not_installed )
135
135
else
136
- local metals_info = fn .system (conf .metals_bin () .. " --version" )
137
-
138
136
local output = {}
139
- for s in metals_info :gmatch (" [^\r\n ]+" ) do
140
- -- A little hacky but the version output is weird and we want to coerce
141
- -- it to markdown, so we give the verstion line a # and then strip the
142
- -- other lines of their #
143
- if util .starts_with (s , " #" ) then
144
- table.insert (output , s :sub (2 ))
145
- else
146
- table.insert (output , " # " .. s )
137
+
138
+ local metals_info = fn .system (conf .metals_bin () .. " --version" )
139
+ if metals_info then
140
+ for s in metals_info :gmatch (" [^\r\n ]+" ) do
141
+ -- A little hacky but the version output is weird and we want to coerce
142
+ -- it to markdown, so we give the verstion line a # and then strip the
143
+ -- other lines of their #
144
+ if util .starts_with (s , " #" ) then
145
+ table.insert (output , s :sub (2 ))
146
+ else
147
+ table.insert (output , " # " .. s )
148
+ end
147
149
end
148
150
end
149
151
150
- if config .settings .metals then
152
+ if config and config .settings .metals then
151
153
table.insert (output , " " )
152
154
table.insert (output , " ## Current settings" )
153
155
table.insert (output , " ```json" )
@@ -161,7 +163,7 @@ M.info = function()
161
163
table.insert (output , string.format (" - nvim-metals log file: %s" , log .nvim_metals_log ))
162
164
table.insert (output , string.format (" - nvim lsp log file: %s" , lsp .get_log_path ()))
163
165
local loc_msg = " - metals install location:"
164
- if config .settings .metals .useGlobalExecutable then
166
+ if config and config .settings .metals .useGlobalExecutable then
165
167
table.insert (output , string.format (" %s %s" , loc_msg , " Using metals executable on $PATH" ))
166
168
else
167
169
table.insert (output , string.format (" %s %s" , loc_msg , conf .metals_bin ()))
@@ -271,31 +273,35 @@ M.did_focus = function()
271
273
end
272
274
273
275
M .find_in_dependency_jars = function ()
274
- local function send_request (mask , query )
275
- lsp .buf_request (util .find_metals_buffer (), " metals/findTextInDependencyJars" , {
276
- options = { include = mask },
277
- query = { pattern = query },
278
- })
279
- end
276
+ local metals_buf = util .find_metals_buffer ()
277
+
278
+ if metals_buf then
279
+ local function send_request (mask , query )
280
+ lsp .buf_request (metals_buf , " metals/findTextInDependencyJars" , {
281
+ options = { include = mask },
282
+ query = { pattern = query },
283
+ })
284
+ end
285
+
286
+ local function get_query_and_send (mask )
287
+ vim .ui .input ({
288
+ prompt = " Query: " ,
289
+ }, function (query )
290
+ if query ~= nil then
291
+ send_request (mask , query )
292
+ end
293
+ end )
294
+ end
280
295
281
- local function get_query_and_send (mask )
282
296
vim .ui .input ({
283
- prompt = " Query: " ,
284
- }, function (query )
285
- if query ~= nil then
286
- send_request (mask , query )
297
+ prompt = " File mask: " ,
298
+ default = " .conf" ,
299
+ }, function (mask )
300
+ if mask ~= nil then
301
+ get_query_and_send (mask )
287
302
end
288
303
end )
289
304
end
290
-
291
- vim .ui .input ({
292
- prompt = " File mask: " ,
293
- default = " .conf" ,
294
- }, function (mask )
295
- if mask ~= nil then
296
- get_query_and_send (mask )
297
- end
298
- end )
299
305
end
300
306
301
307
M .organize_imports = function ()
0 commit comments