aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/api.txt25
-rw-r--r--runtime/doc/deprecated.txt1
-rw-r--r--runtime/doc/lsp.txt3
-rw-r--r--runtime/doc/lua.txt11
-rw-r--r--runtime/doc/luvref.txt7
-rw-r--r--runtime/doc/news.txt7
-rw-r--r--runtime/doc/treesitter.txt68
-rw-r--r--runtime/lua/vim/diagnostic.lua12
-rw-r--r--runtime/lua/vim/filetype.lua1
-rw-r--r--runtime/lua/vim/fs.lua45
-rw-r--r--runtime/lua/vim/loader.lua197
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua54
-rw-r--r--runtime/lua/vim/lsp/protocol.lua2
-rw-r--r--runtime/lua/vim/lsp/types.lua17
-rw-r--r--runtime/lua/vim/shared.lua8
-rw-r--r--runtime/lua/vim/treesitter.lua33
-rw-r--r--runtime/lua/vim/treesitter/health.lua2
-rw-r--r--runtime/lua/vim/treesitter/language.lua61
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua7
-rw-r--r--runtime/queries/c/highlights.scm115
-rw-r--r--runtime/queries/c/injections.scm4
-rw-r--r--runtime/queries/lua/highlights.scm43
-rw-r--r--runtime/queries/lua/injections.scm12
-rw-r--r--runtime/queries/vim/highlights.scm2
-rw-r--r--runtime/queries/vimdoc/highlights.scm (renamed from runtime/queries/help/highlights.scm)0
-rw-r--r--runtime/queries/vimdoc/injections.scm (renamed from runtime/queries/help/injections.scm)0
26 files changed, 456 insertions, 281 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index cc887ad024..3c3e66dd57 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -941,6 +941,10 @@ nvim_get_hl({ns_id}, {*opts}) *nvim_get_hl()*
map as in |nvim_set_hl()|, or only a single highlight definition map
if requested by name or id.
+ Note:
+ When the `link` attribute is defined in the highlight definition map,
+ other attributes will not be taking effect (see |:hi-link|).
+
nvim_get_hl_id_by_name({name}) *nvim_get_hl_id_by_name()*
Gets a highlight group by name
@@ -1388,6 +1392,10 @@ nvim_set_hl({ns_id}, {name}, {*val}) *nvim_set_hl()*
values of the Normal group. If the Normal group has not been defined,
using these values results in an error.
+ Note:
+ If `link` is used in combination with other attributes; only the
+ `link` will take effect (see |:hi-link|).
+
Parameters: ~
• {ns_id} Namespace id for this highlight |nvim_create_namespace()|.
Use 0 to set a highlight group globally |:highlight|.
@@ -1912,7 +1920,7 @@ nvim_get_all_options_info() *nvim_get_all_options_info()*
Gets the option information for all options.
The dictionary has the full option names as keys and option metadata
- dictionaries as detailed at |nvim_get_option_info()|.
+ dictionaries as detailed at |nvim_get_option_info2()|.
Return: ~
dictionary of all options
@@ -1926,8 +1934,8 @@ nvim_get_option({name}) *nvim_get_option()*
Return: ~
Option value (global)
-nvim_get_option_info({name}) *nvim_get_option_info()*
- Gets the option information for one option
+nvim_get_option_info2({name}, {*opts}) *nvim_get_option_info2()*
+ Gets the option information for one option from arbitrary buffer or window
Resulting dictionary has keys:
• name: Name of the option (like 'filetype')
@@ -1943,8 +1951,19 @@ nvim_get_option_info({name}) *nvim_get_option_info()*
• commalist: List of comma separated values
• flaglist: List of single char flags
+ When {scope} is not provided, the last set information applies to the
+ local value in the current buffer or window if it is available, otherwise
+ the global value information is returned. This behavior can be disabled by
+ explicitly specifying {scope} in the {opts} table.
+
Parameters: ~
• {name} Option name
+ • {opts} Optional parameters
+ • scope: One of "global" or "local". Analogous to |:setglobal|
+ and |:setlocal|, respectively.
+ • win: |window-ID|. Used for getting window local options.
+ • buf: Buffer number. Used for getting buffer local options.
+ Implies {scope} is "local".
Return: ~
Option Information
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 69cec8da53..3eb2017bed 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -20,6 +20,7 @@ API
- *nvim_get_hl_by_name()* Use |nvim_get_hl()| instead.
- *nvim_get_hl_by_id()* Use |nvim_get_hl()| instead.
- *nvim_exec()* Use |nvim_exec2()| instead.
+- *nvim_get_option_info()* Use |nvim_get_option_info2()| instead.
COMMANDS
- *:rv* *:rviminfo* Deprecated alias to |:rshada| command.
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 0164b34efb..f5695669ae 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -1113,7 +1113,8 @@ code_action({options}) *vim.lsp.buf.code_action()*
• {options} (table|nil) Optional table which holds the following
optional fields:
• context: (table|nil) Corresponds to `CodeActionContext` of the LSP specification:
- • diagnostics (table|nil): LSP`Diagnostic[]` . Inferred from the current position if not provided.
+ • diagnostics (table|nil): LSP `Diagnostic[]`. Inferred
+ from the current position if not provided.
• only (table|nil): List of LSP `CodeActionKind`s used to
filter the code actions. Most language servers support
values like `refactor` or `quickfix`.
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 58522ac1f3..ebbf8bb463 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1635,8 +1635,8 @@ defaulttable({create}) *vim.defaulttable()*
<
Parameters: ~
- • {create} (function|nil) The function called to create a missing
- value.
+ • {create} function?(key:any):any The function called to create a
+ missing value.
Return: ~
(table) Empty table with metamethod
@@ -2065,7 +2065,7 @@ find({modname}, {opts}) *vim.loader.find()*
for `modname="*"`
reset({path}) *vim.loader.reset()*
- Resets the topmods cache for the path, or all the paths if path is nil.
+ Resets the cache for the path, or all the paths if path is nil.
Parameters: ~
• {path} string? path to reset
@@ -2502,7 +2502,7 @@ find({names}, {opts}) *vim.fs.find()*
(table) Normalized paths |vim.fs.normalize()| of all matching files or
directories
-normalize({path}) *vim.fs.normalize()*
+normalize({path}, {opts}) *vim.fs.normalize()*
Normalize a path to a standard format. A tilde (~) character at the
beginning of the path is expanded to the user's home directory and any
backslash (\) characters are converted to forward slashes (/). Environment
@@ -2522,6 +2522,9 @@ normalize({path}) *vim.fs.normalize()*
Parameters: ~
• {path} (string) Path to normalize
+ • {opts} (table|nil) Options:
+ • expand_env: boolean Expand environment variables (default:
+ true)
Return: ~
(string) Normalized path
diff --git a/runtime/doc/luvref.txt b/runtime/doc/luvref.txt
index 0fdd010880..799d0f6f74 100644
--- a/runtime/doc/luvref.txt
+++ b/runtime/doc/luvref.txt
@@ -91,7 +91,7 @@ used here to facilitate documenting consistent behavior:
metamethod
- `buffer`: a `string` or a sequential `table` of `string`s
- `threadargs`: variable arguments (`...`) of type `nil`, `boolean`, `number`,
- `string`, or `userdata`
+ `string`, or `userdata`; number of arguments limited to 9.
==============================================================================
CONTENTS *luv-contents*
@@ -2576,7 +2576,7 @@ uv.fs_poll_start({fs_poll}, {path}, {interval}, {callback}) *uv.fs_poll_start()*
> method form `fs_poll:start(path, interval, callback)`
Parameters:
- - `fs_event`: `uv_fs_event_t userdata`
+ - `fs_poll`: `uv_fs_poll_t userdata`
- `path`: `string`
- `interval`: `integer`
- `callback`: `callable`
@@ -3484,6 +3484,9 @@ uv.new_thread([{options}, ] {entry}, {...}) *uv.new_thread()*
Returns: `luv_thread_t userdata` or `fail`
+ Note: unsafe, please make sure that the thread's end of life
+ is before Lua state is closed.
+
uv.thread_equal({thread}, {other_thread}) *uv.thread_equal()*
> method form `thread:equal(other_thread)`
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 7efb0ab36f..7b71b53b29 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -62,6 +62,10 @@ The following changes may require adaptations in user config or plugins.
• |nvim_exec()| is now deprecated in favor of |nvim_exec2()|.
+• `help` treesitter parser was renamed to `vimdoc`. The only user-visible
+ change is that language-specific highlight groups need to be renamed from
+ `@foo.help` to `@foo.vimdoc`.
+
==============================================================================
NEW FEATURES *news-features*
@@ -231,6 +235,9 @@ The following new APIs or features were added.
• Added |nvim_get_hl()| for getting highlight group definitions in a format compatible with |nvim_set_hl()|.
+• |vim.diagnostic| now supports LSP DiagnosticsTag.
+ See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticTag
+
==============================================================================
CHANGED FEATURES *news-changes*
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index d7e005ae51..0298f5a9b1 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -195,7 +195,7 @@ treesitter queries from Lua.
TREESITTER QUERY PREDICATES *treesitter-predicates*
Predicates are special scheme nodes that are evaluated to conditionally capture
-nodes. For example, the `eq?` predicate can be used as follows: >
+nodes. For example, the `eq?` predicate can be used as follows: >query
((identifier) @foo (#eq? @foo "foo"))
<
@@ -204,13 +204,13 @@ to only match identifier corresponding to the `"foo"` text.
The following predicates are built in:
`eq?` *treesitter-predicate-eq?*
- Match a string against the text corresponding to a node: >
+ Match a string against the text corresponding to a node: >query
((identifier) @foo (#eq? @foo "foo"))
((node1) @left (node2) @right (#eq? @left @right))
<
`match?` *treesitter-predicate-match?*
`vim-match?` *treesitter-predicate-vim-match?*
- Match a |regexp| against the text corresponding to a node: >
+ Match a |regexp| against the text corresponding to a node: >query
((identifier) @constant (#match? @constant "^[A-Z_]+$"))
< Note: The `^` and `$` anchors will match the start and end of the
node's text.
@@ -220,13 +220,14 @@ The following predicates are built in:
similar to `match?`
`contains?` *treesitter-predicate-contains?*
- Match a string against parts of the text corresponding to a node: >
+ Match a string against parts of the text corresponding to a node:
+ >query
((identifier) @foo (#contains? @foo "foo"))
((identifier) @foo-bar (#contains? @foo-bar "foo" "bar"))
<
`any-of?` *treesitter-predicate-any-of?*
Match any of the given strings against the text corresponding to
- a node: >
+ a node: >query
((identifier) @foo (#any-of? @foo "foo" "bar"))
<
This is the recommended way to check if the node matches one of many
@@ -243,7 +244,7 @@ Use |vim.treesitter.query.list_predicates()| to list all available predicates.
TREESITTER QUERY DIRECTIVES *treesitter-directives*
Treesitter directives store metadata for a node or match and perform side
-effects. For example, the `set!` directive sets metadata on the match or node: >
+effects. For example, the `set!` directive sets metadata on the match or node: >query
((identifier) @foo (#set! "type" "parameter"))
<
@@ -259,7 +260,7 @@ The following directives are built in:
{key}
{value}
- Examples: >
+ Examples: >query
((identifier) @foo (#set! @foo "kind" "parameter"))
((node1) @left (node2) @right (#set! "type" "pair"))
<
@@ -275,7 +276,7 @@ The following directives are built in:
{end_row}
{end_col}
- Example: >
+ Example: >query
((identifier) @constant (#offset! @constant 0 1 0 -1))
<
@@ -304,7 +305,8 @@ currently supported modeline alternatives:
a base depends on your 'runtimepath' value.
Note: These modeline comments must be at the top of the query, but can be
-repeated, for example, the following two modeline blocks are both valid: >
+repeated, for example, the following two modeline blocks are both valid:
+>query
;; inherits: foo,bar
;; extends
@@ -318,13 +320,13 @@ TREESITTER SYNTAX HIGHLIGHTING *treesitter-highlight*
Syntax highlighting is specified through queries named `highlights.scm`,
which match a |TSNode| in the parsed |TSTree| to a `capture` that can be
-assigned a highlight group. For example, the query >
+assigned a highlight group. For example, the query >query
(parameters (identifier) @parameter)
<
matches any `identifier` node inside a function `parameter` node (e.g., the
`bar` in `foo(bar)`) to the capture named `@parameter`. It is also possible to
-match literal expressions (provided the parser returns them): >
+match literal expressions (provided the parser returns them): >query
"return" @keyword.return
<
@@ -409,7 +411,7 @@ The following captures are linked by default to standard |group-name|s:
*treesitter-highlight-spell*
The special `@spell` capture can be used to indicate that a node should be
spell checked by Nvim's builtin |spell| checker. For example, the following
-capture marks comments as to be checked: >
+capture marks comments as to be checked: >query
(comment) @spell
<
@@ -420,14 +422,14 @@ There is also `@nospell` which disables spellchecking regions with `@spell`.
Treesitter highlighting supports |conceal| via the `conceal` metadata. By
convention, nodes to be concealed are captured as `@conceal`, but any capture
can be used. For example, the following query can be used to hide code block
-delimiters in Markdown: >
+delimiters in Markdown: >query
- (fenced_code_block_delimiter) @conceal (#set! conceal "")
+ (fenced_code_block_delimiter @conceal (#set! conceal ""))
<
It is also possible to replace a node with a single character, which (unlike
legacy syntax) can be given a custom highlight. For example, the following
(ill-advised) query replaces the `!=` operator by a Unicode glyph, which is
-still highlighted the same as other operators: >
+still highlighted the same as other operators: >query
"!=" @operator (#set! conceal "≠")
<
@@ -438,9 +440,10 @@ Treesitter uses |nvim_buf_set_extmark()| to set highlights with a default
priority of 100. This enables plugins to set a highlighting priority lower or
higher than tree-sitter. It is also possible to change the priority of an
individual query pattern manually by setting its `"priority"` metadata
-attribute: >
+attribute: >query
- (super_important_node) @ImportantHighlight (#set! "priority" 105)
+ ((super_important_node) @superimportant (#set! "priority" 105))
+<
==============================================================================
TREESITTER LANGUAGE INJECTIONS *treesitter-language-injections*
@@ -592,8 +595,7 @@ get_node_text({node}, {source}, {opts})
(string)
get_parser({bufnr}, {lang}, {opts}) *vim.treesitter.get_parser()*
- Returns the parser for a specific buffer and filetype and attaches it to
- the buffer
+ Returns the parser for a specific buffer and attaches it to the buffer
If needed, this will create the parser.
@@ -728,29 +730,35 @@ stop({bufnr}) *vim.treesitter.stop()*
Lua module: vim.treesitter.language *lua-treesitter-language*
add({lang}, {opts}) *vim.treesitter.language.add()*
- Asserts that a parser for the language {lang} is installed.
+ Load parser with name {lang}
Parsers are searched in the `parser` runtime directory, or the provided
{path}
Parameters: ~
- • {lang} (string) Language the parser should parse (alphanumerical and
- `_` only)
+ • {lang} (string) Name of the parser (alphanumerical and `_` only)
• {opts} (table|nil) Options:
- • filetype (string|string[]) Filetype(s) that lang can be
- parsed with. Note this is not strictly the same as lang
- since a single lang can parse multiple filetypes. Defaults
- to lang.
+ • filetype (string|string[]) Default filetype the parser
+ should be associated with. Defaults to {lang}.
• path (string|nil) Optional path the parser is located at
• symbol_name (string|nil) Internal symbol name for the
language to load
+get_filetypes({lang}) *vim.treesitter.language.get_filetypes()*
+ Get the filetypes associated with the parser named {lang}.
+
+ Parameters: ~
+ • {lang} string Name of parser
+
+ Return: ~
+ string[] filetypes
+
get_lang({filetype}) *vim.treesitter.language.get_lang()*
Parameters: ~
- • {filetype} (string)
+ • {filetype} string
Return: ~
- (string|nil)
+ string|nil
inspect({lang}) *vim.treesitter.language.inspect()*
Inspects the provided language.
@@ -765,10 +773,10 @@ inspect({lang}) *vim.treesitter.language.inspect()*
(table)
register({lang}, {filetype}) *vim.treesitter.language.register()*
- Register a lang to be used for a filetype (or list of filetypes).
+ Register a parser named {lang} to be used for {filetype}(s).
Parameters: ~
- • {lang} (string) Language to register
+ • {lang} string Name of parser
• {filetype} string|string[] Filetype(s) to associate with lang
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 56532d0184..714038f8e4 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -483,6 +483,7 @@ local function next_diagnostic(position, search_forward, bufnr, opts, namespace)
local diagnostics =
get_diagnostics(bufnr, vim.tbl_extend('keep', opts, { namespace = namespace }), true)
local line_diagnostics = diagnostic_lines(diagnostics)
+
for i = 0, line_count do
local offset = i * (search_forward and 1 or -1)
local lnum = position[1] + offset
@@ -752,6 +753,7 @@ end
---@field message string
---@field source nil|string
---@field code nil|string
+---@field _tags { deprecated: boolean, unnecessary: boolean}
---@field user_data nil|any arbitrary data plugins can add
--- Get current diagnostics.
@@ -948,6 +950,16 @@ M.handlers.underline = {
higroup = underline_highlight_map.Error
end
+ if diagnostic._tags then
+ -- TODO(lewis6991): we should be able to stack these.
+ if diagnostic._tags.unnecessary then
+ higroup = 'DiagnosticUnnecessary'
+ end
+ if diagnostic._tags.deprecated then
+ higroup = 'DiagnosticDeprecated'
+ end
+ end
+
vim.highlight.range(
bufnr,
underline_ns,
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 740304df15..87439f9f0c 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -615,6 +615,7 @@ local extension = {
asd = 'lisp',
lt = 'lite',
lite = 'lite',
+ livemd = 'livebook',
lgt = 'logtalk',
lotos = 'lotos',
lot = 'lotos',
diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua
index 2c3fc64d57..407b334f20 100644
--- a/runtime/lua/vim/fs.lua
+++ b/runtime/lua/vim/fs.lua
@@ -77,6 +77,8 @@ local function join_paths(...)
return (table.concat({ ... }, '/'):gsub('//+', '/'))
end
+---@alias Iterator fun(): string?, string?
+
--- Return an iterator over the files and directories located in {path}
---
---@param path (string) An absolute or relative path to the directory to iterate
@@ -100,10 +102,13 @@ function M.dir(path, opts)
})
if not opts.depth or opts.depth == 1 then
- return function(fs)
+ local fs = vim.loop.fs_scandir(M.normalize(path))
+ return function()
+ if not fs then
+ return
+ end
return vim.loop.fs_scandir_next(fs)
- end,
- vim.loop.fs_scandir(M.normalize(path))
+ end
end
--- @async
@@ -316,16 +321,32 @@ end
--- </pre>
---
---@param path (string) Path to normalize
+---@param opts table|nil Options:
+--- - expand_env: boolean Expand environment variables (default: true)
---@return (string) Normalized path
-function M.normalize(path)
- vim.validate({ path = { path, 's' } })
- return (
- path
- :gsub('^~$', vim.loop.os_homedir())
- :gsub('^~/', vim.loop.os_homedir() .. '/')
- :gsub('%$([%w_]+)', vim.loop.os_getenv)
- :gsub('\\', '/')
- )
+function M.normalize(path, opts)
+ opts = opts or {}
+
+ vim.validate({
+ path = { path, { 'string' } },
+ expand_env = { opts.expand_env, { 'boolean' }, true },
+ })
+
+ if path:sub(1, 1) == '~' then
+ local home = vim.loop.os_homedir() or '~'
+ if home:sub(-1) == '\\' or home:sub(-1) == '/' then
+ home = home:sub(1, -2)
+ end
+ path = home .. path:sub(2)
+ end
+
+ if opts.expand_env == nil or opts.expand_env then
+ path = path:gsub('%$([%w_]+)', vim.loop.os_getenv)
+ end
+
+ path = path:gsub('\\', '/'):gsub('/+', '/')
+
+ return path:sub(-1) == '/' and path:sub(1, -2) or path
end
return M
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 41d5579664..201de18497 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -1,8 +1,11 @@
local uv = vim.loop
+--- @type (fun(modename: string): fun()|string)[]
+local loaders = package.loaders
+
local M = {}
----@alias CacheHash {mtime: {sec:number, nsec:number}, size:number}
+---@alias CacheHash {mtime: {sec:number, nsec:number}, size:number, type: string}
---@alias CacheEntry {hash:CacheHash, chunk:string}
---@class ModuleFindOpts
@@ -29,6 +32,8 @@ local Loader = {
VERSION = 3,
---@type table<string, table<string,ModuleInfo>>
_indexed = {},
+ ---@type table<string, CacheHash>
+ _hashes = {},
---@type table<string, string[]>
_topmods = {},
_loadfile = loadfile,
@@ -38,27 +43,21 @@ local Loader = {
},
}
---- Tracks the time spent in a function
----@private
-function Loader.track(stat, start)
- Loader._stats[stat] = Loader._stats[stat] or { total = 0, time = 0 }
- Loader._stats[stat].total = Loader._stats[stat].total + 1
- Loader._stats[stat].time = Loader._stats[stat].time + uv.hrtime() - start
+--- @param path string
+--- @return uv.fs_stat.result
+--- @private
+function Loader.get_hash(path)
+ if not Loader._hashes[path] then
+ -- Note we must never save a stat for a non-existent path.
+ -- For non-existent paths fs_stat() will return nil.
+ Loader._hashes[path] = uv.fs_stat(path)
+ end
+ return Loader._hashes[path]
end
---- slightly faster/different version than vim.fs.normalize
---- we also need to have it here, since the loader will load vim.fs
---@private
-function Loader.normalize(path)
- if path:sub(1, 1) == '~' then
- local home = vim.loop.os_homedir() or '~'
- if home:sub(-1) == '\\' or home:sub(-1) == '/' then
- home = home:sub(1, -2)
- end
- path = home .. path:sub(2)
- end
- path = path:gsub('\\', '/'):gsub('/+', '/')
- return path:sub(-1) == '/' and path:sub(1, -2) or path
+local function normalize(path)
+ return vim.fs.normalize(path, { expand_env = false })
end
--- Gets the rtp excluding after directories.
@@ -67,9 +66,7 @@ end
--- @return string[] rtp, boolean updated
---@private
function Loader.get_rtp()
- local start = uv.hrtime()
if vim.in_fast_event() then
- Loader.track('get_rtp', start)
return (Loader._rtp or {}), false
end
local updated = false
@@ -77,7 +74,7 @@ function Loader.get_rtp()
if key ~= Loader._rtp_key then
Loader._rtp = {}
for _, path in ipairs(vim.api.nvim_get_runtime_file('', true)) do
- path = Loader.normalize(path)
+ path = normalize(path)
-- skip after directories
if
path:sub(-6, -1) ~= '/after'
@@ -89,7 +86,6 @@ function Loader.get_rtp()
updated = true
Loader._rtp_key = key
end
- Loader.track('get_rtp', start)
return Loader._rtp, updated
end
@@ -120,19 +116,28 @@ function Loader.write(name, entry)
uv.fs_close(f)
end
+--- @param path string
+--- @param mode integer
+--- @return string? data
+--- @private
+local function readfile(path, mode)
+ local f = uv.fs_open(path, 'r', mode)
+ if f then
+ local hash = assert(uv.fs_fstat(f))
+ local data = uv.fs_read(f, hash.size, 0) --[[@as string?]]
+ uv.fs_close(f)
+ return data
+ end
+end
+
--- Loads the cache entry for a given module or file
---@param name string module name or filename
---@return CacheEntry?
---@private
function Loader.read(name)
- local start = uv.hrtime()
local cname = Loader.cache_file(name)
- local f = uv.fs_open(cname, 'r', 438)
- if f then
- local hash = uv.fs_fstat(f) --[[@as CacheHash]]
- local data = uv.fs_read(f, hash.size, 0) --[[@as string]]
- uv.fs_close(f)
-
+ local data = readfile(cname, 438)
+ if data then
local zero = data:find('\0', 1, true)
if not zero then
return
@@ -143,7 +148,6 @@ function Loader.read(name)
if tonumber(header[1]) ~= Loader.VERSION then
return
end
- Loader.track('read', start)
return {
hash = {
size = tonumber(header[2]),
@@ -152,7 +156,6 @@ function Loader.read(name)
chunk = data:sub(zero + 1),
}
end
- Loader.track('read', start)
end
--- The `package.loaders` loader for lua files using the cache.
@@ -160,14 +163,13 @@ end
---@return string|function
---@private
function Loader.loader(modname)
- local start = uv.hrtime()
local ret = M.find(modname)[1]
if ret then
- local chunk, err = Loader.load(ret.modpath, { hash = ret.stat })
- Loader.track('loader', start)
+ -- Make sure to call the global loadfile so we respect any augmentations done elsewhere.
+ -- E.g. profiling
+ local chunk, err = loadfile(ret.modpath)
return chunk or error(err)
end
- Loader.track('loader', start)
return '\ncache_loader: module ' .. modname .. ' not found'
end
@@ -176,7 +178,6 @@ end
---@return string|function
---@private
function Loader.loader_lib(modname)
- local start = uv.hrtime()
local sysname = uv.os_uname().sysname:lower() or ''
local is_win = sysname:find('win', 1, true) and not sysname:find('darwin', 1, true)
local ret = M.find(modname, { patterns = is_win and { '.dll' } or { '.so' } })[1]
@@ -190,28 +191,23 @@ function Loader.loader_lib(modname)
local dash = modname:find('-', 1, true)
local funcname = dash and modname:sub(dash + 1) or modname
local chunk, err = package.loadlib(ret.modpath, 'luaopen_' .. funcname:gsub('%.', '_'))
- Loader.track('loader_lib', start)
return chunk or error(err)
end
- Loader.track('loader_lib', start)
return '\ncache_loader_lib: module ' .. modname .. ' not found'
end
--- `loadfile` using the cache
+--- Note this has the mode and env arguments which is supported by LuaJIT and is 5.1 compatible.
---@param filename? string
---@param mode? "b"|"t"|"bt"
---@param env? table
----@param hash? CacheHash
---@return function?, string? error_message
---@private
-- luacheck: ignore 312
-function Loader.loadfile(filename, mode, env, hash)
- local start = uv.hrtime()
- filename = Loader.normalize(filename)
- mode = nil -- ignore mode, since we byte-compile the lua source files
- local chunk, err = Loader.load(filename, { mode = mode, env = env, hash = hash })
- Loader.track('loadfile', start)
- return chunk, err
+function Loader.loadfile(filename, mode, env)
+ -- ignore mode, since we byte-compile the lua source files
+ mode = nil
+ return Loader.load(normalize(filename), { mode = mode, env = env })
end
--- Checks whether two cache hashes are the same based on:
@@ -231,26 +227,21 @@ end
--- Loads the given module path using the cache
---@param modpath string
----@param opts? {hash?: CacheHash, mode?: "b"|"t"|"bt", env?:table} (table|nil) Options for loading the module:
---- - hash: (table) the hash of the file to load if it is already known. (defaults to `vim.loop.fs_stat({modpath})`)
+---@param opts? {mode?: "b"|"t"|"bt", env?:table} (table|nil) Options for loading the module:
--- - mode: (string) the mode to load the module with. "b"|"t"|"bt" (defaults to `nil`)
--- - env: (table) the environment to load the module in. (defaults to `nil`)
---@see |luaL_loadfile()|
---@return function?, string? error_message
---@private
function Loader.load(modpath, opts)
- local start = uv.hrtime()
-
opts = opts or {}
- local hash = opts.hash or uv.fs_stat(modpath)
+ local hash = Loader.get_hash(modpath)
---@type function?, string?
local chunk, err
if not hash then
-- trigger correct error
- chunk, err = Loader._loadfile(modpath, opts.mode, opts.env)
- Loader.track('load', start)
- return chunk, err
+ return Loader._loadfile(modpath, opts.mode, opts.env)
end
local entry = Loader.read(modpath)
@@ -258,7 +249,6 @@ function Loader.load(modpath, opts)
-- found in cache and up to date
chunk, err = load(entry.chunk --[[@as string]], '@' .. modpath, opts.mode, opts.env)
if not (err and err:find('cannot load incompatible bytecode', 1, true)) then
- Loader.track('load', start)
return chunk, err
end
end
@@ -269,7 +259,6 @@ function Loader.load(modpath, opts)
entry.chunk = string.dump(chunk)
Loader.write(modpath, entry)
end
- Loader.track('load', start)
return chunk, err
end
@@ -287,7 +276,6 @@ end
--- - modname: (string) the name of the module
--- - stat: (table|nil) the fs_stat of the module path. Won't be returned for `modname="*"`
function M.find(modname, opts)
- local start = uv.hrtime()
opts = opts or {}
modname = modname:gsub('/', '.')
@@ -338,7 +326,7 @@ function M.find(modname, opts)
for _, pattern in ipairs(patterns) do
local modpath = path .. pattern
Loader._stats.find.stat = (Loader._stats.find.stat or 0) + 1
- local hash = uv.fs_stat(modpath)
+ local hash = Loader.get_hash(modpath)
if hash then
results[#results + 1] = { modpath = modpath, stat = hash, modname = modname }
if not continue() then
@@ -366,7 +354,6 @@ function M.find(modname, opts)
_find(opts.paths)
end
- Loader.track('find', start)
if #results == 0 then
-- module not found
Loader._stats.find.not_found = Loader._stats.find.not_found + 1
@@ -375,15 +362,18 @@ function M.find(modname, opts)
return results
end
---- Resets the topmods cache for the path, or all the paths
+--- Resets the cache for the path, or all the paths
--- if path is nil.
---@param path string? path to reset
function M.reset(path)
if path then
- Loader._indexed[Loader.normalize(path)] = nil
+ Loader._indexed[normalize(path)] = nil
else
Loader._indexed = {}
end
+
+ -- Path could be a directory so just clear all the hashes.
+ Loader._hashes = {}
end
--- Enables the experimental Lua module loader:
@@ -399,29 +389,16 @@ function M.enable()
vim.fn.mkdir(vim.fn.fnamemodify(M.path, ':p'), 'p')
_G.loadfile = Loader.loadfile
-- add lua loader
- table.insert(package.loaders, 2, Loader.loader)
+ table.insert(loaders, 2, Loader.loader)
-- add libs loader
- table.insert(package.loaders, 3, Loader.loader_lib)
+ table.insert(loaders, 3, Loader.loader_lib)
-- remove Neovim loader
- for l, loader in ipairs(package.loaders) do
+ for l, loader in ipairs(loaders) do
if loader == vim._load_package then
- table.remove(package.loaders, l)
+ table.remove(loaders, l)
break
end
end
-
- -- this will reset the top-mods in case someone adds a new
- -- top-level lua module to a path already on the rtp
- vim.api.nvim_create_autocmd('BufWritePost', {
- group = vim.api.nvim_create_augroup('cache_topmods_reset', { clear = true }),
- callback = function(event)
- local bufname = event.match ---@type string
- local idx = bufname:find('/lua/', 1, true)
- if idx then
- M.reset(bufname:sub(1, idx - 1))
- end
- end,
- })
end
--- Disables the experimental Lua module loader:
@@ -433,14 +410,12 @@ function M.disable()
end
M.enabled = false
_G.loadfile = Loader._loadfile
- ---@diagnostic disable-next-line: no-unknown
- for l, loader in ipairs(package.loaders) do
+ for l, loader in ipairs(loaders) do
if loader == Loader.loader or loader == Loader.loader_lib then
- table.remove(package.loaders, l)
+ table.remove(loaders, l)
end
end
- table.insert(package.loaders, 2, vim._load_package)
- vim.api.nvim_del_augroup_by_name('cache_topmods_reset')
+ table.insert(loaders, 2, vim._load_package)
end
--- Return the top-level `/lua/*` modules for this path
@@ -448,17 +423,11 @@ end
---@private
function Loader.lsmod(path)
if not Loader._indexed[path] then
- local start = uv.hrtime()
Loader._indexed[path] = {}
- local handle = vim.loop.fs_scandir(path .. '/lua')
- while handle do
- local name, t = vim.loop.fs_scandir_next(handle)
- if not name then
- break
- end
+ for name, t in vim.fs.dir(path .. '/lua') do
local modpath = path .. '/lua/' .. name
-- HACK: type is not always returned due to a bug in luv
- t = t or uv.fs_stat(modpath).type
+ t = t or Loader.get_hash(modpath).type
---@type string
local topname
local ext = name:sub(-4)
@@ -477,22 +446,46 @@ function Loader.lsmod(path)
end
end
end
- Loader.track('lsmod', start)
end
return Loader._indexed[path]
end
+--- Tracks the time spent in a function
+--- @generic F: function
+--- @param f F
+--- @return F
+--- @private
+function Loader.track(stat, f)
+ return function(...)
+ local start = vim.loop.hrtime()
+ local r = { f(...) }
+ Loader._stats[stat] = Loader._stats[stat] or { total = 0, time = 0 }
+ Loader._stats[stat].total = Loader._stats[stat].total + 1
+ Loader._stats[stat].time = Loader._stats[stat].time + uv.hrtime() - start
+ return unpack(r, 1, table.maxn(r))
+ end
+end
+
+---@class ProfileOpts
+---@field loaders? boolean Add profiling to the loaders
+
--- Debug function that wrapps all loaders and tracks stats
---@private
-function M._profile_loaders()
- for l, loader in pairs(package.loaders) do
- local loc = debug.getinfo(loader, 'Sn').source:sub(2)
- package.loaders[l] = function(modname)
- local start = vim.loop.hrtime()
- local ret = loader(modname)
- Loader.track('loader ' .. l .. ': ' .. loc, start)
- Loader.track('loader_all', start)
- return ret
+---@param opts ProfileOpts?
+function M._profile(opts)
+ Loader.get_rtp = Loader.track('get_rtp', Loader.get_rtp)
+ Loader.read = Loader.track('read', Loader.read)
+ Loader.loader = Loader.track('loader', Loader.loader)
+ Loader.loader_lib = Loader.track('loader_lib', Loader.loader_lib)
+ Loader.loadfile = Loader.track('loadfile', Loader.loadfile)
+ Loader.load = Loader.track('load', Loader.load)
+ M.find = Loader.track('find', M.find)
+ Loader.lsmod = Loader.track('lsmod', Loader.lsmod)
+
+ if opts and opts.loaders then
+ for l, loader in pairs(loaders) do
+ local loc = debug.getinfo(loader, 'Sn').source:sub(2)
+ loaders[l] = Loader.track('loader ' .. l .. ': ' .. loc, loader)
end
end
end
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index b27bf6e425..3efa5c51ff 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -1,13 +1,6 @@
---@brief lsp-diagnostic
----
----@class Diagnostic
----@field range Range
----@field message string
----@field severity DiagnosticSeverity|nil
----@field code integer | string
----@field source string
----@field tags DiagnosticTag[]
----@field relatedInformation DiagnosticRelatedInformation[]
+
+local protocol = require('vim.lsp.protocol')
local M = {}
@@ -22,14 +15,16 @@ local function get_client_id(client_id)
end
---@private
+---@param severity lsp.DiagnosticSeverity
local function severity_lsp_to_vim(severity)
if type(severity) == 'string' then
- severity = vim.lsp.protocol.DiagnosticSeverity[severity]
+ severity = protocol.DiagnosticSeverity[severity]
end
return severity
end
---@private
+---@return lsp.DiagnosticSeverity
local function severity_vim_to_lsp(severity)
if type(severity) == 'string' then
severity = vim.diagnostic.severity[severity]
@@ -38,6 +33,7 @@ local function severity_vim_to_lsp(severity)
end
---@private
+---@return integer
local function line_byte_from_position(lines, lnum, col, offset_encoding)
if not lines or offset_encoding == 'utf-8' then
return col
@@ -77,12 +73,41 @@ local function get_buf_lines(bufnr)
return lines
end
+--- @private
+--- @param diagnostic lsp.Diagnostic
+--- @param client_id integer
+--- @return table?
+local function tags_lsp_to_vim(diagnostic, client_id)
+ local tags ---@type table?
+ for _, tag in ipairs(diagnostic.tags or {}) do
+ if tag == protocol.DiagnosticTag.Unnecessary then
+ tags = tags or {}
+ tags.unnecessary = true
+ elseif tag == protocol.DiagnosticTag.Deprecated then
+ tags = tags or {}
+ tags.deprecated = true
+ else
+ vim.notify_once(
+ string.format('Unknown DiagnosticTag %d from LSP client %d', tag, client_id),
+ vim.log.levels.WARN
+ )
+ end
+ end
+ return tags
+end
+
---@private
+---@param diagnostics lsp.Diagnostic[]
+---@param bufnr integer
+---@param client_id integer
+---@return Diagnostic[]
local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
local buf_lines = get_buf_lines(bufnr)
local client = vim.lsp.get_client_by_id(client_id)
local offset_encoding = client and client.offset_encoding or 'utf-16'
+ ---@diagnostic disable-next-line:no-unknown
return vim.tbl_map(function(diagnostic)
+ ---@cast diagnostic lsp.Diagnostic
local start = diagnostic.range.start
local _end = diagnostic.range['end']
return {
@@ -94,12 +119,12 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
message = diagnostic.message,
source = diagnostic.source,
code = diagnostic.code,
+ _tags = tags_lsp_to_vim(diagnostic, client_id),
user_data = {
lsp = {
-- usage of user_data.lsp.code is deprecated in favor of the top-level code field
code = diagnostic.code,
codeDescription = diagnostic.codeDescription,
- tags = diagnostic.tags,
relatedInformation = diagnostic.relatedInformation,
data = diagnostic.data,
},
@@ -108,9 +133,13 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
end, diagnostics)
end
----@private
+--- @private
+--- @param diagnostics Diagnostic[]
+--- @return lsp.Diagnostic[]
local function diagnostic_vim_to_lsp(diagnostics)
+ ---@diagnostic disable-next-line:no-unknown
return vim.tbl_map(function(diagnostic)
+ ---@cast diagnostic Diagnostic
return vim.tbl_extend('keep', {
-- "keep" the below fields over any duplicate fields in diagnostic.user_data.lsp
range = {
@@ -131,6 +160,7 @@ local function diagnostic_vim_to_lsp(diagnostics)
end, diagnostics)
end
+---@type table<integer,integer>
local _client_namespaces = {}
--- Get the diagnostic namespace associated with an LSP client |vim.diagnostic|.
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 1686e22c48..f4489ad17d 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -21,6 +21,7 @@ end
--]=]
local constants = {
+ --- @enum lsp.DiagnosticSeverity
DiagnosticSeverity = {
-- Reports an error.
Error = 1,
@@ -32,6 +33,7 @@ local constants = {
Hint = 4,
},
+ --- @enum lsp.DiagnosticTag
DiagnosticTag = {
-- Unused or unnecessary code
Unnecessary = 1,
diff --git a/runtime/lua/vim/lsp/types.lua b/runtime/lua/vim/lsp/types.lua
index 1aea6841ee..779f313aa7 100644
--- a/runtime/lua/vim/lsp/types.lua
+++ b/runtime/lua/vim/lsp/types.lua
@@ -18,3 +18,20 @@
---@class lsp.FileEvent
---@field uri string
---@field type lsp.FileChangeType
+
+---@class lsp.Position
+---@field line integer
+---@field character integer
+
+---@class lsp.Range
+---@field start lsp.Position
+---@field end lsp.Position
+
+---@class lsp.Diagnostic
+---@field range lsp.Range
+---@field message string
+---@field severity? lsp.DiagnosticSeverity
+---@field code integer | string
+---@field source string
+---@field tags? lsp.DiagnosticTag[]
+---@field relatedInformation DiagnosticRelatedInformation[]
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 884929e33a..9e337e93e8 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -796,13 +796,15 @@ end
--- a.b.c = 1
--- </pre>
---
----@param create function|nil The function called to create a missing value.
+---@param create function?(key:any):any The function called to create a missing value.
---@return table Empty table with metamethod
function vim.defaulttable(create)
- create = create or vim.defaulttable
+ create = create or function(_)
+ return vim.defaulttable()
+ end
return setmetatable({}, {
__index = function(tbl, key)
- rawset(tbl, key, create())
+ rawset(tbl, key, create(key))
return rawget(tbl, key)
end,
})
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index 4c3b17daa4..2594c1672d 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -58,9 +58,6 @@ function M._create_parser(bufnr, lang, opts)
vim.fn.bufload(bufnr)
- local ft = vim.bo[bufnr].filetype
- M.language.add(lang, { filetype = ft ~= '' and ft or nil })
-
local self = LanguageTree.new(bufnr, lang, opts)
---@private
@@ -94,7 +91,12 @@ function M._create_parser(bufnr, lang, opts)
return self
end
---- Returns the parser for a specific buffer and filetype and attaches it to the buffer
+--- @private
+local function valid_lang(lang)
+ return lang and lang ~= ''
+end
+
+--- Returns the parser for a specific buffer and attaches it to the buffer
---
--- If needed, this will create the parser.
---
@@ -110,18 +112,12 @@ function M.get_parser(bufnr, lang, opts)
bufnr = a.nvim_get_current_buf()
end
- if lang == nil then
- local ft = vim.bo[bufnr].filetype
- if ft ~= '' then
- lang = M.language.get_lang(ft) or ft
- -- TODO(lewis6991): we should error here and not default to ft
- -- if not lang then
- -- error(string.format('filetype %s of buffer %d is not associated with any lang', ft, bufnr))
- -- end
- else
- if parsers[bufnr] then
- return parsers[bufnr]
- end
+ if not valid_lang(lang) then
+ lang = M.language.get_lang(vim.bo[bufnr].filetype) or vim.bo[bufnr].filetype
+ end
+
+ if not valid_lang(lang) then
+ if not parsers[bufnr] then
error(
string.format(
'There is no parser available for buffer %d and one could not be'
@@ -131,9 +127,7 @@ function M.get_parser(bufnr, lang, opts)
)
)
end
- end
-
- if parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then
+ elseif parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then
parsers[bufnr] = M._create_parser(bufnr, lang, opts)
end
@@ -164,7 +158,6 @@ function M.get_string_parser(str, lang, opts)
str = { str, 'string' },
lang = { lang, 'string' },
})
- M.language.add(lang)
return LanguageTree.new(str, lang, opts)
end
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
index fd1188fde4..dabf2cdf6c 100644
--- a/runtime/lua/vim/treesitter/health.lua
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -22,7 +22,7 @@ function M.check()
)
)
else
- local lang = ts.language.inspect_language(parsername)
+ local lang = ts.language.inspect(parsername)
health.report_ok(
string.format('Parser: %-10s ABI: %d, path: %s', parsername, lang._abi_version, parser)
)
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index 974d66ec05..5b74bb6200 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -4,11 +4,29 @@ local a = vim.api
local M = {}
---@type table<string,string>
-local ft_to_lang = {}
+local ft_to_lang = {
+ help = 'vimdoc',
+}
+
+--- Get the filetypes associated with the parser named {lang}.
+--- @param lang string Name of parser
+--- @return string[] filetypes
+function M.get_filetypes(lang)
+ local r = {} ---@type string[]
+ for ft, p in pairs(ft_to_lang) do
+ if p == lang then
+ r[#r + 1] = ft
+ end
+ end
+ return r
+end
----@param filetype string
----@return string|nil
+--- @param filetype string
+--- @return string|nil
function M.get_lang(filetype)
+ if filetype == '' then
+ return
+ end
return ft_to_lang[filetype]
end
@@ -35,16 +53,14 @@ end
---@field filetype? string|string[]
---@field symbol_name? string
---- Asserts that a parser for the language {lang} is installed.
+--- Load parser with name {lang}
---
--- Parsers are searched in the `parser` runtime directory, or the provided {path}
---
----@param lang string Language the parser should parse (alphanumerical and `_` only)
+---@param lang string Name of the parser (alphanumerical and `_` only)
---@param opts (table|nil) Options:
---- - filetype (string|string[]) Filetype(s) that lang can be parsed with.
---- Note this is not strictly the same as lang since a single lang can
---- parse multiple filetypes.
---- Defaults to lang.
+--- - filetype (string|string[]) Default filetype the parser should be associated with.
+--- Defaults to {lang}.
--- - path (string|nil) Optional path the parser is located at
--- - symbol_name (string|nil) Internal symbol name for the language to load
function M.add(lang, opts)
@@ -61,7 +77,7 @@ function M.add(lang, opts)
filetype = { filetype, { 'string', 'table' }, true },
})
- M.register(lang, filetype or lang)
+ M.register(lang, filetype)
if vim._ts_has_language(lang) then
return
@@ -83,23 +99,26 @@ function M.add(lang, opts)
vim._ts_add_language(path, lang, symbol_name)
end
---- Register a lang to be used for a filetype (or list of filetypes).
----@param lang string Language to register
----@param filetype string|string[] Filetype(s) to associate with lang
+--- @private
+--- @param x string|string[]
+--- @return string[]
+local function ensure_list(x)
+ if type(x) == 'table' then
+ return x
+ end
+ return { x }
+end
+
+--- Register a parser named {lang} to be used for {filetype}(s).
+--- @param lang string Name of parser
+--- @param filetype string|string[] Filetype(s) to associate with lang
function M.register(lang, filetype)
vim.validate({
lang = { lang, 'string' },
filetype = { filetype, { 'string', 'table' } },
})
- local filetypes ---@type string[]
- if type(filetype) == 'string' then
- filetypes = { filetype }
- else
- filetypes = filetype
- end
-
- for _, f in ipairs(filetypes) do
+ for _, f in ipairs(ensure_list(filetype)) do
if f ~= '' then
ft_to_lang[f] = lang
end
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 82e507551d..922e4881ca 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -76,7 +76,7 @@ LanguageTree.__index = LanguageTree
--- "injected" language parsers, which themselves may inject other languages, recursively.
---
---@param source (integer|string) Buffer or text string to parse
----@param lang string Root language of this tree
+---@param lang string|nil Root language of this tree
---@param opts (table|nil) Optional arguments:
--- - injections table Map of language to injection query strings. Overrides the
--- built-in runtime file searching for language injections.
@@ -86,11 +86,6 @@ function LanguageTree.new(source, lang, opts)
---@type LanguageTreeOpts
opts = opts or {}
- if opts.queries then
- a.nvim_err_writeln("'queries' is no longer supported. Use 'injections' now")
- opts.injections = opts.queries
- end
-
local injections = opts.injections or {}
local self = setmetatable({
_source = source,
diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm
index 33e6df74ab..dee70f9cc7 100644
--- a/runtime/queries/c/highlights.scm
+++ b/runtime/queries/c/highlights.scm
@@ -1,22 +1,19 @@
-(identifier) @variable
+; Lower priority to prefer @parameter when identifier appears in parameter_declaration.
+((identifier) @variable (#set! "priority" 95))
[
- "const"
"default"
"enum"
- "extern"
- "inline"
- "return"
- "sizeof"
- "static"
"struct"
"typedef"
"union"
- "volatile"
"goto"
- "register"
] @keyword
+"sizeof" @keyword.operator
+
+"return" @keyword.return
+
[
"while"
"for"
@@ -32,7 +29,6 @@
"switch"
] @conditional
-"#define" @constant.macro
[
"#if"
"#ifdef"
@@ -41,10 +37,18 @@
"#elif"
"#endif"
(preproc_directive)
-] @keyword
+] @preproc
+
+"#define" @define
"#include" @include
+[ ";" ":" "," ] @punctuation.delimiter
+
+"..." @punctuation.special
+
+[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
+
[
"="
@@ -62,6 +66,7 @@
">>"
"->"
+ "."
"<"
"<="
@@ -88,35 +93,25 @@
"++"
] @operator
+;; Make sure the comma operator is given a highlight group after the comma
+;; punctuator so the operator is highlighted properly.
+(comma_expression [ "," ] @operator)
+
[
(true)
(false)
] @boolean
-[ "." ";" ":" "," ] @punctuation.delimiter
-
-(conditional_expression [ "?" ":" ] @conditional)
-
-
-[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
+(conditional_expression [ "?" ":" ] @conditional.ternary)
(string_literal) @string
-(string_literal) @spell
(system_lib_string) @string
+(escape_sequence) @string.escape
(null) @constant.builtin
(number_literal) @number
-(char_literal) @number
+(char_literal) @character
-(call_expression
- function: (identifier) @function)
-(call_expression
- function: (field_expression
- field: (field_identifier) @function))
-(function_declarator
- declarator: (identifier) @function)
-(preproc_function_def
- name: (identifier) @function.macro)
[
(preproc_arg)
(preproc_defined)
@@ -126,18 +121,32 @@
(statement_identifier) @label
[
-(type_identifier)
-(primitive_type)
-(sized_type_specifier)
-(type_descriptor)
- ] @type
+ (type_identifier)
+ (sized_type_specifier)
+ (type_descriptor)
+] @type
+
+(storage_class_specifier) @storageclass
+
+(type_qualifier) @type.qualifier
+
+(linkage_specification
+ "extern" @storageclass)
-(declaration (type_qualifier) @type)
-(cast_expression type: (type_descriptor) @type)
-(sizeof_expression value: (parenthesized_expression (identifier) @type))
+(type_definition
+ declarator: (type_identifier) @type.definition)
+
+(primitive_type) @type.builtin
((identifier) @constant
- (#match? @constant "^[A-Z][A-Z0-9_]+$"))
+ (#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
+(enumerator
+ name: (identifier) @constant)
+(case_statement
+ value: (identifier) @constant)
+
+((identifier) @constant.builtin
+ (#any-of? @constant.builtin "stderr" "stdin" "stdout"))
;; Preproc def / undef
(preproc_def
@@ -147,9 +156,20 @@
argument: (_) @constant
(#eq? @_u "#undef"))
+(call_expression
+ function: (identifier) @function.call)
+(call_expression
+ function: (field_expression
+ field: (field_identifier) @function.call))
+(function_declarator
+ declarator: (identifier) @function)
+(preproc_function_def
+ name: (identifier) @function.macro)
+
+(comment) @comment @spell
-(comment) @comment
-(comment) @spell
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
;; Parameters
(parameter_declaration
@@ -158,7 +178,20 @@
(parameter_declaration
declarator: (pointer_declarator) @parameter)
-(preproc_params
- (identifier)) @parameter
+(preproc_params (identifier) @parameter)
+
+[
+ "__attribute__"
+ "__cdecl"
+ "__clrcall"
+ "__stdcall"
+ "__fastcall"
+ "__thiscall"
+ "__vectorcall"
+ "_unaligned"
+ "__unaligned"
+ "__declspec"
+ (attribute_declaration)
+] @attribute
(ERROR) @error
diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm
index 84ae33683e..3b99c7a444 100644
--- a/runtime/queries/c/injections.scm
+++ b/runtime/queries/c/injections.scm
@@ -1,5 +1,5 @@
-((preproc_arg) @injection.content
- (#set! injection.language "c"))
+; ((preproc_arg) @injection.content
+; (#set! injection.language "c"))
; ((comment) @injection.content
; (#set! injection.language "comment"))
diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm
index 2c0dc5447a..5fbf8a1833 100644
--- a/runtime/queries/lua/highlights.scm
+++ b/runtime/queries/lua/highlights.scm
@@ -8,8 +8,6 @@
"local"
] @keyword
-(label_statement) @label
-
(break_statement) @keyword
(do_statement
@@ -109,6 +107,7 @@
[
";"
":"
+ "::"
","
"."
] @punctuation.delimiter
@@ -129,12 +128,21 @@
(identifier) @variable
((identifier) @variable.builtin
- (#eq? @variable.builtin "self"))
+ (#any-of? @variable.builtin "_G" "_VERSION" "debug" "io" "jit" "math" "os" "package" "self" "string" "table" "utf8"))
+
+((identifier) @keyword.coroutine
+ (#eq? @keyword.coroutine "coroutine"))
(variable_list
- attribute: (attribute
- (["<" ">"] @punctuation.bracket
- (identifier) @attribute)))
+ attribute: (attribute
+ (["<" ">"] @punctuation.bracket
+ (identifier) @attribute)))
+
+;; Labels
+
+(label_statement (identifier) @label)
+
+(goto_statement (identifier) @label)
;; Constants
@@ -172,7 +180,7 @@
(function_call name: (dot_index_expression field: (identifier) @function.call))
(function_declaration name: (dot_index_expression field: (identifier) @function))
-(method_index_expression method: (identifier) @method)
+(method_index_expression method: (identifier) @method.call)
(function_call
(identifier) @function.builtin
@@ -180,20 +188,27 @@
;; built-in functions in Lua 5.1
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
- "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
- "tonumber" "tostring" "type" "unpack" "xpcall"))
+ "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setfenv" "setmetatable"
+ "tonumber" "tostring" "type" "unpack" "xpcall"
+ "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc"
+ "__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex"
+ "__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
;; Others
-(comment) @comment
-(comment) @spell
+(comment) @comment @spell
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^[-][-][-]"))
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^[-][-](%s?)@"))
-(hash_bang_line) @comment
+(hash_bang_line) @preproc
(number) @number
-(string) @string
-(string) @spell
+(string) @string @spell
;; Error
(ERROR) @error
diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm
index 10eb4c4054..1c7bdaf951 100644
--- a/runtime/queries/lua/injections.scm
+++ b/runtime/queries/lua/injections.scm
@@ -11,18 +11,18 @@
name: (_) @_vimcmd_identifier
arguments: (arguments (string content: _ @injection.content)))
(#set! injection.language "vim")
- (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd"))
+ (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd"))
((function_call
name: (_) @_vimcmd_identifier
arguments: (arguments (string content: _ @injection.content) .))
(#set! injection.language "query")
- (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query"))
+ (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
-; ;; highlight string as query if starts with `;; query`
-; ((string ("string_content") @injection.content)
-; (#set! injection.language "query")
-; (#lua-match? @injection.content "^%s*;+%s?query"))
+;; highlight string as query if starts with `;; query`
+((string ("string_content") @injection.content)
+ (#set! injection.language "query")
+ (#lua-match? @injection.content "^%s*;+%s?query"))
; ((comment) @injection.content
; (#set! injection.language "comment"))
diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm
index 239b0a0b37..ce25b13b9f 100644
--- a/runtime/queries/vim/highlights.scm
+++ b/runtime/queries/vim/highlights.scm
@@ -271,7 +271,7 @@
":"
] @punctuation.delimiter
-(ternary_expression ["?" ":"] @conditional)
+(ternary_expression ["?" ":"] @conditional.ternary)
; Options
((set_value) @number
diff --git a/runtime/queries/help/highlights.scm b/runtime/queries/vimdoc/highlights.scm
index c0d88301bc..c0d88301bc 100644
--- a/runtime/queries/help/highlights.scm
+++ b/runtime/queries/vimdoc/highlights.scm
diff --git a/runtime/queries/help/injections.scm b/runtime/queries/vimdoc/injections.scm
index 260a05d863..260a05d863 100644
--- a/runtime/queries/help/injections.scm
+++ b/runtime/queries/vimdoc/injections.scm