diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-07-16 17:17:42 +0200 |
---|---|---|
committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-08-13 20:30:15 +0200 |
commit | 18c0e775286aa6621d9190db8cf02e65a3f3d61f (patch) | |
tree | 8a53b4e0c7dc4bf78a310878a61bac00a4da08a1 /runtime/lua/vim | |
parent | 613068071e02ddf5958fa82974373c370112c5e6 (diff) | |
download | rneovim-18c0e775286aa6621d9190db8cf02e65a3f3d61f.tar.gz rneovim-18c0e775286aa6621d9190db8cf02e65a3f3d61f.tar.bz2 rneovim-18c0e775286aa6621d9190db8cf02e65a3f3d61f.zip |
treesitter(docs): update and refresh docs
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 9 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 10 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/language.lua | 13 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 23 |
4 files changed, 46 insertions, 9 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index f43c8a872d..550dee1e3f 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -10,6 +10,12 @@ local parsers = {} local Parser = {} Parser.__index = Parser +--- Parses the buffer if needed and returns a tree. +-- +-- Calling this will call the on_changedtree callbacks if the tree has changed. +-- +-- @returns An up to date tree +-- @returns If the tree changed with this call, the changed ranges function Parser:parse() if self.valid then return self.tree @@ -40,6 +46,9 @@ function Parser:_on_lines(bufnr, changed_tick, start_row, old_stop_row, stop_row end end +--- Sets the included ranges for the current parser +-- +-- @param ranges A table of nodes that will be used as the ranges the parser should include. function Parser:set_included_ranges(ranges) self._parser:set_included_ranges(ranges) -- The buffer will need to be parsed again later diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index b410f01092..681d2c6324 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -7,9 +7,6 @@ local ts_hs_ns = a.nvim_create_namespace("treesitter_hl") -- These are conventions defined by tree-sitter, though it -- needs to be user extensible also. --- TODO(bfredl): this is very much incomplete, we will need to --- go through a few tree-sitter provided queries and decide --- on translations that makes the most sense. TSHighlighter.hl_map = { ["error"] = "Error", @@ -112,11 +109,8 @@ function TSHighlighter:set_query(query) query = vim.treesitter.get_query(self.parser.lang, 'highlights') if query == nil then - a.err_writeln("No highlights.scm query found for " .. self.parser.lang) - - if query == nil then - query = vim.treesitter.parse_query(self.parser.lang, "") - end + a.nvim_err_writeln("No highlights.scm query found for " .. self.parser.lang) + query = vim.treesitter.parse_query(self.parser.lang, "") end end diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua index b4817de91e..a7e36a0b89 100644 --- a/runtime/lua/vim/treesitter/language.lua +++ b/runtime/lua/vim/treesitter/language.lua @@ -2,6 +2,12 @@ local a = vim.api local M = {} +--- Asserts that the provided language is installed, and optionnaly 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 function M.require_language(lang, path) if vim._ts_has_language(lang) then return true @@ -11,13 +17,18 @@ function M.require_language(lang, path) local paths = a.nvim_get_runtime_file(fname, false) if #paths == 0 then -- TODO(bfredl): help tag? - error("no parser for '"..lang.."' language") + error("no parser for '"..lang.."' language, see :help treesitter-parsers") end path = paths[1] end vim._ts_add_language(path, lang) end +--- Inspects the provided language. +-- +-- Inspecting provides some useful informations on the language like node names, ... +-- +-- @param lang The language. function M.inspect_language(lang) M.require_language(lang) return vim._ts_inspect_language(lang) diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 914c266426..d16e1c3662 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -67,6 +67,11 @@ local predicate_handlers = { end, } +--- Adds a new predicates to be used in queries +-- +-- @param name the name of the predicate, without leading # +-- @param handler the handler function to be used +-- signature will be (match, pattern, bufnr, predicate) function M.add_predicate(name, handler) if predicate_handlers[name] then a.nvim_err_writeln("It is recomended to not overwrite predicates.") @@ -93,6 +98,15 @@ function Query:match_preds(match, pattern, bufnr) return true end +--- Iterates of the captures of self on a given range. +-- +-- @param node The node under witch 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) +-- +-- @returns The matching capture id +-- @returns The captured node function Query:iter_captures(node, bufnr, start, stop) if bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() @@ -112,6 +126,15 @@ function Query:iter_captures(node, bufnr, start, stop) return iter end +--- Iterates of the matches of self on a given range. +-- +-- @param node The node under witch 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) +-- +-- @returns The matching pattern id +-- @returns The matching match function Query:iter_matches(node, bufnr, start, stop) if bufnr == 0 then bufnr = vim.api.nvim_get_current_buf() |