Skip to content

Commit 225e188

Browse files
committed
refactor: centralize check for Nvim 0.11
1 parent 909bffc commit 225e188

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
@@ -9,6 +9,8 @@ local utils = require "telescope.utils"
99

1010
local lsp = {}
1111

12+
local nvim011 = utils.nvim011
13+
1214
local function call_hierarchy(opts, method, title, direction, item)
1315
vim.lsp.buf_request(opts.bufnr, method, { item = item }, function(err, result)
1416
if err then
@@ -73,7 +75,7 @@ end
7375
---@return table|(fun(client: vim.lsp.Client): table) parmas to send to the server
7476
local function client_position_params(win, extra)
7577
win = win or vim.api.nvim_get_current_win()
76-
if vim.fn.has "nvim-0.11" == 0 then
78+
if not nvim011 then
7779
local params = vim.lsp.util.make_position_params(win)
7880
if extra then
7981
params = vim.tbl_extend("force", params, extra)
@@ -330,7 +332,7 @@ lsp.document_symbols = function(opts)
330332
end
331333

332334
local locations
333-
if vim.fn.has "nvim-0.11" == 1 then
335+
if nvim011 then
334336
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
335337
locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr, client.offset_encoding) or {}
336338
else
@@ -380,7 +382,7 @@ lsp.workspace_symbols = function(opts)
380382
end
381383

382384
local locations
383-
if vim.fn.has "nvim-0.11" == 1 then
385+
if nvim011 then
384386
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
385387
locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr, client.offset_encoding) or {}
386388
else
@@ -436,7 +438,7 @@ local function get_workspace_symbols_requester(bufnr, opts)
436438
if client_res.error then
437439
vim.api.nvim_err_writeln("Error when executing workspace/symbol : " .. client_res.error.message)
438440
elseif client_res.result ~= nil then
439-
if vim.fn.has "nvim-0.11" == 1 then
441+
if nvim011 then
440442
local client = assert(vim.lsp.get_client_by_id(client_id))
441443
vim.list_extend(locations, vim.lsp.util.symbols_to_items(client_res.result, bufnr, client.offset_encoding))
442444
else
@@ -474,7 +476,7 @@ local function check_capabilities(method, bufnr)
474476
local clients = vim.lsp.get_clients { bufnr = bufnr }
475477

476478
for _, client in pairs(clients) do
477-
if vim.fn.has "nvim-0.11" == 1 then
479+
if nvim011 then
478480
if client:supports_method(method, bufnr) then
479481
return true
480482
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)