aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/provider/pythonx.vim2
-rw-r--r--runtime/doc/editing.txt4
-rw-r--r--runtime/doc/eval.txt33
-rw-r--r--runtime/doc/lsp.txt3
-rw-r--r--runtime/doc/lua.txt89
-rw-r--r--runtime/doc/vim_diff.txt4
-rw-r--r--runtime/filetype.vim3
-rw-r--r--runtime/indent/testdir/runtest.vim1
-rw-r--r--runtime/lua/vim/highlight.lua41
-rw-r--r--runtime/lua/vim/lsp/buf.lua16
-rw-r--r--runtime/lua/vim/lsp/callbacks.lua52
-rw-r--r--runtime/lua/vim/lsp/log.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua10
-rw-r--r--runtime/lua/vim/lsp/util.lua106
-rw-r--r--runtime/lua/vim/shared.lua41
-rw-r--r--runtime/lua/vim/uri.lua10
-rw-r--r--runtime/pack/dist/opt/termdebug/plugin/termdebug.vim21
-rw-r--r--runtime/syntax/tutor.vim12
18 files changed, 387 insertions, 65 deletions
diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim
index 23e7ff8f64..ffb9bf3021 100644
--- a/runtime/autoload/provider/pythonx.vim
+++ b/runtime/autoload/provider/pythonx.vim
@@ -29,7 +29,7 @@ endfunction
function! s:get_python_candidates(major_version) abort
return {
\ 2: ['python2', 'python2.7', 'python2.6', 'python'],
- \ 3: ['python3', 'python3.8', 'python3.7', 'python3.6', 'python3.5',
+ \ 3: ['python3', 'python3.9', 'python3.8', 'python3.7', 'python3.6', 'python3.5',
\ 'python3.4', 'python3.3', 'python']
\ }[a:major_version]
endfunction
diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt
index 23a65f16e4..ac398ec494 100644
--- a/runtime/doc/editing.txt
+++ b/runtime/doc/editing.txt
@@ -1265,7 +1265,7 @@ exist, the next-higher scope in the hierarchy applies.
other tabs and windows is not changed.
*:tcd-*
-:tcd[!] - Change to the previous current directory (before the
+:tc[d][!] - Change to the previous current directory (before the
previous ":tcd {path}" command).
*:tch* *:tchdir*
@@ -1280,7 +1280,7 @@ exist, the next-higher scope in the hierarchy applies.
:lch[dir][!] Same as |:lcd|.
*:lcd-*
-:lcd[!] - Change to the previous current directory (before the
+:lc[d][!] - Change to the previous current directory (before the
previous ":lcd {path}" command).
*:pw* *:pwd* *E187*
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 6f13b34876..214d815006 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1423,6 +1423,10 @@ PREDEFINED VIM VARIABLES *vim-variable* *v:var* *v:*
*E963*
Some variables can be set by the user, but the type cannot be changed.
+ *v:argv* *argv-variable*
+v:argv The command line arguments Vim was invoked with. This is a
+ list of strings. The first item is the Vim command.
+
*v:beval_col* *beval_col-variable*
v:beval_col The number of the column, over which the mouse pointer is.
This is the byte index in the |v:beval_lnum| line.
@@ -2059,7 +2063,7 @@ chanclose({id}[, {stream}]) Number Closes a channel or one of its streams
chansend({id}, {data}) Number Writes {data} to channel
char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
cindent({lnum}) Number C indent for line {lnum}
-clearmatches() none clear all matches
+clearmatches([{win}]) none clear all matches
col({expr}) Number column nr of cursor or mark
complete({startcol}, {matches}) none set Insert mode completion
complete_add({expr}) Number add completion match
@@ -2167,7 +2171,7 @@ getjumplist([{winnr} [, {tabnr}]])
getline({lnum}) String line {lnum} of current buffer
getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
getloclist({nr} [, {what}]) List list of location list items
-getmatches() List list of current matches
+getmatches([{win}]) List list of current matches
getpid() Number process ID of Vim
getpos({expr}) List position of cursor, mark, etc.
getqflist([{what}]) List list of quickfix items
@@ -2259,7 +2263,7 @@ matchadd({group}, {pattern}[, {priority}[, {id}]])
matchaddpos({group}, {list}[, {priority}[, {id}]])
Number highlight positions with {group}
matcharg({nr}) List arguments of |:match|
-matchdelete({id}) Number delete match identified by {id}
+matchdelete({id} [, {win}]) Number delete match identified by {id}
matchend({expr}, {pat}[, {start}[, {count}]])
Number position where {pat} ends in {expr}
matchlist({expr}, {pat}[, {start}[, {count}]])
@@ -2352,7 +2356,7 @@ setfperm({fname}, {mode} Number set {fname} file permissions to {mode}
setline({lnum}, {line}) Number set line {lnum} to {line}
setloclist({nr}, {list}[, {action}[, {what}]])
Number modify location list using {list}
-setmatches({list}) Number restore a list of matches
+setmatches({list} [, {win}]) Number restore a list of matches
setpos({expr}, {list}) Number set the {expr} position to {list}
setqflist({list}[, {action}[, {what}]]
Number modify quickfix list using {list}
@@ -2600,6 +2604,7 @@ argv([{nr} [, {winid}])
the whole |arglist| is returned.
The {winid} argument specifies the window ID, see |argc()|.
+ For the Vim command line arguments see |v:argv|.
assert_beeps({cmd}) *assert_beeps()*
Run {cmd} and add an error message to |v:errors| if it does
@@ -3005,9 +3010,11 @@ cindent({lnum}) *cindent()*
When {lnum} is invalid -1 is returned.
See |C-indenting|.
-clearmatches() *clearmatches()*
- Clears all matches previously defined for the current window
- by |matchadd()| and the |:match| commands.
+clearmatches([{win}]) *clearmatches()*
+ Clears all matches previously defined for the current window
+ by |matchadd()| and the |:match| commands.
+ If {win} is specified, use the window with this number or
+ window ID instead of the current window.
*col()*
col({expr}) The result is a Number, which is the byte index of the column
@@ -4602,7 +4609,7 @@ getloclist({nr},[, {what}]) *getloclist()*
field is applicable only when called from a location list
window.
-getmatches() *getmatches()*
+getmatches([{win}]) *getmatches()*
Returns a |List| with all matches previously defined for the
current window by |matchadd()| and the |:match| commands.
|getmatches()| is useful in combination with |setmatches()|,
@@ -5943,7 +5950,7 @@ matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]])
Defines a pattern to be highlighted in the current window (a
"match"). It will be highlighted with {group}. Returns an
identification number (ID), which can be used to delete the
- match using |matchdelete()|.
+ match using |matchdelete()|. The ID is bound to the window.
Matching is case sensitive and magic, unless case sensitivity
or magicness are explicitly overridden in {pattern}. The
'magic', 'smartcase' and 'ignorecase' options are not used.
@@ -6043,11 +6050,13 @@ matcharg({nr}) *matcharg()*
Highlighting matches using the |:match| commands are limited
to three matches. |matchadd()| does not have this limitation.
-matchdelete({id}) *matchdelete()* *E802* *E803*
+matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Deletes a match with ID {id} previously defined by |matchadd()|
or one of the |:match| commands. Returns 0 if successful,
otherwise -1. See example for |matchadd()|. All matches can
be deleted in one operation by |clearmatches()|.
+ If {win} is specified, use the window with this number or
+ window ID instead of the current window.
matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
Same as |match()|, but return the index of first character
@@ -7420,11 +7429,13 @@ setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()*
only the items listed in {what} are set. Refer to |setqflist()|
for the list of supported keys in {what}.
-setmatches({list}) *setmatches()*
+setmatches({list} [, {win}]) *setmatches()*
Restores a list of matches saved by |getmatches() for the
current window|. Returns 0 if successful, otherwise -1. All
current matches are cleared before the list is restored. See
example for |getmatches()|.
+ If {win} is specified, use the window with this number or
+ window ID instead of the current window.
*setpos()*
setpos({expr}, {list})
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 249136f32f..9460e600e3 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -731,6 +731,9 @@ transform_schema_to_table()
==============================================================================
Lua module: vim.lsp.buf *lsp-buf*
+code_action({context}) *vim.lsp.buf.code_action()*
+ TODO: Documentation
+
completion({context}) *vim.lsp.buf.completion()*
TODO: Documentation
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 7f376cbbf0..2b83c35c90 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -693,6 +693,27 @@ identical identifiers, highlighting both as |hl-WarningMsg|: >
(eq? @WarningMsg.left @WarningMsg.right))
------------------------------------------------------------------------------
+VIM.HIGHLIGHT *lua-highlight*
+
+Nvim includes a function for highlighting a selection on yank (see for example
+https://github.com/machakann/vim-highlightedyank). To enable it, add
+>
+ au TextYankPost * silent! lua require'vim.highlight'.on_yank()
+<
+to your `init.vim`. You can customize the highlight group and the duration of
+the highlight via
+>
+ au TextYankPost * silent! lua require'vim.highlight'.on_yank("IncSearch", 500)
+<
+
+vim.highlight.on_yank([{higroup}, {timeout}, {event}])
+ *vim.highlight.on_yank()*
+ Highlights the yanked text. Optional arguments are the highlight group
+ to use ({higroup}, default `"IncSearch"`), the duration of highlighting
+ in milliseconds ({timeout}, default `500`), and the event structure
+ that is fired ({event}, default `vim.v.event`).
+
+------------------------------------------------------------------------------
VIM.REGEX *lua-regex*
Vim regexes can be used directly from lua. Currently they only allow
@@ -758,6 +779,14 @@ vim.empty_dict() *vim.empty_dict()*
Note: if numeric keys are added to the table, the metatable will be
ignored and the dict converted to a list/array anyway.
+vim.region({bufnr}, {pos1}, {pos2}, {type}, {inclusive}) *vim.region()*
+ Converts a selection specified by the buffer ({bufnr}), starting
+ position ({pos1}, a zero-indexed pair `{line1,column1}`), ending
+ position ({pos2}, same format as {pos1}), the type of the register
+ for the selection ({type}, see |regtype|), and a boolean indicating
+ whether the selection is inclusive or not, into a zero-indexed table
+ of linewise selections of the form `{linenr = {startcol, endcol}}` .
+
vim.rpcnotify({channel}, {method}[, {args}...]) *vim.rpcnotify()*
Sends {event} to {channel} via |RPC| and returns immediately.
If {channel} is 0, the event is broadcast to all channels.
@@ -850,6 +879,66 @@ vim.types *vim.types*
only contain values for these three types.
==============================================================================
+Vim Internal Variables *lua-vim-internal-variables*
+
+Built-in Vim dictionaries can be accessed and set idiomatically in Lua by each
+of the following tables.
+
+To set a value: >
+
+ vim.g.my_global_variable = 5
+<
+
+To read a value: >
+
+ print(vim.g.my_global_variable)
+<
+
+To delete a value: >
+
+ vim.g.my_global_variable = nil
+<
+
+vim.g *vim.g*
+ Table with values from |g:|
+ Keys with no values set will result in `nil`.
+
+vim.b *vim.b*
+ Gets a buffer-scoped (b:) variable for the current buffer.
+ Keys with no values set will result in `nil`.
+
+vim.w *vim.w*
+ Gets a window-scoped (w:) variable for the current window.
+ Keys with no values set will result in `nil`.
+
+vim.t *vim.t*
+ Gets a tabpage-scoped (t:) variable for the current table.
+ Keys with no values set will result in `nil`.
+
+vim.v *vim.v*
+ Gets a v: variable.
+ Keys with no values set will result in `nil`.
+
+
+Vim Internal Options *lua-vim-internal-options*
+
+Read, set and clear vim |options| in Lua by each of the following tables.
+
+
+vim.o *vim.o*
+ Table with values from |options|
+ Invalid keys will result in an error.
+
+vim.bo *vim.bo*
+ Gets a buffer-scoped option for the current buffer.
+ Invalid keys will result in an error.
+
+vim.wo *vim.wo*
+ Gets a window-scoped option for the current window.
+ Invalid keys will result in an error.
+
+
+==============================================================================
Lua module: vim *lua-vim*
inspect({object}, {options}) *vim.inspect()*
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 376375e4ef..24b562543e 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -116,6 +116,10 @@ backwards-compatibility cost. Some examples:
- Directories for 'directory' and 'undodir' are auto-created.
- Terminal features such as 'guicursor' are enabled where possible.
+Some features are built in that otherwise required external plugins:
+
+- Highlighting the yanked region, see |lua-highlight|.
+
ARCHITECTURE ~
External plugins run in separate processes. |remote-plugin| This improves
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index dc0bca2c60..0b5003dc44 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1129,6 +1129,9 @@ au BufNewFile,BufRead pf.conf setf pf
" Pam conf
au BufNewFile,BufRead */etc/pam.conf setf pamconf
+" Pam environment
+au BufNewFile,BufRead pam_env.conf,.pam_environment setf pamenv
+
" PApp
au BufNewFile,BufRead *.papp,*.pxml,*.pxsl setf papp
diff --git a/runtime/indent/testdir/runtest.vim b/runtime/indent/testdir/runtest.vim
index 9502c42f3e..945c2753e9 100644
--- a/runtime/indent/testdir/runtest.vim
+++ b/runtime/indent/testdir/runtest.vim
@@ -10,6 +10,7 @@ filetype indent on
syn on
set nowrapscan
set report=9999
+set modeline
au! SwapExists * call HandleSwapExists()
func HandleSwapExists()
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua
new file mode 100644
index 0000000000..5c98c626a4
--- /dev/null
+++ b/runtime/lua/vim/highlight.lua
@@ -0,0 +1,41 @@
+local api = vim.api
+
+local highlight = {}
+
+--- Highlight the yanked region
+--
+--- use from init.vim via
+--- au TextYankPost * lua require'vim.highlight'.on_yank()
+--- customize highlight group and timeout via
+--- au TextYankPost * lua require'vim.highlight'.on_yank("IncSearch", 500)
+-- @param higroup highlight group for yanked region
+-- @param timeout time in ms before highlight is cleared
+-- @param event event structure
+function highlight.on_yank(higroup, timeout, event)
+ event = event or vim.v.event
+ if event.operator ~= 'y' or event.regtype == '' then return end
+ higroup = higroup or "IncSearch"
+ timeout = timeout or 500
+
+ local bufnr = api.nvim_get_current_buf()
+ local yank_ns = api.nvim_create_namespace('')
+ api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
+
+ local pos1 = vim.fn.getpos("'[")
+ local pos2 = vim.fn.getpos("']")
+
+ pos1 = {pos1[2] - 1, pos1[3] - 1 + pos1[4]}
+ pos2 = {pos2[2] - 1, pos2[3] - 1 + pos2[4]}
+
+ local region = vim.region(bufnr, pos1, pos2, event.regtype, event.inclusive)
+ for linenr, cols in pairs(region) do
+ api.nvim_buf_add_highlight(bufnr, yank_ns, higroup, linenr, cols[1], cols[2])
+ end
+
+ vim.defer_fn(
+ function() api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) end,
+ timeout
+ )
+end
+
+return highlight
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 0b45951a56..7a819f3c3d 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -161,5 +161,21 @@ function M.clear_references()
util.buf_clear_references()
end
+function M.code_action(context)
+ validate { context = { context, 't', true } }
+ context = context or { diagnostics = util.get_line_diagnostics() }
+ local params = util.make_range_params()
+ params.context = context
+ request('textDocument/codeAction', params)
+end
+
+function M.execute_command(command)
+ validate {
+ command = { command.command, 's' },
+ arguments = { command.arguments, 't', true }
+ }
+ request('workspace/executeCommand', command)
+end
+
return M
-- vim:sw=2 ts=2 et
diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua
index 70d21be8e7..7c51fc2cc2 100644
--- a/runtime/lua/vim/lsp/callbacks.lua
+++ b/runtime/lua/vim/lsp/callbacks.lua
@@ -3,6 +3,7 @@ local protocol = require 'vim.lsp.protocol'
local util = require 'vim.lsp.util'
local vim = vim
local api = vim.api
+local buf = require 'vim.lsp.buf'
local M = {}
@@ -11,13 +12,56 @@ local function err_message(...)
api.nvim_command("redraw")
end
+M['workspace/executeCommand'] = function(err, _)
+ if err then
+ error("Could not execute code action: "..err.message)
+ end
+end
+
+M['textDocument/codeAction'] = function(_, _, actions)
+ if actions == nil or vim.tbl_isempty(actions) then
+ print("No code actions available")
+ return
+ end
+
+ local option_strings = {"Code Actions:"}
+ for i, action in ipairs(actions) do
+ local title = action.title:gsub('\r\n', '\\r\\n')
+ title = title:gsub('\n', '\\n')
+ table.insert(option_strings, string.format("%d. %s", i, title))
+ end
+
+ local choice = vim.fn.inputlist(option_strings)
+ if choice < 1 or choice > #actions then
+ return
+ end
+ local action_chosen = actions[choice]
+ -- textDocument/codeAction can return either Command[] or CodeAction[].
+ -- If it is a CodeAction, it can have either an edit, a command or both.
+ -- Edits should be executed first
+ if action_chosen.edit or type(action_chosen.command) == "table" then
+ if action_chosen.edit then
+ util.apply_workspace_edit(action_chosen.edit)
+ end
+ if type(action_chosen.command) == "table" then
+ buf.execute_command(action_chosen.command)
+ end
+ else
+ buf.execute_command(action_chosen)
+ end
+end
+
M['workspace/applyEdit'] = function(_, _, workspace_edit)
if not workspace_edit then return end
-- TODO(ashkan) Do something more with label?
if workspace_edit.label then
print("Workspace edit", workspace_edit.label)
end
- util.apply_workspace_edit(workspace_edit.edit)
+ local status, result = pcall(util.apply_workspace_edit, workspace_edit.edit)
+ return {
+ applied = status;
+ failureReason = result;
+ }
end
M['textDocument/publishDiagnostics'] = function(_, _, result)
@@ -198,12 +242,12 @@ end
-- Add boilerplate error validation and logging for all of these.
for k, fn in pairs(M) do
- M[k] = function(err, method, params, client_id)
- local _ = log.debug() and log.debug('default_callback', method, { params = params, client_id = client_id, err = err })
+ M[k] = function(err, method, params, client_id, bufnr)
+ log.debug('default_callback', method, { params = params, client_id = client_id, err = err, bufnr = bufnr })
if err then
error(tostring(err))
end
- return fn(err, method, params, client_id)
+ return fn(err, method, params, client_id, bufnr)
end
end
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index c0db5e5485..696ce43a59 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -17,14 +17,14 @@ log.levels = {
-- Default log level is warn.
local current_log_level = log.levels.WARN
-local log_date_format = "%FT%H:%M:%SZ%z"
+local log_date_format = "%FT%H:%M:%S%z"
do
local path_sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/"
local function path_join(...)
return table.concat(vim.tbl_flatten{...}, path_sep)
end
- local logfilename = path_join(vim.fn.stdpath('data'), 'vim-lsp.log')
+ local logfilename = path_join(vim.fn.stdpath('data'), 'lsp.log')
--- Return the log filename.
function log.get_filename()
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 76817e3a4a..877d11411b 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -620,6 +620,15 @@ function protocol.make_client_capabilities()
-- Send textDocument/didSave after saving (BufWritePost)
didSave = true;
};
+ codeAction = {
+ dynamicRegistration = false;
+
+ codeActionLiteralSupport = {
+ codeActionKind = {
+ valueSet = {};
+ };
+ };
+ };
completion = {
dynamicRegistration = false;
completionItem = {
@@ -703,6 +712,7 @@ function protocol.make_client_capabilities()
};
hierarchicalWorkspaceSymbolSupport = true;
};
+ applyEdit = true;
};
experimental = nil;
}
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 494eebf9ea..5c6d183ac1 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -94,18 +94,45 @@ local edit_sort_key = sort_by_key(function(e)
return {e.A[1], e.A[2], e.i}
end)
+local function get_line_byte_from_line_character(bufnr, lnum, cnum)
+ -- Skip check when the byte and character position is the same
+ if cnum > 0 then
+ local lines = api.nvim_buf_get_lines(bufnr, lnum, lnum+1, false)
+
+ if #lines > 0 then
+ return vim.str_byteindex(lines[1], cnum)
+ end
+ end
+
+ return cnum
+end
+
function M.apply_text_edits(text_edits, bufnr)
if not next(text_edits) then return end
+ if not api.nvim_buf_is_loaded(bufnr) then
+ vim.fn.bufload(bufnr)
+ end
local start_line, finish_line = math.huge, -1
local cleaned = {}
for i, e in ipairs(text_edits) do
+ -- adjust start and end column for UTF-16 encoding of non-ASCII characters
+ local start_row = e.range.start.line
+ local start_col = get_line_byte_from_line_character(
+ bufnr,
+ start_row,
+ e.range.start.character)
+ local end_row = e.range["end"].line
+ local end_col = get_line_byte_from_line_character(
+ bufnr,
+ end_row,
+ e.range["end"].character)
start_line = math.min(e.range.start.line, start_line)
finish_line = math.max(e.range["end"].line, finish_line)
-- TODO(ashkan) sanity check ranges for overlap.
table.insert(cleaned, {
i = i;
- A = {e.range.start.line; e.range.start.character};
- B = {e.range["end"].line; e.range["end"].character};
+ A = {start_row; start_col};
+ B = {end_row; end_col};
lines = vim.split(e.newText, '\n', true);
})
end
@@ -113,9 +140,6 @@ function M.apply_text_edits(text_edits, bufnr)
-- Reverse sort the orders so we can apply them without interfering with
-- eachother. Also add i as a sort key to mimic a stable sort.
table.sort(cleaned, edit_sort_key)
- if not api.nvim_buf_is_loaded(bufnr) then
- vim.fn.bufload(bufnr)
- end
local lines = api.nvim_buf_get_lines(bufnr, start_line, finish_line + 1, false)
local fix_eol = api.nvim_buf_get_option(bufnr, 'fixeol')
local set_eol = fix_eol and api.nvim_buf_line_count(bufnr) <= finish_line + 1
@@ -159,10 +183,12 @@ end
function M.apply_text_document_edit(text_document_edit)
local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri)
- -- `VersionedTextDocumentIdentifier`s version may be nil https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
- if text_document.version ~= vim.NIL and M.buf_versions[bufnr] > text_document.version then
- print("Buffer ", text_document.uri, " newer than edits.")
- return
+ if text_document.version then
+ -- `VersionedTextDocumentIdentifier`s version may be null https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
+ if text_document.version ~= vim.NIL and M.buf_versions[bufnr] ~= nil and M.buf_versions[bufnr] > text_document.version then
+ print("Buffer ", text_document.uri, " newer than edits.")
+ return
+ end
end
M.apply_text_edits(text_document_edit.edits, bufnr)
end
@@ -203,6 +229,13 @@ local function remove_unmatch_completion_items(items, prefix)
end, items)
end
+-- Acording to LSP spec, if the client set "completionItemKind.valueSet",
+-- the client must handle it properly even if it receives a value outside the specification.
+-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+function M._get_completion_item_kind_name(completion_item_kind)
+ return protocol.CompletionItemKind[completion_item_kind] or "Unknown"
+end
+
--- Getting vim complete-items with incomplete flag.
-- @params CompletionItem[], CompletionList or nil (https://microsoft.github.io/language-server-protocol/specification#textDocument_completion)
-- @return { matches = complete-items table, incomplete = boolean }
@@ -234,7 +267,7 @@ function M.text_document_completion_list_to_complete_items(result, prefix)
table.insert(matches, {
word = word,
abbr = completion_item.label,
- kind = protocol.CompletionItemKind[completion_item.kind] or '',
+ kind = M._get_completion_item_kind_name(completion_item.kind),
menu = completion_item.detail or '',
info = info,
icase = 1,
@@ -436,8 +469,9 @@ function M.jump_to_location(location)
local items = {{tagname=vim.fn.expand('<cword>'), from=from}}
vim.fn.settagstack(vim.fn.win_getid(), {items=items}, 't')
- --- Jump to new location
+ --- Jump to new location (adjusting for UTF-16 encoding of characters)
api.nvim_set_current_buf(bufnr)
+ api.nvim_buf_set_option(0, 'buflisted', true)
local range = location.range or location.targetSelectionRange
local row = range.start.line
local col = range.start.character
@@ -701,20 +735,29 @@ do
return severity_highlights[severity]
end
- function M.show_line_diagnostics()
+ function M.get_line_diagnostics()
local bufnr = api.nvim_get_current_buf()
- local line = api.nvim_win_get_cursor(0)[1] - 1
+ local linenr = api.nvim_win_get_cursor(0)[1] - 1
+
+ local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
+
+ if not buffer_diagnostics then
+ return {}
+ end
+
+ local diagnostics_by_line = M.diagnostics_group_by_line(buffer_diagnostics)
+ return diagnostics_by_line[linenr] or {}
+ end
+
+ function M.show_line_diagnostics()
-- local marks = api.nvim_buf_get_extmarks(bufnr, diagnostic_ns, {line, 0}, {line, -1}, {})
-- if #marks == 0 then
-- return
-- end
local lines = {"Diagnostics:"}
local highlights = {{0, "Bold"}}
-
- local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
- if not buffer_diagnostics then return end
- local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics)[line]
- if not line_diagnostics then return end
+ local line_diagnostics = M.get_line_diagnostics()
+ if vim.tbl_isempty(line_diagnostics) then return end
for i, diagnostic in ipairs(line_diagnostics) do
-- for i, mark in ipairs(marks) do
@@ -934,6 +977,13 @@ function M.set_qflist(items)
})
end
+-- Acording to LSP spec, if the client set "symbolKind.valueSet",
+-- the client must handle it properly even if it receives a value outside the specification.
+-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
+function M._get_symbol_kind_name(symbol_kind)
+ return protocol.SymbolKind[symbol_kind] or "Unknown"
+end
+
--- Convert symbols to quickfix list items
---
--@symbols DocumentSymbol[] or SymbolInformation[]
@@ -942,7 +992,7 @@ function M.symbols_to_items(symbols, bufnr)
for _, symbol in ipairs(_symbols) do
if symbol.location then -- SymbolInformation type
local range = symbol.location.range
- local kind = protocol.SymbolKind[symbol.kind]
+ local kind = M._get_symbol_kind_name(symbol.kind)
table.insert(_items, {
filename = vim.uri_to_fname(symbol.location.uri),
lnum = range.start.line + 1,
@@ -951,7 +1001,7 @@ function M.symbols_to_items(symbols, bufnr)
text = '['..kind..'] '..symbol.name,
})
elseif symbol.range then -- DocumentSymbole type
- local kind = protocol.SymbolKind[symbol.kind]
+ local kind = M._get_symbol_kind_name(symbol.kind)
table.insert(_items, {
-- bufnr = _bufnr,
filename = vim.api.nvim_buf_get_name(_bufnr),
@@ -1018,14 +1068,26 @@ function M.try_trim_markdown_code_blocks(lines)
end
local str_utfindex = vim.str_utfindex
-function M.make_position_params()
+local function make_position_param()
local row, col = unpack(api.nvim_win_get_cursor(0))
row = row - 1
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
col = str_utfindex(line, col)
+ return { line = row; character = col; }
+end
+
+function M.make_position_params()
return {
textDocument = M.make_text_document_params();
- position = { line = row; character = col; }
+ position = make_position_param()
+ }
+end
+
+function M.make_range_params()
+ local position = make_position_param()
+ return {
+ textDocument = { uri = vim.uri_from_bufnr(0) },
+ range = { start = position; ["end"] = position; }
}
end
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index d18fcfaf95..2135bfc837 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -200,16 +200,7 @@ function vim.tbl_isempty(t)
return next(t) == nil
end
---- Merges two or more map-like tables.
----
---@see |extend()|
----
---@param behavior Decides what to do if a key is found in more than one map:
---- - "error": raise an error
---- - "keep": use value from the leftmost map
---- - "force": use value from the rightmost map
---@param ... Two or more map-like tables.
-function vim.tbl_extend(behavior, ...)
+local function tbl_extend(behavior, deep_extend, ...)
if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then
error('invalid "behavior": '..tostring(behavior))
end
@@ -228,7 +219,9 @@ function vim.tbl_extend(behavior, ...)
vim.validate{["after the second argument"] = {tbl,'t'}}
if tbl then
for k, v in pairs(tbl) do
- if behavior ~= 'force' and ret[k] ~= nil then
+ if type(v) == 'table' and deep_extend and not vim.tbl_islist(v) then
+ ret[k] = tbl_extend(behavior, true, ret[k] or vim.empty_dict(), v)
+ elseif behavior ~= 'force' and ret[k] ~= nil then
if behavior == 'error' then
error('key found in more than one map: '..k)
end -- Else behavior is "keep".
@@ -241,6 +234,32 @@ function vim.tbl_extend(behavior, ...)
return ret
end
+--- Merges two or more map-like tables.
+---
+--@see |extend()|
+---
+--@param behavior Decides what to do if a key is found in more than one map:
+--- - "error": raise an error
+--- - "keep": use value from the leftmost map
+--- - "force": use value from the rightmost map
+--@param ... Two or more map-like tables.
+function vim.tbl_extend(behavior, ...)
+ return tbl_extend(behavior, false, ...)
+end
+
+--- Merges recursively two or more map-like tables.
+---
+--@see |tbl_extend()|
+---
+--@param behavior Decides what to do if a key is found in more than one map:
+--- - "error": raise an error
+--- - "keep": use value from the leftmost map
+--- - "force": use value from the rightmost map
+--@param ... Two or more map-like tables.
+function vim.tbl_deep_extend(behavior, ...)
+ return tbl_extend(behavior, true, ...)
+end
+
--- Deep compare values for equality
function vim.deep_equal(a, b)
if a == b then return true end
diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua
index e28cc9e20f..9c3535c676 100644
--- a/runtime/lua/vim/uri.lua
+++ b/runtime/lua/vim/uri.lua
@@ -65,9 +65,11 @@ local function uri_from_fname(path)
return table.concat(uri_parts)
end
+local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*'
+
local function uri_from_bufnr(bufnr)
local fname = vim.api.nvim_buf_get_name(bufnr)
- local scheme = fname:match("^([a-z]+)://.*")
+ local scheme = fname:match(URI_SCHEME_PATTERN)
if scheme then
return fname
else
@@ -76,6 +78,10 @@ local function uri_from_bufnr(bufnr)
end
local function uri_to_fname(uri)
+ local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri)
+ if scheme ~= 'file' then
+ return uri
+ end
uri = uri_decode(uri)
-- TODO improve this.
if is_windows_file_uri(uri) then
@@ -89,7 +95,7 @@ end
-- Return or create a buffer for a uri.
local function uri_to_bufnr(uri)
- local scheme = assert(uri:match("^([a-z]+)://.*"), 'Uri must contain a scheme: ' .. uri)
+ local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri)
if scheme == 'file' then
return vim.fn.bufadd(uri_to_fname(uri))
else
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index aa2b69ad97..28dc3256c7 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -645,7 +645,7 @@ func s:InstallCommands()
command Gdb call win_gotoid(s:gdbwin)
command Program call win_gotoid(s:ptywin)
command Source call s:GotoSourcewinOrCreateIt()
- " command Winbar call s:InstallWinbar()
+ command Winbar call s:InstallWinbar()
" TODO: can the K mapping be restored?
nnoremap K :Evaluate<CR>
@@ -655,6 +655,19 @@ endfunc
" let s:winbar_winids = []
+" Install the window toolbar in the current window.
+func s:InstallWinbar()
+ " if has('menu') && &mouse != ''
+ " nnoremenu WinBar.Step :Step<CR>
+ " nnoremenu WinBar.Next :Over<CR>
+ " nnoremenu WinBar.Finish :Finish<CR>
+ " nnoremenu WinBar.Cont :Continue<CR>
+ " nnoremenu WinBar.Stop :Stop<CR>
+ " nnoremenu WinBar.Eval :Evaluate<CR>
+ " call add(s:winbar_winids, win_getid(winnr()))
+ " endif
+endfunc
+
" Delete installed debugger commands in the current window.
func s:DeleteCommands()
delcommand Break
@@ -670,7 +683,7 @@ func s:DeleteCommands()
delcommand Gdb
delcommand Program
delcommand Source
- " delcommand Winbar
+ delcommand Winbar
nunmap K
@@ -940,7 +953,7 @@ func s:GotoSourcewinOrCreateIt()
if !win_gotoid(s:sourcewin)
new
let s:sourcewin = win_getid(winnr())
- " call s:InstallWinbar()
+ call s:InstallWinbar()
endif
endfunc
@@ -971,7 +984,7 @@ func s:HandleCursor(msg)
" TODO: find existing window
exe 'split ' . fnameescape(fname)
let s:sourcewin = win_getid(winnr())
- " call s:InstallWinbar()
+ call s:InstallWinbar()
else
exe 'edit ' . fnameescape(fname)
endif
diff --git a/runtime/syntax/tutor.vim b/runtime/syntax/tutor.vim
index 6305eef734..83ca547fdd 100644
--- a/runtime/syntax/tutor.vim
+++ b/runtime/syntax/tutor.vim
@@ -33,16 +33,16 @@ syn keyword tutorMarks Todo Note Tip Excersise
syn region tutorCodeblock matchgroup=Delimiter start=/^\~\{3}.*$/ end=/^\~\{3}/
-syn region tutorShell matchgroup=Delimiter start=/^\~\{3} sh\s*$/ end=/^\~\{3}/ keepend contains=@TUTORSHELL
+syn region tutorShell matchgroup=Delimiter start=/^\~\{3} sh\s*$/ end=/^\~\{3}/ keepend contains=@TUTORSHELL concealends
syn match tutorShellPrompt /\(^\s*\)\@<=[$#]/ contained containedin=tutorShell
-syn region tutorInlineCode matchgroup=Delimiter start=/\\\@<!`/ end=/\\\@<!\(`{\@!\|`\s\)/
+syn region tutorInlineCode matchgroup=Delimiter start=/\\\@<!`/ end=/\\\@<!\(`{\@!\|`\s\)/ concealends
-syn region tutorCommand matchgroup=Delimiter start=/^\~\{3} cmd\( :\)\?\s*$/ end=/^\~\{3}/ keepend contains=@VIM
-syn region tutorInlineCommand matchgroup=Delimiter start=/\\\@<!`\(.*{vim}\)\@=/ end=/\\\@<!`\({vim}\)\@=/ nextgroup=tutorInlineType contains=@VIM
+syn region tutorCommand matchgroup=Delimiter start=/^\~\{3} cmd\( :\)\?\s*$/ end=/^\~\{3}/ keepend contains=@VIM concealends
+syn region tutorInlineCommand matchgroup=Delimiter start=/\\\@<!`\(.*`{vim}\)\@=/ end=/\\\@<!`\({vim}\)\@=/ nextgroup=tutorInlineType contains=@VIM concealends keepend
-syn region tutorNormal matchgroup=Delimiter start=/^\~\{3} norm\(al\?\)\?\s*$/ end=/^\~\{3}/ contains=@VIMNORMAL
-syn region tutorInlineNormal matchgroup=Delimiter start=/\\\@<!`\(\S*{normal}\)\@=/ end=/\\\@<!`\({normal}\)\@=/ nextgroup=tutorInlineType contains=@VIMNORMAL
+syn region tutorNormal matchgroup=Delimiter start=/^\~\{3} norm\(al\?\)\?\s*$/ end=/^\~\{3}/ contains=@VIMNORMAL concealends
+syn region tutorInlineNormal matchgroup=Delimiter start=/\\\@<!`\(\S*`{normal}\)\@=/ end=/\\\@<!`\({normal}\)\@=/ nextgroup=tutorInlineType contains=@VIMNORMAL concealends keepend
syn match tutorInlineType /{\(normal\|vim\)}/ contained conceal