aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/_meta/options.lua4
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua2
-rw-r--r--runtime/lua/vim/lsp/buf.lua14
-rw-r--r--runtime/lua/vim/lsp/util.lua21
4 files changed, 25 insertions, 16 deletions
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
index 36c0f583c7..c33753047f 100644
--- a/runtime/lua/vim/_meta/options.lua
+++ b/runtime/lua/vim/_meta/options.lua
@@ -7310,7 +7310,9 @@ vim.go.titleold = vim.o.titleold
--- window. This happens only when the 'title' option is on.
---
--- When this option contains printf-style '%' items, they will be
---- expanded according to the rules used for 'statusline'.
+--- expanded according to the rules used for 'statusline'. If it contains
+--- an invalid '%' format, the value is used as-is and no error or warning
+--- will be given when the value is set.
--- This option cannot be set in a modeline when 'modelineexpr' is off.
---
--- Example:
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index 4e5d3f5701..f40a94a442 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -10629,7 +10629,7 @@ function vim.fn.wait(timeout, condition, interval) end
--- For example to make <c-j> work like <down> in wildmode, use: >vim
--- cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
--- <
---- (Note, this needs the 'wildcharm' option set appropriately).
+--- (Note: this needs the 'wildcharm' option set appropriately).
---
--- @return any
function vim.fn.wildmenumode() end
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index e3f4beeeb1..ccef314d86 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -829,11 +829,19 @@ local function on_code_action_results(results, opts)
return
end
- ---@param item {action: lsp.Command|lsp.CodeAction}
+ ---@param item {action: lsp.Command|lsp.CodeAction, ctx: lsp.HandlerContext}
local function format_item(item)
- local title = item.action.title:gsub('\r\n', '\\r\\n')
- return title:gsub('\n', '\\n')
+ local clients = vim.lsp.get_clients({ bufnr = item.ctx.bufnr })
+ local title = item.action.title:gsub('\r\n', '\\r\\n'):gsub('\n', '\\n')
+
+ if #clients == 1 then
+ return title
+ end
+
+ local source = vim.lsp.get_client_by_id(item.ctx.client_id).name
+ return ('%s [%s]'):format(title, source)
end
+
local select_opts = {
prompt = 'Code actions:',
kind = 'codeaction',
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 76a18a409c..e3eef8901b 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -159,25 +159,24 @@ end
---@param encoding string utf-8|utf-16|utf-32| defaults to utf-16
---@return integer byte (utf-8) index of `encoding` index `index` in `line`
function M._str_byteindex_enc(line, index, encoding)
- local len = #line
- if index > len then
- -- LSP spec: if character > line length, default to the line length.
- -- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
- return len
- end
+ -- LSP spec: if character > line length, default to the line length.
+ -- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
+ local len8 = #line
if not encoding then
encoding = 'utf-16'
end
if encoding == 'utf-8' then
- if index then
+ if index and index <= len8 then
return index
else
- return len
+ return len8
end
- elseif encoding == 'utf-16' then
- return vim.str_byteindex(line, index, true)
+ end
+ local len32, len16 = vim.str_utfindex(line)
+ if encoding == 'utf-16' then
+ return index <= len16 and vim.str_byteindex(line, index, true) or len8
elseif encoding == 'utf-32' then
- return vim.str_byteindex(line, index)
+ return index <= len32 and vim.str_byteindex(line, index) or len8
else
error('Invalid encoding: ' .. vim.inspect(encoding))
end