Skip to content

Commit a4ed825

Browse files
authored
fix(lsp): don't return negative values from item_to_location (nvim-telescope#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
1 parent a17d611 commit a4ed825

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lua/telescope/builtin/__lsp.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ end
125125
---@param offset_encoding string|nil utf-8|utf-16|utf-32
126126
---@return lsp.Location
127127
local function item_to_location(item, offset_encoding)
128-
local line = item.lnum - 1
129-
local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1
128+
local line = math.max(0, item.lnum - 1)
129+
local character = math.max(0, utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1)
130130
local uri
131131
if utils.is_uri(item.filename) then
132132
uri = item.filename

0 commit comments

Comments
 (0)