aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /runtime/lua/vim
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/_comment.lua15
-rw-r--r--runtime/lua/vim/_defaults.lua264
-rw-r--r--runtime/lua/vim/_editor.lua106
-rw-r--r--runtime/lua/vim/_inspector.lua4
-rw-r--r--runtime/lua/vim/_meta.lua2
-rw-r--r--runtime/lua/vim/_meta/api.lua2290
-rw-r--r--runtime/lua/vim/_meta/api_keysets.lua3
-rw-r--r--runtime/lua/vim/_meta/api_keysets_extra.lua29
-rw-r--r--runtime/lua/vim/_meta/builtin.lua9
-rw-r--r--runtime/lua/vim/_meta/builtin_types.lua73
-rw-r--r--runtime/lua/vim/_meta/diff.lua26
-rw-r--r--runtime/lua/vim/_meta/lpeg.lua41
-rw-r--r--runtime/lua/vim/_meta/options.lua195
-rw-r--r--runtime/lua/vim/_meta/regex.lua26
-rw-r--r--runtime/lua/vim/_meta/spell.lua2
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua1075
-rw-r--r--runtime/lua/vim/_options.lua12
-rw-r--r--runtime/lua/vim/_watch.lua88
-rw-r--r--runtime/lua/vim/deprecated/health.lua2
-rw-r--r--runtime/lua/vim/diagnostic.lua266
-rw-r--r--runtime/lua/vim/filetype.lua1405
-rw-r--r--runtime/lua/vim/filetype/detect.lua127
-rw-r--r--runtime/lua/vim/fs.lua84
-rw-r--r--runtime/lua/vim/glob.lua30
-rw-r--r--runtime/lua/vim/health.lua137
-rw-r--r--runtime/lua/vim/health/health.lua17
-rw-r--r--runtime/lua/vim/highlight.lua86
-rw-r--r--runtime/lua/vim/iter.lua12
-rw-r--r--runtime/lua/vim/keymap.lua22
-rw-r--r--runtime/lua/vim/loader.lua20
-rw-r--r--runtime/lua/vim/lsp.lua113
-rw-r--r--runtime/lua/vim/lsp/_completion.lua276
-rw-r--r--runtime/lua/vim/lsp/_dynamic.lua4
-rw-r--r--runtime/lua/vim/lsp/_meta/protocol.lua1556
-rw-r--r--runtime/lua/vim/lsp/_watchfiles.lua4
-rw-r--r--runtime/lua/vim/lsp/buf.lua71
-rw-r--r--runtime/lua/vim/lsp/client.lua53
-rw-r--r--runtime/lua/vim/lsp/codelens.lua8
-rw-r--r--runtime/lua/vim/lsp/completion.lua754
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua33
-rw-r--r--runtime/lua/vim/lsp/handlers.lua3
-rw-r--r--runtime/lua/vim/lsp/health.lua92
-rw-r--r--runtime/lua/vim/lsp/inlay_hint.lua41
-rw-r--r--runtime/lua/vim/lsp/log.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua382
-rw-r--r--runtime/lua/vim/lsp/rpc.lua16
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua16
-rw-r--r--runtime/lua/vim/lsp/sync.lua13
-rw-r--r--runtime/lua/vim/lsp/util.lua218
-rw-r--r--runtime/lua/vim/provider/health.lua259
-rw-r--r--runtime/lua/vim/secure.lua2
-rw-r--r--runtime/lua/vim/shared.lua297
-rw-r--r--runtime/lua/vim/snippet.lua80
-rw-r--r--runtime/lua/vim/text.lua15
-rw-r--r--runtime/lua/vim/treesitter.lua64
-rw-r--r--runtime/lua/vim/treesitter/_fold.lua36
-rw-r--r--runtime/lua/vim/treesitter/_meta.lua113
-rw-r--r--runtime/lua/vim/treesitter/_meta/misc.lua78
-rw-r--r--runtime/lua/vim/treesitter/_meta/tsnode.lua185
-rw-r--r--runtime/lua/vim/treesitter/_meta/tstree.lua44
-rw-r--r--runtime/lua/vim/treesitter/_query_linter.lua21
-rw-r--r--runtime/lua/vim/treesitter/_range.lua4
-rw-r--r--runtime/lua/vim/treesitter/dev.lua72
-rw-r--r--runtime/lua/vim/treesitter/health.lua3
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua15
-rw-r--r--runtime/lua/vim/treesitter/language.lua64
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua44
-rw-r--r--runtime/lua/vim/treesitter/query.lua43
-rw-r--r--runtime/lua/vim/ui.lua94
-rw-r--r--runtime/lua/vim/version.lua14
-rw-r--r--runtime/lua/vim/vimhelp.lua38
71 files changed, 7198 insertions, 4512 deletions
diff --git a/runtime/lua/vim/_comment.lua b/runtime/lua/vim/_comment.lua
index 044cd69716..de7f62632c 100644
--- a/runtime/lua/vim/_comment.lua
+++ b/runtime/lua/vim/_comment.lua
@@ -9,8 +9,8 @@
local function get_commentstring(ref_position)
local buf_cs = vim.bo.commentstring
- local has_ts_parser, ts_parser = pcall(vim.treesitter.get_parser)
- if not has_ts_parser then
+ local ts_parser = vim.treesitter.get_parser(0, '', { error = false })
+ if not ts_parser then
return buf_cs
end
@@ -194,14 +194,9 @@ local function toggle_lines(line_start, line_end, ref_position)
-- - Debatable for highlighting in text area (like LSP semantic tokens).
-- Mostly because it causes flicker as highlighting is preserved during
-- comment toggling.
- package.loaded['vim._comment']._lines = vim.tbl_map(f, lines)
- local lua_cmd = string.format(
- 'vim.api.nvim_buf_set_lines(0, %d, %d, false, package.loaded["vim._comment"]._lines)',
- line_start - 1,
- line_end
- )
- vim.cmd.lua({ lua_cmd, mods = { lockmarks = true } })
- package.loaded['vim._comment']._lines = nil
+ vim._with({ lockmarks = true }, function()
+ vim.api.nvim_buf_set_lines(0, line_start - 1, line_end, false, vim.tbl_map(f, lines))
+ end)
end
--- Operator which toggles user-supplied range of lines
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 5b964b84a0..6cad1dbca9 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -85,13 +85,13 @@ do
vim.keymap.set(
'x',
'Q',
- "mode() == 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
+ "mode() ==# 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
{ silent = true, expr = true, desc = ':help v_Q-default' }
)
vim.keymap.set(
'x',
'@',
- "mode() == 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
+ "mode() ==# 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
{ silent = true, expr = true, desc = ':help v_@-default' }
)
@@ -113,9 +113,11 @@ do
local gx_desc =
'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)'
vim.keymap.set({ 'n' }, 'gx', function()
- local err = do_open(require('vim.ui')._get_url())
- if err then
- vim.notify(err, vim.log.levels.ERROR)
+ for _, url in ipairs(require('vim.ui')._get_urls()) do
+ local err = do_open(url)
+ if err then
+ vim.notify(err, vim.log.levels.ERROR)
+ end
end
end, { desc = gx_desc })
vim.keymap.set({ 'x' }, 'gx', function()
@@ -180,12 +182,20 @@ do
--- See |[d-default|, |]d-default|, and |CTRL-W_d-default|.
do
vim.keymap.set('n', ']d', function()
- vim.diagnostic.goto_next({ float = false })
- end, { desc = 'Jump to the next diagnostic' })
+ vim.diagnostic.jump({ count = vim.v.count1 })
+ end, { desc = 'Jump to the next diagnostic in the current buffer' })
vim.keymap.set('n', '[d', function()
- vim.diagnostic.goto_prev({ float = false })
- end, { desc = 'Jump to the previous diagnostic' })
+ vim.diagnostic.jump({ count = -vim.v.count1 })
+ end, { desc = 'Jump to the previous diagnostic in the current buffer' })
+
+ vim.keymap.set('n', ']D', function()
+ vim.diagnostic.jump({ count = math.huge, wrap = false })
+ end, { desc = 'Jump to the last diagnostic in the current buffer' })
+
+ vim.keymap.set('n', '[D', function()
+ vim.diagnostic.jump({ count = -math.huge, wrap = false })
+ end, { desc = 'Jump to the first diagnostic in the current buffer' })
vim.keymap.set('n', '<C-W>d', function()
vim.diagnostic.open_float()
@@ -198,13 +208,187 @@ do
{ remap = true, desc = 'Show diagnostics under the cursor' }
)
end
+
+ --- vim-unimpaired style mappings. See: https://github.com/tpope/vim-unimpaired
+ do
+ -- Quickfix mappings
+ vim.keymap.set('n', '[q', function()
+ vim.cmd.cprevious({ count = vim.v.count1 })
+ end, {
+ desc = ':cprevious',
+ })
+
+ vim.keymap.set('n', ']q', function()
+ vim.cmd.cnext({ count = vim.v.count1 })
+ end, {
+ desc = ':cnext',
+ })
+
+ vim.keymap.set('n', '[Q', function()
+ vim.cmd.crewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':crewind',
+ })
+
+ vim.keymap.set('n', ']Q', function()
+ vim.cmd.clast({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':clast',
+ })
+
+ vim.keymap.set('n', '[<C-Q>', function()
+ vim.cmd.cpfile({ count = vim.v.count1 })
+ end, {
+ desc = ':cpfile',
+ })
+
+ vim.keymap.set('n', ']<C-Q>', function()
+ vim.cmd.cnfile({ count = vim.v.count1 })
+ end, {
+ desc = ':cnfile',
+ })
+
+ -- Location list mappings
+ vim.keymap.set('n', '[l', function()
+ vim.cmd.lprevious({ count = vim.v.count1 })
+ end, {
+ desc = ':lprevious',
+ })
+
+ vim.keymap.set('n', ']l', function()
+ vim.cmd.lnext({ count = vim.v.count1 })
+ end, {
+ desc = ':lnext',
+ })
+
+ vim.keymap.set('n', '[L', function()
+ vim.cmd.lrewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':lrewind',
+ })
+
+ vim.keymap.set('n', ']L', function()
+ vim.cmd.llast({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':llast',
+ })
+
+ vim.keymap.set('n', '[<C-L>', function()
+ vim.cmd.lpfile({ count = vim.v.count1 })
+ end, {
+ desc = ':lpfile',
+ })
+
+ vim.keymap.set('n', ']<C-L>', function()
+ vim.cmd.lnfile({ count = vim.v.count1 })
+ end, {
+ desc = ':lnfile',
+ })
+
+ -- Argument list
+ vim.keymap.set('n', '[a', function()
+ vim.cmd.previous({ count = vim.v.count1 })
+ end, {
+ desc = ':previous',
+ })
+
+ vim.keymap.set('n', ']a', function()
+ -- count doesn't work with :next, must use range. See #30641.
+ vim.cmd.next({ range = { vim.v.count1 } })
+ end, {
+ desc = ':next',
+ })
+
+ vim.keymap.set('n', '[A', function()
+ if vim.v.count ~= 0 then
+ vim.cmd.argument({ count = vim.v.count })
+ else
+ vim.cmd.rewind()
+ end
+ end, {
+ desc = ':rewind',
+ })
+
+ vim.keymap.set('n', ']A', function()
+ if vim.v.count ~= 0 then
+ vim.cmd.argument({ count = vim.v.count })
+ else
+ vim.cmd.last()
+ end
+ end, {
+ desc = ':last',
+ })
+
+ -- Tags
+ vim.keymap.set('n', '[t', function()
+ -- count doesn't work with :tprevious, must use range. See #30641.
+ vim.cmd.tprevious({ range = { vim.v.count1 } })
+ end, { desc = ':tprevious' })
+
+ vim.keymap.set('n', ']t', function()
+ -- count doesn't work with :tnext, must use range. See #30641.
+ vim.cmd.tnext({ range = { vim.v.count1 } })
+ end, { desc = ':tnext' })
+
+ vim.keymap.set('n', '[T', function()
+ -- count doesn't work with :trewind, must use range. See #30641.
+ vim.cmd.trewind({ range = vim.v.count ~= 0 and { vim.v.count } or nil })
+ end, { desc = ':trewind' })
+
+ vim.keymap.set('n', ']T', function()
+ -- :tlast does not accept a count, so use :trewind if count given
+ if vim.v.count ~= 0 then
+ vim.cmd.trewind({ range = { vim.v.count } })
+ else
+ vim.cmd.tlast()
+ end
+ end, { desc = ':tlast' })
+
+ vim.keymap.set('n', '[<C-T>', function()
+ -- count doesn't work with :ptprevious, must use range. See #30641.
+ vim.cmd.ptprevious({ range = { vim.v.count1 } })
+ end, { desc = ' :ptprevious' })
+
+ vim.keymap.set('n', ']<C-T>', function()
+ -- count doesn't work with :ptnext, must use range. See #30641.
+ vim.cmd.ptnext({ range = { vim.v.count1 } })
+ end, { desc = ':ptnext' })
+
+ -- Buffers
+ vim.keymap.set('n', '[b', function()
+ vim.cmd.bprevious({ count = vim.v.count1 })
+ end, { desc = ':bprevious' })
+
+ vim.keymap.set('n', ']b', function()
+ vim.cmd.bnext({ count = vim.v.count1 })
+ end, { desc = ':bnext' })
+
+ vim.keymap.set('n', '[B', function()
+ if vim.v.count ~= 0 then
+ vim.cmd.buffer({ count = vim.v.count })
+ else
+ vim.cmd.brewind()
+ end
+ end, { desc = ':brewind' })
+
+ vim.keymap.set('n', ']B', function()
+ if vim.v.count ~= 0 then
+ vim.cmd.buffer({ count = vim.v.count })
+ else
+ vim.cmd.blast()
+ end
+ end, { desc = ':blast' })
+ end
end
--- Default menus
do
--- Right click popup menu
- -- TODO VimScript, no l10n
vim.cmd([[
+ anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR>
+ amenu PopUp.Open\ in\ web\ browser gx
+ anoremenu PopUp.Inspect <Cmd>Inspect<CR>
+ anoremenu PopUp.-1- <Nop>
vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y
anoremenu PopUp.Paste "+gP
@@ -213,10 +397,36 @@ do
nnoremenu PopUp.Select\ All ggVG
vnoremenu PopUp.Select\ All gg0oG$
inoremenu PopUp.Select\ All <C-Home><C-O>VG
- anoremenu PopUp.Inspect <Cmd>Inspect<CR>
- anoremenu PopUp.-1- <Nop>
+ anoremenu PopUp.-2- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
]])
+
+ local function enable_ctx_menu(ctx)
+ vim.cmd([[
+ amenu disable PopUp.Go\ to\ definition
+ amenu disable PopUp.Open\ in\ web\ browser
+ ]])
+
+ if ctx == 'url' then
+ vim.cmd([[amenu enable PopUp.Open\ in\ web\ browser]])
+ elseif ctx == 'lsp' then
+ vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]])
+ end
+ end
+
+ local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim_popupmenu', {})
+ vim.api.nvim_create_autocmd('MenuPopup', {
+ pattern = '*',
+ group = nvim_popupmenu_augroup,
+ desc = 'Mouse popup menu',
+ -- nested = true,
+ callback = function()
+ local urls = require('vim.ui')._get_urls()
+ local url = vim.startswith(urls[1], 'http')
+ local ctx = url and 'url' or (vim.lsp.get_clients({ bufnr = 0 })[1] and 'lsp' or nil)
+ enable_ctx_menu(ctx)
+ end,
+ })
end
--- Default autocommands. See |default-autocmds|
@@ -274,6 +484,26 @@ do
end,
})
+ vim.api.nvim_create_autocmd('TermOpen', {
+ group = nvim_terminal_augroup,
+ desc = 'Default settings for :terminal buffers',
+ callback = function()
+ vim.bo.modifiable = false
+ vim.bo.undolevels = -1
+ vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback)
+ vim.bo.textwidth = 0
+ vim.wo[0][0].wrap = false
+ vim.wo[0][0].list = false
+
+ -- This is gross. Proper list options support when?
+ local winhl = vim.o.winhighlight
+ if winhl ~= '' then
+ winhl = winhl .. ','
+ end
+ vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC'
+ end,
+ })
+
vim.api.nvim_create_autocmd('CmdwinEnter', {
pattern = '[:>]',
desc = 'Limit syntax sync to maxlines=1 in the command window',
@@ -462,10 +692,14 @@ do
--- response indicates that it does support truecolor enable 'termguicolors',
--- but only if the user has not already disabled it.
do
- if tty.rgb then
- -- The TUI was able to determine truecolor support
+ local colorterm = os.getenv('COLORTERM')
+ if tty.rgb or colorterm == 'truecolor' or colorterm == '24bit' then
+ -- The TUI was able to determine truecolor support or $COLORTERM explicitly indicates
+ -- truecolor support
setoption('termguicolors', true)
- else
+ elseif colorterm == nil or colorterm == '' then
+ -- Neither the TUI nor $COLORTERM indicate that truecolor is supported, so query the
+ -- terminal
local caps = {} ---@type table<string, boolean>
require('vim.termcap').query({ 'Tc', 'RGB', 'setrgbf', 'setrgbb' }, function(cap, found)
if not found then
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 5e9be509c8..2e829578a7 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -1,17 +1,19 @@
-- Nvim-Lua stdlib: the `vim` module (:help lua-stdlib)
--
--- Lua code lives in one of three places:
--- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the
--- `inspect` and `lpeg` modules.
--- 2. runtime/lua/vim/shared.lua: pure Lua functions which always
--- are available. Used in the test runner, as well as worker threads
--- and processes launched from Nvim.
--- 3. runtime/lua/vim/_editor.lua: Code which directly interacts with
--- the Nvim editor state. Only available in the main thread.
+-- Lua code lives in one of four places:
+-- 1. Plugins! Not everything needs to live on "vim.*". Plugins are the correct model for
+-- non-essential features which the user may want to disable or replace with a third-party
+-- plugin. Examples: "editorconfig", "comment".
+-- - "opt-out": runtime/plugin/*.lua
+-- - "opt-in": runtime/pack/dist/opt/
+-- 2. runtime/lua/vim/ (the runtime): Lazy-loaded modules. Examples: `inspect`, `lpeg`.
+-- 3. runtime/lua/vim/shared.lua: pure Lua functions which always are available. Used in the test
+-- runner, as well as worker threads and processes launched from Nvim.
+-- 4. runtime/lua/vim/_editor.lua: Eager-loaded code which directly interacts with the Nvim
+-- editor state. Only available in the main thread.
--
--- Guideline: "If in doubt, put it in the runtime".
---
--- Most functions should live directly in `vim.`, not in submodules.
+-- The top level "vim.*" namespace is for fundamental Lua and editor features. Use submodules for
+-- everything else (but avoid excessive "nesting"), or plugins (see above).
--
-- Compatibility with Vim's `if_lua` is explicitly a non-goal.
--
@@ -19,9 +21,7 @@
-- - https://github.com/luafun/luafun
-- - https://github.com/rxi/lume
-- - http://leafo.net/lapis/reference/utilities.html
--- - https://github.com/torch/paths
-- - https://github.com/bakpakin/Fennel (pretty print, repl)
--- - https://github.com/howl-editor/howl/tree/master/lib/howl/util
-- These are for loading runtime modules lazily since they aren't available in
-- the nvim binary as specified in executor.c
@@ -208,8 +208,10 @@ vim.inspect = vim.inspect
do
local tdots, tick, got_line1, undo_started, trailing_nl = 0, 0, false, false, false
- --- Paste handler, invoked by |nvim_paste()| when a conforming UI
- --- (such as the |TUI|) pastes text into the editor.
+ --- Paste handler, invoked by |nvim_paste()|.
+ ---
+ --- Note: This is provided only as a "hook", don't call it directly; call |nvim_paste()| instead,
+ --- which arranges redo (dot-repeat) and invokes `vim.paste`.
---
--- Example: To remove ANSI color codes when pasting:
---
@@ -220,7 +222,7 @@ do
--- -- Scrub ANSI color codes from paste input.
--- lines[i] = line:gsub('\27%[[0-9;mK]+', '')
--- end
- --- overridden(lines, phase)
+ --- return overridden(lines, phase)
--- end
--- end)(vim.paste)
--- ```
@@ -494,6 +496,7 @@ do
vim.t = make_dict_accessor('t')
end
+--- @deprecated
--- Gets a dict of line segment ("chunk") positions for the region from `pos1` to `pos2`.
---
--- Input and output positions are byte positions, (0,0)-indexed. "End of line" column
@@ -507,6 +510,8 @@ end
---@return table region Dict of the form `{linenr = {startcol,endcol}}`. `endcol` is exclusive, and
---whole lines are returned as `{startcol,endcol} = {0,-1}`.
function vim.region(bufnr, pos1, pos2, regtype, inclusive)
+ vim.deprecate('vim.region', 'vim.fn.getregionpos()', '0.13')
+
if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr)
end
@@ -605,10 +610,9 @@ end
--- Displays a notification to the user.
---
---- This function can be overridden by plugins to display notifications using a
---- custom provider (such as the system notification provider). By default,
+--- This function can be overridden by plugins to display notifications using
+--- a custom provider (such as the system notification provider). By default,
--- writes to |:messages|.
----