@@ -368,7 +368,7 @@ MiniCompletion.completefunc_lsp = function(findstart, base)
368
368
if findstart == 1 then return - 3 end
369
369
return {}
370
370
else
371
- if findstart == 1 then return H .get_completion_start () end
371
+ if findstart == 1 then return H .get_completion_start (H . completion . lsp . result ) end
372
372
373
373
local process_items = H .get_config ().lsp_completion .process_items
374
374
local words = H .process_lsp_response (H .completion .lsp .result , function (response , client_id )
@@ -1285,12 +1285,29 @@ end
1285
1285
1286
1286
H .pumvisible = function () return vim .fn .pumvisible () > 0 end
1287
1287
1288
- H .get_completion_start = function ()
1289
- -- Compute start position of latest keyword (as in `vim.lsp.omnifunc`)
1288
+ H .get_completion_start = function (lsp_result )
1290
1289
local pos = vim .api .nvim_win_get_cursor (0 )
1290
+
1291
+ -- Prefer completion start from LSP response(s)
1292
+ for _ , response_data in pairs (lsp_result or {}) do
1293
+ local server_start = H .get_completion_start_server (response_data , pos [1 ] - 1 )
1294
+ if server_start ~= nil then return server_start end
1295
+ end
1296
+
1297
+ -- Fall back to start position of latest keyword
1291
1298
local line = vim .api .nvim_get_current_line ()
1292
- local line_to_cursor = line :sub (1 , pos [2 ])
1293
- return vim .fn .match (line_to_cursor , ' \\ k*$' )
1299
+ return vim .fn .match (line :sub (1 , pos [2 ]), ' \\ k*$' )
1300
+ end
1301
+
1302
+ H .get_completion_start_server = function (response_data , line_num )
1303
+ if response_data .err or type (response_data .result ) ~= ' table' then return end
1304
+ local items = response_data .result .items or response_data .result
1305
+ for _ , item in pairs (items ) do
1306
+ if type (item .textEdit ) == ' table' and item .textEdit .range .start .line == line_num then
1307
+ -- NOTE: Ignore case when items contain several conflicting starts
1308
+ return item .textEdit .range .start .character
1309
+ end
1310
+ end
1294
1311
end
1295
1312
1296
1313
H .is_whitespace = function (s )
0 commit comments