Skip to content

Commit 69c70e8

Browse files
committed
refactor: centralize check for Nvim 0.11
1 parent 6c73005 commit 69c70e8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lua/telescope/builtin/__lsp.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local utils = require "telescope.utils"
1111

1212
local lsp = {}
1313

14+
local nvim011 = utils.nvim011
15+
1416
local function call_hierarchy(opts, method, title, direction, item)
1517
vim.lsp.buf_request(opts.bufnr, method, { item = item }, function(err, result)
1618
if err then
@@ -75,7 +77,7 @@ end
7577
---@return lsp.TextDocumentPositionParams|TextDocumentFunction: Params to send to the server
7678
local function client_position_params(win, extra)
7779
win = win or vim.api.nvim_get_current_win()
78-
if 1 ~= vim.fn.has "nvim-0.11" then
80+
if not nvim011 then
7981
local params = vim.lsp.util.make_position_params(win)
8082
if extra then
8183
params = vim.tbl_extend("force", params, extra)
@@ -332,7 +334,7 @@ lsp.document_symbols = function(opts)
332334
end
333335

334336
local locations
335-
if vim.fn.has "nvim-0.11" == 1 then
337+
if nvim011 then
336338
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
337339
locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr, client.offset_encoding) or {}
338340
else
@@ -382,7 +384,7 @@ lsp.workspace_symbols = function(opts)
382384
end
383385

384386
local locations
385-
if vim.fn.has "nvim-0.11" == 1 then
387+
if nvim011 then
386388
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
387389
locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr, client.offset_encoding) or {}
388390
else
@@ -438,7 +440,7 @@ local function get_workspace_symbols_requester(bufnr, opts)
438440
if client_res.error then
439441
vim.api.nvim_err_writeln("Error when executing workspace/symbol : " .. client_res.error.message)
440442
elseif client_res.result ~= nil then
441-
if vim.fn.has "nvim-0.11" == 1 then
443+
if nvim011 then
442444
local client = assert(vim.lsp.get_client_by_id(client_id))
443445
vim.list_extend(locations, vim.lsp.util.symbols_to_items(client_res.result, bufnr, client.offset_encoding))
444446
else
@@ -476,7 +478,7 @@ local function check_capabilities(method, bufnr)
476478
local clients = vim.lsp.get_clients { bufnr = bufnr }
477479

478480
for _, client in pairs(clients) do
479-
if vim.fn.has "nvim-0.11" == 1 then
481+
if nvim011 then
480482
if client:supports_method(method, bufnr) then
481483
return true
482484
end

lua/telescope/utils.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ local get_status = require("telescope.state").get_status
1616
local utils = {}
1717

1818
utils.iswin = vim.uv.os_uname().sysname == "Windows_NT"
19+
utils.nvim011 = vim.fn.has "nvim-0.11" == 1
1920

2021
---@param s string
2122
---@param i number
2223
---@param encoding "utf-8" | "utf-16" | "utf-32"
2324
---@return integer
2425
utils.str_byteindex = function(s, i, encoding)
25-
if vim.fn.has "nvim-0.11" == 1 then
26+
if utils.nvim011 then
2627
return vim.str_byteindex(s, encoding, i, false)
2728
else
2829
return vim.lsp.util._str_byteindex_enc(s, i, encoding)
@@ -672,7 +673,7 @@ end)
672673
--- Checks if treesitter parser for language is installed
673674
---@param lang string
674675
utils.has_ts_parser = function(lang)
675-
if vim.fn.has "nvim-0.11" == 1 then
676+
if utils.nvim011 then
676677
return vim.treesitter.language.add(lang)
677678
else
678679
return pcall(vim.treesitter.language.add, lang)

0 commit comments

Comments
 (0)