@@ -5,22 +5,22 @@ local Item = require("trouble.item")
55local Promise = require (" trouble.promise" )
66local Util = require (" trouble.util" )
77
8- --- @param line string line to be indexed
8+ local str_byteindex_new = pcall (vim .str_byteindex , " aa" , " utf-8" , 1 )
9+
10+ --- @param s string line to be indexed
911--- @param index integer UTF index
1012--- @param encoding string utf-8 | utf-16 | utf-32 | defaults to utf-16
1113--- @return integer byte (utf-8 ) index of ` encoding` index ` index` in ` line`
12- local function get_line_col (line , index , encoding )
13- local function get ()
14- if vim .str_byteindex then
15- if vim .fn .has (" nvim-0.11" ) == 0 then
16- return vim .str_byteindex (line , encoding , index , false )
17- end
18- return vim .str_byteindex (line , index , encoding == " utf-16" )
19- end
20- return vim .lsp .util ._str_byteindex_enc (line , index , encoding )
14+ local function get_line_col (s , index , encoding )
15+ if str_byteindex_new then
16+ return vim .str_byteindex (s , encoding , index , false )
17+ elseif vim .str_byteindex then
18+ --- @diagnostic disable-next-line : param-type-mismatch
19+ return vim .str_byteindex (s , index , encoding == " utf-16" )
20+ elseif vim .lsp .util ._str_byteindex then
21+ return vim .lsp .util ._str_byteindex (s , index , encoding )
2122 end
22- local ok , ret = pcall (get )
23- return ok and ret or # line
23+ error (" No str_byteindex function available" )
2424end
2525
2626--- @class trouble.Source.lsp : trouble.Source
0 commit comments