diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/filetype.txt | 1 | ||||
-rw-r--r-- | runtime/doc/lsp.txt | 12 | ||||
-rw-r--r-- | runtime/doc/news.txt | 4 | ||||
-rw-r--r-- | runtime/doc/treesitter.txt | 7 | ||||
-rw-r--r-- | runtime/lua/vim/filetype.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 22 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/_watchfiles.lua | 10 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/_meta.lua | 14 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 8 |
10 files changed, 67 insertions, 19 deletions
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 175c531950..48d6aed0f2 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -162,6 +162,7 @@ variables can be used to overrule the filetype used for certain extensions: *.sys g:filetype_sys *.sh g:bash_is_sh |ft-sh-syntax| *.tex g:tex_flavor |ft-tex-plugin| + *.typ g:filetype_typ *.w g:filetype_w |ft-cweb-syntax| For a few filetypes the global variable is used only when the filetype could diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index e07bfc2209..fc365c927b 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -942,12 +942,12 @@ start_client({config}) *vim.lsp.start_client()* Parameters: ~ • {config} (table) Configuration for the server: - • cmd: (table|string|fun(dispatchers: table):table) command - string or list treated like |jobstart()|. The command must - launch the language server process. `cmd` can also be a - function that creates an RPC client. The function receives - a dispatchers table and must return a table with the - functions `request`, `notify`, `is_closing` and + • cmd: (string[]|fun(dispatchers: table):table) command a + list of strings treated like |jobstart()|. The command + must launch the language server process. `cmd` can also be + a function that creates an RPC client. The function + receives a dispatchers table and must return a table with + the functions `request`, `notify`, `is_closing` and `terminate` See |vim.lsp.rpc.request()| and |vim.lsp.rpc.notify()| For TCP there is a built-in rpc client factory: |vim.lsp.rpc.connect()| diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index bc357ac534..6b1e9112c1 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -29,6 +29,7 @@ The following changes may require adaptations in user config or plugins. set selectmode=mouse,key set mousemodel=popup set keymodel=startsel,stopsel +< ============================================================================== ADDED FEATURES *news-added* @@ -52,6 +53,9 @@ iterators |luaref-in|. • |'smoothscroll'| option to scroll by screen line rather than by text line when |'wrap'| is set. +• |Query:iter_matches()| now has the ability to set the maximum start depth + for matches. + ============================================================================== CHANGED FEATURES *news-changed* diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index 0168b11499..d425c8dace 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -939,7 +939,7 @@ Query:iter_captures({self}, {node}, {source}, {start}, {stop}) metadata *Query:iter_matches()* -Query:iter_matches({self}, {node}, {source}, {start}, {stop}) +Query:iter_matches({self}, {node}, {source}, {start}, {stop}, {opts}) Iterates the matches of self on a given range. Iterate over all matches within a {node}. The arguments are the same as @@ -966,6 +966,11 @@ Query:iter_matches({self}, {node}, {source}, {start}, {stop}) • {source} (integer|string) Source buffer or string to search • {start} (integer) Starting line for the search • {stop} (integer) Stopping line for the search (end-exclusive) + • {opts} (table|nil) Options: + • max_start_depth (integer) if non-zero, sets the maximum + start depth for each match. This is used to prevent + traversing too deep into a tree. Requires treesitter >= + 0.20.9. • {self} Return: ~ diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 5c799b23f2..c746eef1bb 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -997,7 +997,9 @@ local extension = { spi = 'spyce', spy = 'spyce', tyc = 'sql', - typ = 'sql', + typ = function(path, bufnr) + return require('vim.filetype.detect').typ(bufnr) + end, pkb = 'sql', tyb = 'sql', pks = 'sql', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 74b01d569c..94106a3547 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -1322,6 +1322,28 @@ function M.txt(bufnr) end end +function M.typ(bufnr) + if vim.g.filetype_typ then + return vim.g.filetype_typ + end + + for _, line in ipairs(getlines(bufnr, 1, 200)) do + if + findany(line, { + '^CASE[%s]?=[%s]?SAME$', + '^CASE[%s]?=[%s]?LOWER$', + '^CASE[%s]?=[%s]?UPPER$', + '^CASE[%s]?=[%s]?OPPOSITE$', + '^TYPE%s', + }) + then + return 'sql' + end + end + + return 'typst' +end + -- Determine if a .v file is Verilog, V, or Coq function M.v(bufnr) if vim.fn.did_filetype() ~= 0 then diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 5c78bd7580..a724593188 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -901,8 +901,8 @@ end --- Field `cmd` in {config} is required. --- ---@param config (table) Configuration for the server: ---- - cmd: (table|string|fun(dispatchers: table):table) command string or ---- list treated like |jobstart()|. The command must launch the language server +--- - cmd: (string[]|fun(dispatchers: table):table) command a list of +--- strings treated like |jobstart()|. The command must launch the language server --- process. `cmd` can also be a function that creates an RPC client. --- The function receives a dispatchers table and must return a table with the --- functions `request`, `notify`, `is_closing` and `terminate` diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index 533a955925..3a78724d79 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -198,16 +198,17 @@ function M.register(reg, ctx) end local watch_regs = {} for _, w in ipairs(reg.registerOptions.watchers) do + local relative_pattern = false local glob_patterns = {} if type(w.globPattern) == 'string' then for _, folder in ipairs(client.workspace_folders) do table.insert(glob_patterns, { baseUri = folder.uri, pattern = w.globPattern }) end else + relative_pattern = true table.insert(glob_patterns, w.globPattern) end for _, glob_pattern in ipairs(glob_patterns) do - local pattern = parse(glob_pattern.pattern) local base_dir = nil if type(glob_pattern.baseUri) == 'string' then base_dir = glob_pattern.baseUri @@ -216,9 +217,16 @@ function M.register(reg, ctx) end assert(base_dir, "couldn't identify root of watch") base_dir = vim.uri_to_fname(base_dir) + local kind = w.kind or protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete + local pattern = glob_pattern.pattern + if relative_pattern then + pattern = base_dir .. '/' .. pattern + end + pattern = parse(pattern) + table.insert(watch_regs, { base_dir = base_dir, pattern = pattern, diff --git a/runtime/lua/vim/treesitter/_meta.lua b/runtime/lua/vim/treesitter/_meta.lua index 4d0f43d030..c1009f5f5d 100644 --- a/runtime/lua/vim/treesitter/_meta.lua +++ b/runtime/lua/vim/treesitter/_meta.lua @@ -31,17 +31,19 @@ local TSNode = {} ---@param query userdata ---@param captures true ----@param start integer ----@param end_ integer +---@param start? integer +---@param end_? integer +---@param opts? table ---@return fun(): integer, TSNode, any -function TSNode:_rawquery(query, captures, start, end_) end +function TSNode:_rawquery(query, captures, start, end_, opts) end ---@param query userdata ---@param captures false ----@param start integer ----@param end_ integer +---@param start? integer +---@param end_? integer +---@param opts? table ---@return fun(): string, any -function TSNode:_rawquery(query, captures, start, end_) end +function TSNode:_rawquery(query, captures, start, end_, opts) end ---@class TSParser ---@field parse fun(self: TSParser, tree: TSTree?, source: integer|string, include_bytes: boolean?): TSTree, integer[] diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 93841bb31e..e6a117557a 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -686,16 +686,20 @@ end ---@param source (integer|string) Source buffer or string to search ---@param start integer Starting line for the search ---@param stop integer Stopping line for the search (end-exclusive) +---@param opts table|nil Options: +--- - max_start_depth (integer) if non-zero, sets the maximum start depth +--- for each match. This is used to prevent traversing too deep into a tree. +--- Requires treesitter >= 0.20.9. --- ---@return (fun(): integer, table<integer,TSNode>, table): pattern id, match, metadata -function Query:iter_matches(node, source, start, stop) +function Query:iter_matches(node, source, start, stop, opts) if type(source) == 'number' and source == 0 then source = api.nvim_get_current_buf() end start, stop = value_or_node_range(start, stop, node) - local raw_iter = node:_rawquery(self.query, false, start, stop) + local raw_iter = node:_rawquery(self.query, false, start, stop, opts) ---@cast raw_iter fun(): string, any local function iter() local pattern, match = raw_iter() |