commit 37079fca58f396fd866dc7b7d87a0100c17ee760
parent d55d7646c129a9afe1da3a61813bb365d178c421
Author: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Date: Fri, 30 Jun 2023 11:33:28 +0200
feat(lsp): move inlay_hint() to vim.lsp (#24130)
Allows to keep more functions hidden and gives a path forward for
further inlay_hint related functions - like applying textEdits.
See https://github.com/neovim/neovim/pull/23984#pullrequestreview-1486624668
Diffstat:
8 files changed, 336 insertions(+), 329 deletions(-)
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
@@ -810,6 +810,13 @@ get_log_path() *vim.lsp.get_log_path()*
Return: ~
(string) path to log file
+inlay_hint({bufnr}, {enable}) *vim.lsp.inlay_hint()*
+ Enable/disable/toggle inlay hints for a buffer
+
+ Parameters: ~
+ • {bufnr} (integer) Buffer handle, or 0 for current
+ • {enable} (boolean|nil) true/false to enable/disable, nil to toggle
+
omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
Implements 'omnifunc' compatible LSP completion.
@@ -1227,13 +1234,6 @@ incoming_calls() *vim.lsp.buf.incoming_calls()*
window. If the symbol can resolve to multiple items, the user can pick one
in the |inputlist()|.
-inlay_hint({bufnr}, {enable}) *vim.lsp.buf.inlay_hint()*
- Enable/disable/toggle inlay hints for a buffer
-
- Parameters: ~
- • {bufnr} (integer) Buffer handle, or 0 for current
- • {enable} (boolean|nil) true/false to enable/disable, nil to toggle
-
list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
List workspace folders.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
@@ -98,7 +98,7 @@ The following new APIs and features were added.
• |nvim_set_keymap()| and |nvim_del_keymap()| now support abbreviations.
-• Implemented LSP inlay hints: |vim.lsp.buf.inlay_hint()|
+• Implemented LSP inlay hints: |vim.lsp.inlay_hint()|
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
==============================================================================
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
@@ -2474,6 +2474,13 @@ function lsp.with(handler, override_config)
end
end
+--- Enable/disable/toggle inlay hints for a buffer
+---@param bufnr (integer) Buffer handle, or 0 for current
+---@param enable (boolean|nil) true/false to enable/disable, nil to toggle
+function lsp.inlay_hint(bufnr, enable)
+ return require('vim.lsp.inlay_hint')(bufnr, enable)
+end
+
--- Helper function to use when implementing a handler.
--- This will check that all of the keys in the user configuration
--- are valid keys and make sense to include for this handler.
diff --git a/runtime/lua/vim/lsp/_inlay_hint.lua b/runtime/lua/vim/lsp/_inlay_hint.lua
@@ -1,284 +0,0 @@
-local util = require('vim.lsp.util')
-local log = require('vim.lsp.log')
-local api = vim.api
-local M = {}
-
----@class lsp._inlay_hint.bufstate
----@field version integer
----@field client_hint table<integer, table<integer, lsp.InlayHint[]>> client_id -> (lnum -> hints)
----@field enabled boolean Whether inlay hints are enabled for the buffer
----@field timer uv.uv_timer_t? Debounce timer associated with the buffer
----@field applied table<integer, integer> Last version of hints applied to this line
-
----@type table<integer, lsp._inlay_hint.bufstate>
-local bufstates = {}
-
-local namespace = api.nvim_create_namespace('vim_lsp_inlayhint')
-local augroup = api.nvim_create_augroup('vim_lsp_inlayhint', {})
-
---- Reset the request debounce timer of a buffer
----@private
-local function reset_timer(reset_bufnr)
- local timer = bufstates[reset_bufnr].timer
- if timer then
- bufstates[reset_bufnr].timer = nil
- if not timer:is_closing() then
- timer:stop()
- timer:close()
- end
- end
-end
-
---- |lsp-handler| for the method `textDocument/inlayHint`
---- Store hints for a specific buffer and client
----@private
-function M.on_inlayhint(err, result, ctx, _)
- if err then
- local _ = log.error() and log.error('inlayhint', err)
- return
- end
- local bufnr = ctx.bufnr
- if util.buf_versions[bufnr] ~= ctx.version then
- return
- end
- local client_id = ctx.client_id
- if not result then
- return
- end
- local bufstate = bufstates[bufnr]
- if not (bufstate.client_hint and bufstate.version) then
- bufstate.client_hint = vim.defaulttable()
- bufstate.version = ctx.version
- end
- local hints_by_client = bufstate.client_hint
- local client = vim.lsp.get_client_by_id(client_id)
-
- local new_hints_by_lnum = vim.defaulttable()
- local num_unprocessed = #result
- if num_unprocessed == 0 then
- hints_by_client[client_id] = {}
- bufstate.version = ctx.version
- api.nvim__buf_redraw_range(bufnr, 0, -1)
- return
- end
-
- local lines = api.nvim_buf_get_lines(bufnr, 0, -1, false)
- ---@private
- local function pos_to_byte(position)
- local col = position.character
- if col > 0 then
- local line = lines[position.line + 1] or ''
- local ok, convert_result
- ok, convert_result = pcall(util._str_byteindex_enc, line, col, client.offset_encoding)
- if ok then
- return convert_result
- end
- return math.min(#line, col)
- end
- return col
- end
-
- for _, hint in ipairs(result) do
- local lnum = hint.position.line
- hint.position.character = pos_to_byte(hint.position)
- table.insert(new_hints_by_lnum[lnum], hint)
- end
-
- hints_by_client[client_id] = new_hints_by_lnum
- bufstate.version = ctx.version
- api.nvim__buf_redraw_range(bufnr, 0, -1)
-end
-
----@private
-local function resolve_bufnr(bufnr)
- return bufnr > 0 and bufnr or api.nvim_get_current_buf()
-end
-
---- Refresh inlay hints for a buffer
----
----@param opts (nil|table) Optional arguments
---- - bufnr (integer, default: 0): Buffer whose hints to refresh
---- - only_visible (boolean, default: false): Whether to only refresh hints for the visible regions of the buffer
----
----@private
-function M.refresh(opts)
- opts = opts or {}
- local bufnr = resolve_bufnr(opts.bufnr or 0)
- local bufstate = bufstates[bufnr]
- if not (bufstate and bufstate.enabled) then
- return
- end
- local only_visible = opts.only_visible or false
- local buffer_windows = {}
- for _, winid in ipairs(api.nvim_list_wins()) do
- if api.nvim_win_get_buf(winid) == bufnr then
- table.insert(buffer_windows, winid)
- end
- end
- for _, window in ipairs(buffer_windows) do
- local first = vim.fn.line('w0', window)
- local last = vim.fn.line('w$', window)
- local params = {
- textDocument = util.make_text_document_params(bufnr),
- range = {
- start = { line = first - 1, character = 0 },
- ['end'] = { line = last, character = 0 },
- },
- }
- vim.lsp.buf_request(bufnr, 'textDocument/inlayHint', params)
- end
- if not only_visible then
- local params = {
- textDocument = util.make_text_document_params(bufnr),
- range = {
- start = { line = 0, character = 0 },
- ['end'] = { line = api.nvim_buf_line_count(bufnr), character = 0 },
- },
- }
- vim.lsp.buf_request(bufnr, 'textDocument/inlayHint', params)
- end
-end
-
---- Clear inlay hints
----@param bufnr (integer) Buffer handle, or 0 for current
----@private
-local function clear(bufnr)
- bufnr = resolve_bufnr(bufnr)
- if not bufstates[bufnr] then
- return
- end
- reset_timer(bufnr)
- local bufstate = bufstates[bufnr]
- local client_lens = (bufstate or {}).client_hint or {}
- local client_ids = vim.tbl_keys(client_lens)
- for _, iter_client_id in ipairs(client_ids) do
- if bufstate then
- bufstate.client_hint[iter_client_id] = {}
- end
- end
- api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)
- api.nvim__buf_redraw_range(bufnr, 0, -1)
-end
-
----@private
-local function make_request(request_bufnr)
- reset_timer(request_bufnr)
- M.refresh({ bufnr = request_bufnr })
-end
-
---- Enable inlay hints for a buffer
----@param bufnr (integer) Buffer handle, or 0 for current
----@private
-function M.enable(bufnr)
- bufnr = resolve_bufnr(bufnr)
- local bufstate = bufstates[bufnr]
- if not (bufstate and bufstate.enabled) then
- bufstates[bufnr] = { enabled = true, timer = nil, applied = {} }
- M.refresh({ bufnr = bufnr })
- api.nvim_buf_attach(bufnr, true, {
- on_lines = function(_, cb_bufnr)
- if not bufstates[cb_bufnr].enabled then
- return true
- end
- reset_timer(cb_bufnr)
- bufstates[cb_bufnr].timer = vim.defer_fn(function()
- make_request(cb_bufnr)
- end, 200)
- end,
- on_reload = function(_, cb_bufnr)
- clear(cb_bufnr)
- if bufstates[cb_bufnr] and bufstates[cb_bufnr].enabled then
- bufstates[cb_bufnr] = { enabled = true, applied = {} }
- end
- M.refresh({ bufnr = cb_bufnr })
- end,
- on_detach = function(_, cb_bufnr)
- clear(cb_bufnr)
- bufstates[cb_bufnr] = nil
- end,
- })
- api.nvim_create_autocmd('LspDetach', {
- buffer = bufnr,
- callback = function(opts)
- clear(opts.buf)
- end,
- once = true,
- group = augroup,
- })
- end
-end
-
---- Disable inlay hints for a buffer
----@param bufnr (integer) Buffer handle, or 0 for current
----@private
-function M.disable(bufnr)
- bufnr = resolve_bufnr(bufnr)
- if bufstates[bufnr] and bufstates[bufnr].enabled then
- clear(bufnr)
- bufstates[bufnr].enabled = nil
- bufstates[bufnr].timer = nil
- end
-end
-
---- Toggle inlay hints for a buffer
----@param bufnr (integer) Buffer handle, or 0 for current
----@private
-function M.toggle(bufnr)
- bufnr = resolve_bufnr(bufnr)
- local bufstate = bufstates[bufnr]
- if bufstate and bufstate.enabled then
- M.disable(bufnr)
- else
- M.enable(bufnr)
- end
-end
-
-api.nvim_set_decoration_provider(namespace, {
- on_win = function(_, _, bufnr, topline, botline)
- local bufstate = bufstates[bufnr]
- if not bufstate then
- return
- end
-
- if bufstate.version ~= util.buf_versions[bufnr] then
- return
- end
- local hints_by_client = bufstate.client_hint
-
- for lnum = topline, botline do
- if bufstate.applied[lnum] ~= bufstate.version then
- api.nvim_buf_clear_namespace(bufnr, namespace, lnum, lnum + 1)
- for _, hints_by_lnum in pairs(hints_by_client) do
- local line_hints = hints_by_lnum[lnum] or {}
- for _, hint in pairs(line_hints) do
- local text = ''
- if type(hint.label) == 'string' then
- text = hint.label
- else
- for _, part in ipairs(hint.label) do
- text = text .. part.value
- end
- end
- local vt = {}
- if hint.paddingLeft then
- vt[#vt + 1] = { ' ' }
- end
- vt[#vt + 1] = { text, 'LspInlayHint' }
- if hint.paddingRight then
- vt[#vt + 1] = { ' ' }
- end
- api.nvim_buf_set_extmark(bufnr, namespace, lnum, hint.position.character, {
- virt_text_pos = 'inline',
- ephemeral = false,
- virt_text = vt,
- hl_mode = 'combine',
- })
- end
- end
- bufstate.applied[lnum] = bufstate.version
- end
- end
- end,
-})
-
-return M
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
@@ -796,19 +796,4 @@ function M.execute_command(command_params)
request('workspace/executeCommand', command_params)
end
---- Enable/disable/toggle inlay hints for a buffer
----@param bufnr (integer) Buffer handle, or 0 for current
----@param enable (boolean|nil) true/false to enable/disable, nil to toggle
-function M.inlay_hint(bufnr, enable)
- vim.validate({ enable = { enable, { 'boolean', 'nil' } }, bufnr = { bufnr, 'number' } })
- local inlay_hint = require('vim.lsp._inlay_hint')
- if enable then
- inlay_hint.enable(bufnr)
- elseif enable == false then
- inlay_hint.disable(bufnr)
- else
- inlay_hint.toggle(bufnr)
- end
-end
-
return M
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
@@ -220,7 +220,7 @@ M['textDocument/codeLens'] = function(...)
end
M['textDocument/inlayHint'] = function(...)
- return require('vim.lsp._inlay_hint').on_inlayhint(...)
+ return require('vim.lsp.inlay_hint').on_inlayhint(...)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
@@ -617,22 +617,8 @@ M['window/showDocument'] = function(_, result, ctx, _)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_inlayHint_refresh
-M['workspace/inlayHint/refresh'] = function(err, _, ctx)
- local inlay_hint = require('vim.lsp._inlay_hint')
- if err then
- return vim.NIL
- end
-
- for _, bufnr in ipairs(vim.lsp.get_buffers_by_client_id(ctx.client_id)) do
- for _, winid in ipairs(api.nvim_list_wins()) do
- if api.nvim_win_get_buf(winid) == bufnr then
- inlay_hint.refresh({ bufnr = bufnr })
- break
- end
- end
- end
-
- return vim.NIL
+M['workspace/inlayHint/refresh'] = function(err, result, ctx, config)
+ return require('vim.lsp.inlay_hint').on_refresh(err, result, ctx, config)
end
-- Add boilerplate error validation and logging for all of these.
diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua
@@ -0,0 +1,313 @@
+local util = require('vim.lsp.util')
+local log = require('vim.lsp.log')
+local api = vim.api
+local M = {}
+
+---@class lsp._inlay_hint.bufstate
+---@field version integer
+---@field client_hint table<integer, table<integer, lsp.InlayHint[]>> client_id -> (lnum -> hints)
+---@field enabled boolean Whether inlay hints are enabled for the buffer
+---@field timer uv.uv_timer_t? Debounce timer associated with the buffer
+---@field applied table<integer, integer> Last version of hints applied to this line
+
+---@type table<integer, lsp._inlay_hint.bufstate>
+local bufstates = {}
+
+local namespace = api.nvim_create_namespace('vim_lsp_inlayhint')
+local augroup = api.nvim_create_augroup('vim_lsp_inlayhint', {})
+
+--- Reset the request debounce timer of a buffer
+---@private
+local function reset_timer(reset_bufnr)
+ local timer = bufstates[reset_bufnr].timer
+ if timer then
+ bufstates[reset_bufnr].timer = nil
+ if not timer:is_closing() then
+ timer:stop()
+ timer:close()
+ end
+ end
+end
+
+--- |lsp-handler| for the method `textDocument/inlayHint`
+--- Store hints for a specific buffer and client
+---@private
+function M.on_inlayhint(err, result, ctx, _)
+ if err then
+ local _ = log.error() and log.error('inlayhint', err)
+ return
+ end
+ local bufnr = ctx.bufnr
+ if util.buf_versions[bufnr] ~= ctx.version then
+ return
+ end
+ local client_id = ctx.client_id
+ if not result then
+ return
+ end
+ local bufstate = bufstates[bufnr]
+ if not (bufstate.client_hint and bufstate.version) then
+ bufstate.client_hint = vim.defaulttable()
+ bufstate.version = ctx.version
+ end
+ local hints_by_client = bufstate.client_hint
+ local client = vim.lsp.get_client_by_id(client_id)
+
+ local new_hints_by_lnum = vim.defaulttable()
+ local num_unprocessed = #result
+ if num_unprocessed == 0 then
+ hints_by_client[client_id] = {}
+ bufstate.version = ctx.version
+ api.nvim__buf_redraw_range(bufnr, 0, -1)
+ return
+ end
+
+ local lines = api.nvim_buf_get_lines(bufnr, 0, -1, false)
+ ---@private
+ local function pos_to_byte(position)
+ local col = position.character
+ if col > 0 then
+ local line = lines[position.line + 1] or ''
+ local ok, convert_result
+ ok, convert_result = pcall(util._str_byteindex_enc, line, col, client.offset_encoding)
+ if ok then
+ return convert_result
+ end
+ return math.min(#line, col)
+ end
+ return col
+ end
+
+ for _, hint in ipairs(result) do
+ local lnum = hint.position.line
+ hint.position.character = pos_to_byte(hint.position)
+ table.insert(new_hints_by_lnum[lnum], hint)
+ end
+
+ hints_by_client[client_id] = new_hints_by_lnum
+ bufstate.version = ctx.version
+ api.nvim__buf_redraw_range(bufnr, 0, -1)
+end
+
+---@private
+local function resolve_bufnr(bufnr)
+ return bufnr > 0 and bufnr or api.nvim_get_current_buf()
+end
+
+--- Refresh inlay hints for a buffer
+---
+---@param opts (nil|table) Optional arguments
+--- - bufnr (integer, default: 0): Buffer whose hints to refresh
+--- - only_visible (boolean, default: false): Whether to only refresh hints for the visible regions of the buffer
+---
+---@private
+local function refresh(opts)
+ opts = opts or {}
+ local bufnr = resolve_bufnr(opts.bufnr or 0)
+ local bufstate = bufstates[bufnr]
+ if not (bufstate and bufstate.enabled) then
+ return
+ end
+ local only_visible = opts.only_visible or false
+ local buffer_windows = {}
+ for _, winid in ipairs(api.nvim_list_wins()) do
+ if api.nvim_win_get_buf(winid) == bufnr then
+ table.insert(buffer_windows, winid)
+ end
+ end
+ for _, window in ipairs(buffer_windows) do
+ local first = vim.fn.line('w0', window)
+ local last = vim.fn.line('w$', window)
+ local params = {
+ textDocument = util.make_text_document_params(bufnr),
+ range = {
+ start = { line = first - 1, character = 0 },
+ ['end'] = { line = last, character = 0 },
+ },
+ }
+ vim.lsp.buf_request(bufnr, 'textDocument/inlayHint', params)
+ end
+ if not only_visible then
+ local params = {
+ textDocument = util.make_text_document_params(bufnr),
+ range = {
+ start = { line = 0, character = 0 },
+ ['end'] = { line = api.nvim_buf_line_count(bufnr), character = 0 },
+ },
+ }
+ vim.lsp.buf_request(bufnr, 'textDocument/inlayHint', params)
+ end
+end
+
+--- |lsp-handler| for the method `textDocument/inlayHint/refresh`
+---@private
+function M.on_refresh(err, _, ctx, _)
+ if err then
+ return vim.NIL
+ end
+ for _, bufnr in ipairs(vim.lsp.get_buffers_by_client_id(ctx.client_id)) do
+ for _, winid in ipairs(api.nvim_list_wins()) do
+ if api.nvim_win_get_buf(winid) == bufnr then
+ refresh({ bufnr = bufnr })
+ break
+ end
+ end
+ end
+
+ return vim.NIL
+end
+
+--- Clear inlay hints
+---@param bufnr (integer) Buffer handle, or 0 for current
+---@private
+local function clear(bufnr)
+ bufnr = resolve_bufnr(bufnr)
+ if not bufstates[bufnr] then
+ return
+ end
+ reset_timer(bufnr)
+ local bufstate = bufstates[bufnr]
+ local client_lens = (bufstate or {}).client_hint or {}
+ local client_ids = vim.tbl_keys(client_lens)
+ for _, iter_client_id in ipairs(client_ids) do
+ if bufstate then
+ bufstate.client_hint[iter_client_id] = {}
+ end
+ end
+ api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)
+ api.nvim__buf_redraw_range(bufnr, 0, -1)
+end
+
+---@private
+local function make_request(request_bufnr)
+ reset_timer(request_bufnr)
+ refresh({ bufnr = request_bufnr })
+end
+
+--- Enable inlay hints for a buffer
+---@param bufnr (integer) Buffer handle, or 0 for current
+---@private
+local function enable(bufnr)
+ bufnr = resolve_bufnr(bufnr)
+ local bufstate = bufstates[bufnr]
+ if not (bufstate and bufstate.enabled) then
+ bufstates[bufnr] = { enabled = true, timer = nil, applied = {} }
+ refresh({ bufnr = bufnr })
+ api.nvim_buf_attach(bufnr, true, {
+ on_lines = function(_, cb_bufnr)
+ if not bufstates[cb_bufnr].enabled then
+ return true
+ end
+ reset_timer(cb_bufnr)
+ bufstates[cb_bufnr].timer = vim.defer_fn(function()
+ make_request(cb_bufnr)
+ end, 200)
+ end,
+ on_reload = function(_, cb_bufnr)
+ clear(cb_bufnr)
+ if bufstates[cb_bufnr] and bufstates[cb_bufnr].enabled then
+ bufstates[cb_bufnr] = { enabled = true, applied = {} }
+ end
+ refresh({ bufnr = cb_bufnr })
+ end,
+ on_detach = function(_, cb_bufnr)
+ clear(cb_bufnr)
+ bufstates[cb_bufnr] = nil
+ end,
+ })
+ api.nvim_create_autocmd('LspDetach', {
+ buffer = bufnr,
+ callback = function(opts)
+ clear(opts.buf)
+ end,
+ once = true,
+ group = augroup,
+ })
+ end
+end
+
+--- Disable inlay hints for a buffer
+---@param bufnr (integer) Buffer handle, or 0 for current
+---@private
+local function disable(bufnr)
+ bufnr = resolve_bufnr(bufnr)
+ if bufstates[bufnr] and bufstates[bufnr].enabled then
+ clear(bufnr)
+ bufstates[bufnr].enabled = nil
+ bufstates[bufnr].timer = nil
+ end
+end
+
+--- Toggle inlay hints for a buffer
+---@param bufnr (integer) Buffer handle, or 0 for current
+---@private
+local function toggle(bufnr)
+ bufnr = resolve_bufnr(bufnr)
+ local bufstate = bufstates[bufnr]
+ if bufstate and bufstate.enabled then
+ M.disable(bufnr)
+ else
+ M.enable(bufnr)
+ end
+end
+
+api.nvim_set_decoration_provider(namespace, {
+ on_win = function(_, _, bufnr, topline, botline)
+ local bufstate = bufstates[bufnr]
+ if not bufstate then
+ return
+ end
+
+ if bufstate.version ~= util.buf_versions[bufnr] then
+ return
+ end
+ local hints_by_client = bufstate.client_hint
+
+ for lnum = topline, botline do
+ if bufstate.applied[lnum] ~= bufstate.version then
+ api.nvim_buf_clear_namespace(bufnr, namespace, lnum, lnum + 1)
+ for _, hints_by_lnum in pairs(hints_by_client) do
+ local line_hints = hints_by_lnum[lnum] or {}
+ for _, hint in pairs(line_hints) do
+ local text = ''
+ if type(hint.label) == 'string' then
+ text = hint.label
+ else
+ for _, part in ipairs(hint.label) do
+ text = text .. part.value
+ end
+ end
+ local vt = {}
+ if hint.paddingLeft then
+ vt[#vt + 1] = { ' ' }
+ end
+ vt[#vt + 1] = { text, 'LspInlayHint' }
+ if hint.paddingRight then
+ vt[#vt + 1] = { ' ' }
+ end
+ api.nvim_buf_set_extmark(bufnr, namespace, lnum, hint.position.character, {
+ virt_text_pos = 'inline',
+ ephemeral = false,
+ virt_text = vt,
+ hl_mode = 'combine',
+ })
+ end
+ end
+ bufstate.applied[lnum] = bufstate.version
+ end
+ end
+ end,
+})
+
+return setmetatable(M, {
+ __call = function(_, bufnr, enable_)
+ vim.validate({ enable = { enable_, { 'boolean', 'nil' } }, bufnr = { bufnr, 'number' } })
+ if enable_ then
+ enable(bufnr)
+ elseif enable_ == false then
+ disable(bufnr)
+ else
+ toggle(bufnr)
+ end
+ end,
+})
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -64,7 +64,7 @@ describe('inlay hints', function()
end)
it(
- 'inlay hints are applied when vim.lsp.buf.inlay_hint(true) is called',
+ 'inlay hints are applied when vim.lsp.inlay_hint(true) is called',
function()
local res = exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
@@ -79,7 +79,7 @@ describe('inlay hints', function()
insert(text)
- exec_lua([[vim.lsp.buf.inlay_hint(bufnr, true)]])
+ exec_lua([[vim.lsp.inlay_hint(bufnr, true)]])
screen:expect({
grid = [[
auto add(int a, int b)-> int { return a + b; } |
@@ -96,7 +96,7 @@ describe('inlay hints', function()
end)
it(
- 'inlay hints are cleared when vim.lsp.buf.inlay_hint(false) is called',
+ 'inlay hints are cleared when vim.lsp.inlay_hint(false) is called',
function()
exec_lua([[
bufnr = vim.api.nvim_get_current_buf()
@@ -105,7 +105,7 @@ describe('inlay hints', function()
]])
insert(text)
- exec_lua([[vim.lsp.buf.inlay_hint(bufnr, true)]])
+ exec_lua([[vim.lsp.inlay_hint(bufnr, true)]])
screen:expect({
grid = [[
auto add(int a, int b)-> int { return a + b; } |
@@ -119,7 +119,7 @@ describe('inlay hints', function()
|
]]
})
- exec_lua([[vim.lsp.buf.inlay_hint(bufnr, false)]])
+ exec_lua([[vim.lsp.inlay_hint(bufnr, false)]])
screen:expect({
grid = [[
auto add(int a, int b) { return a + b; } |