aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/log.lua8
-rw-r--r--runtime/lua/vim/lsp/util.lua2
-rw-r--r--runtime/lua/vim/treesitter.lua9
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua9
-rw-r--r--runtime/lua/vim/treesitter/language.lua4
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua46
-rw-r--r--runtime/lua/vim/treesitter/query.lua18
7 files changed, 60 insertions, 36 deletions
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index b6e91e37b9..4e8d2d4202 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -10,13 +10,7 @@ local log = {}
-- Can be used to lookup the number from the name or the name from the number.
-- Levels by name: 'trace', 'debug', 'info', 'warn', 'error'
-- Level numbers begin with 'trace' at 0
-log.levels = {
- TRACE = 0;
- DEBUG = 1;
- INFO = 2;
- WARN = 3;
- ERROR = 4;
-}
+log.levels = vim.log.levels
-- Default log level is warn.
local current_log_level = log.levels.WARN
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index e33e0109b6..00bdeecef3 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -726,7 +726,7 @@ function M.focusable_float(unique_name, fn)
local bufnr = api.nvim_get_current_buf()
do
local win = find_window_by_var(unique_name, bufnr)
- if win and api.nvim_win_is_valid(win) and not vim.fn.pumvisible() then
+ if win and api.nvim_win_is_valid(win) and vim.fn.pumvisible() == 0 then
api.nvim_set_current_win(win)
api.nvim_command("stopinsert")
return
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index 38ac182e32..3af66b134c 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -44,13 +44,18 @@ function M._create_parser(bufnr, lang, opts)
self:_on_bytes(...)
end
- local function detach_cb()
+ local function detach_cb(_, ...)
if parsers[bufnr] == self then
parsers[bufnr] = nil
end
+ self:_on_detach(...)
end
- a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, preview=true})
+ local function reload_cb(_, ...)
+ self:_on_reload(...)
+ end
+
+ a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, on_reload=reload_cb, preview=true})
self:parse()
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 275e960e28..6b833c6d35 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -113,8 +113,9 @@ function TSHighlighter.new(tree, opts)
opts = opts or {}
self.tree = tree
tree:register_cbs {
- on_changedtree = function(...) self:on_changedtree(...) end,
- on_bytes = function(...) self:on_bytes(...) end
+ on_changedtree = function(...) self:on_changedtree(...) end;
+ on_bytes = function(...) self:on_bytes(...) end;
+ on_detach = function(...) self:on_detach(...) end;
}
self.bufnr = tree:source()
@@ -176,6 +177,10 @@ function TSHighlighter:on_bytes(_, _, start_row, _, _, _, _, _, new_end)
a.nvim__buf_redraw_range(self.bufnr, start_row, start_row + new_end + 1)
end
+function TSHighlighter:on_detach()
+ self:destroy()
+end
+
function TSHighlighter:on_changedtree(changes)
for _, ch in ipairs(changes or {}) do
a.nvim__buf_redraw_range(self.bufnr, ch[1], ch[3]+1)
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index d60cd2d0c7..eed28e0e41 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -2,12 +2,12 @@ local a = vim.api
local M = {}
---- Asserts that the provided language is installed, and optionnaly provide a path for the parser
+--- Asserts that the provided language is installed, and optionally provide a path for the parser
--
-- Parsers are searched in the `parser` runtime directory.
--
-- @param lang The language the parser should parse
--- @param path Optionnal path the parser is located at
+-- @param path Optional path the parser is located at
-- @param silent Don't throw an error if language not found
function M.require_language(lang, path, silent)
if vim._ts_has_language(lang) then
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index c864fe5878..28a87f26c7 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -6,14 +6,14 @@ local LanguageTree = {}
LanguageTree.__index = LanguageTree
-- Represents a single treesitter parser for a language.
--- The language can contain child languages with in it's range,
+-- The language can contain child languages with in its range,
-- hence the tree.
--
-- @param source Can be a bufnr or a string of text to parse
-- @param lang The language this tree represents
-- @param opts Options table
--- @param opts.queries A table of language to injection query strings
--- This is useful for overridding the built in runtime file
+-- @param opts.queries A table of language to injection query strings.
+-- This is useful for overriding the built-in runtime file
-- searching for the injection language query per language.
function LanguageTree.new(source, lang, opts)
language.require_language(lang)
@@ -21,8 +21,8 @@ function LanguageTree.new(source, lang, opts)
local custom_queries = opts.queries or {}
local self = setmetatable({
- _source=source,
- _lang=lang,
+ _source = source,
+ _lang = lang,
_children = {},
_regions = {},
_trees = {},
@@ -35,6 +35,7 @@ function LanguageTree.new(source, lang, opts)
_callbacks = {
changedtree = {},
bytes = {},
+ detach = {},
child_added = {},
child_removed = {}
},
@@ -44,12 +45,17 @@ function LanguageTree.new(source, lang, opts)
return self
end
--- Invalidates this parser and all it's children
-function LanguageTree:invalidate()
+-- Invalidates this parser and all its children
+function LanguageTree:invalidate(reload)
self._valid = false
+ -- buffer was reloaded, reparse all trees
+ if reload then
+ self._trees = {}
+ end
+
for _, child in ipairs(self._children) do
- child:invalidate()
+ child:invalidate(reload)
end
end
@@ -97,7 +103,7 @@ function LanguageTree:parse()
self._trees = {}
-- If there are no ranges, set to an empty list
- -- so the included ranges in the parser ar cleared.
+ -- so the included ranges in the parser are cleared.
if self._regions and #self._regions > 0 then
for i, ranges in ipairs(self._regions) do
local old_tree = old_trees[i]
@@ -214,7 +220,7 @@ function LanguageTree:remove_child(lang)
end
end
--- Destroys this language tree and all it's children.
+-- Destroys this language tree and all its children.
-- Any cleanup logic should be performed here.
-- Note, this DOES NOT remove this tree from a parent.
-- `remove_child` must be called on the parent to remove it.
@@ -241,7 +247,7 @@ end
--
-- Note, this call invalidates the tree and requires it to be parsed again.
--
--- @param regions A list of regions this tree should manange and parse.
+-- @param regions A list of regions this tree should manage and parse.
function LanguageTree:set_included_regions(regions)
-- Transform the tables from 4 element long to 6 element long (with byte offset)
for _, region in ipairs(regions) do
@@ -397,14 +403,24 @@ function LanguageTree:_on_bytes(bufnr, changed_tick,
new_row, new_col, new_byte)
end
+function LanguageTree:_on_reload()
+ self:invalidate(true)
+end
+
+
+function LanguageTree:_on_detach(...)
+ self:invalidate(true)
+ self:_do_callback('detach', ...)
+end
+
--- Registers callbacks for the parser
-- @param cbs An `nvim_buf_attach`-like table argument with the following keys :
-- `on_bytes` : see `nvim_buf_attach`, but this will be called _after_ the parsers callback.
--- `on_changedtree` : a callback that will be called everytime the tree has syntactical changes.
+-- `on_changedtree` : a callback that will be called every time the tree has syntactical changes.
-- it will only be passed one argument, that is a table of the ranges (as node ranges) that
-- changed.
-- `on_child_added` : emitted when a child is added to the tree.
--- `on_child_removed` : emitted when a child is remvoed from the tree.
+-- `on_child_removed` : emitted when a child is removed from the tree.
function LanguageTree:register_cbs(cbs)
if not cbs then return end
@@ -416,6 +432,10 @@ function LanguageTree:register_cbs(cbs)
table.insert(self._callbacks.bytes, cbs.on_bytes)
end
+ if cbs.on_detach then
+ table.insert(self._callbacks.detach, cbs.on_detach)
+ end
+
if cbs.on_child_added then
table.insert(self._callbacks.child_added, cbs.on_child_added)
end
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index e49f54681d..8b94348994 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -111,7 +111,7 @@ end
--- Gets the text corresponding to a given node
-- @param node the node
--- @param bufnr the buffer from which the node in extracted.
+-- @param bufnr the buffer from which the node is extracted.
function M.get_node_text(node, source)
local start_row, start_col, start_byte = node:start()
local end_row, end_col, end_byte = node:end_()
@@ -215,10 +215,10 @@ predicate_handlers["vim-match?"] = predicate_handlers["match?"]
local directive_handlers = {
["set!"] = function(_, _, _, pred, metadata)
if #pred == 4 then
- -- (set! @capture "key" "value")
+ -- (#set! @capture "key" "value")
metadata[pred[2]][pred[3]] = pred[4]
else
- -- (set! "key" "value")
+ -- (#set! "key" "value")
metadata[pred[2]] = pred[3]
end
end,
@@ -245,7 +245,7 @@ local directive_handlers = {
end
}
---- Adds a new predicates to be used in queries
+--- Adds a new predicate to be used in queries
--
-- @param name the name of the predicate, without leading #
-- @param handler the handler function to be used
@@ -355,10 +355,10 @@ end
--- Iterates of the captures of self on a given range.
--
--- @param node The node under witch the search will occur
+-- @param node The node under which the search will occur
-- @param buffer The source buffer to search
-- @param start The starting line of the search
--- @param stop The stoping line of the search (end-exclusive)
+-- @param stop The stopping line of the search (end-exclusive)
--
-- @returns The matching capture id
-- @returns The captured node
@@ -388,12 +388,12 @@ function Query:iter_captures(node, source, start, stop)
return iter
end
---- Iterates of the matches of self on a given range.
+--- Iterates the matches of self on a given range.
--
--- @param node The node under witch the search will occur
+-- @param node The node under which the search will occur
-- @param buffer The source buffer to search
-- @param start The starting line of the search
--- @param stop The stoping line of the search (end-exclusive)
+-- @param stop The stopping line of the search (end-exclusive)
--
-- @returns The matching pattern id
-- @returns The matching match