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:
Will Lillis
2025-03-18 21:05:22 -04:00
committed by GitHub
parent a17d611a0e
commit a4ed82509c

View File

@@ -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