From a4ed82509cecc56df1c7138920a1aeaf246c0ac5 Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Tue, 18 Mar 2025 21:05:22 -0400 Subject: [PATCH] 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 --- lua/telescope/builtin/__lsp.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua index 4637256..d51bb6c 100644 --- a/lua/telescope/builtin/__lsp.lua +++ b/lua/telescope/builtin/__lsp.lua @@ -125,8 +125,8 @@ end ---@param offset_encoding string|nil utf-8|utf-16|utf-32 ---@return lsp.Location local function item_to_location(item, offset_encoding) - local line = item.lnum - 1 - local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1 + local line = math.max(0, item.lnum - 1) + local character = math.max(0, utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1) local uri if utils.is_uri(item.filename) then uri = item.filename