fix(lsp): don't return negative values from item_to_location (#3433)
Problem: If `telescope.builtin.__lsp.definition` is invoked on an empty file, `item_to_location` returns a location with `-1` as a its column value. Solution: Respectively return 0 if the line or column number is <= 0
This commit is contained in:
@@ -125,8 +125,8 @@ end
|
|||||||
---@param offset_encoding string|nil utf-8|utf-16|utf-32
|
---@param offset_encoding string|nil utf-8|utf-16|utf-32
|
||||||
---@return lsp.Location
|
---@return lsp.Location
|
||||||
local function item_to_location(item, offset_encoding)
|
local function item_to_location(item, offset_encoding)
|
||||||
local line = item.lnum - 1
|
local line = math.max(0, item.lnum - 1)
|
||||||
local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1
|
local character = math.max(0, utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1)
|
||||||
local uri
|
local uri
|
||||||
if utils.is_uri(item.filename) then
|
if utils.is_uri(item.filename) then
|
||||||
uri = item.filename
|
uri = item.filename
|
||||||
|
|||||||
Reference in New Issue
Block a user