aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorSteven Sojka <Steven.Sojka@tdameritrade.com>2020-06-15 07:05:20 -0500
committerSteven Sojka <Steven.Sojka@tdameritrade.com>2020-06-15 07:05:20 -0500
commit4551b0e1c914f8f0dabdec4010c86c163c08fee2 (patch)
tree09f781e5970756fb5a092a37fcbc4274f9664b10 /lua
parentfeat(queries): add typescript and javascript queries (diff)
parentMerge pull request #63 from theHamsta/cpp-locals (diff)
downloadnvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar.gz
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar.bz2
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar.lz
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar.xz
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.tar.zst
nvim-treesitter-4551b0e1c914f8f0dabdec4010c86c163c08fee2.zip
Merge branch 'master' into feat/typescript-queries
* master: Change regexes in C/C++ highlights Update C/C++ highlights to new query syntax Add better highlighting for preprocessor functions in C highlights Add operators /=,*=,|=,&= to C highlights Add compound_statement to c queries Add punctuation.bracket/punctuation.delimiter to C highlights Make =,~,! operators in C highlights Add cpp/locals.scm Add @error highlight to c/highlights.scm Add C++ highlights.scm Introduce base languages for queries Add tree-sitter-regex feat(queries): allow for user overrides Update issue templates
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua7
-rw-r--r--lua/nvim-treesitter/query.lua35
2 files changed, 38 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index f79fed00c..f7b5ff2cf 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -203,6 +203,13 @@ parsers.nix = {
}
}
+parsers.regex = {
+ install_info = {
+ url = "https://github.com/tree-sitter/tree-sitter-regex",
+ files = { "src/parser.c" }
+ }
+}
+
-- @enable can be true or false
-- @disable is a list of languages, only relevant if enable is true
-- @keymaps list of user mappings for a given module if relevant
diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua
index 644c33933..788bfa126 100644
--- a/lua/nvim-treesitter/query.lua
+++ b/lua/nvim-treesitter/query.lua
@@ -3,14 +3,41 @@ local ts = vim.treesitter
local M = {}
-local function read_query_file(fname)
- return table.concat(vim.fn.readfile(fname), '\n')
+local function read_query_files(filenames)
+ local contents = {}
+
+ for _,filename in ipairs(filenames) do
+ vim.list_extend(contents, vim.fn.readfile(filename))
+ end
+
+ return table.concat(contents, '\n')
end
+-- Some treesitter grammars extend others.
+-- We can use that to import the queries of the base language
+M.base_language_map = {
+ cpp = {'c'},
+ typescript = {'javascript'},
+ tsx = {'typescript', 'javascript'},
+}
+
function M.get_query(ft, query_name)
- local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), false)
+ local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), true)
+ local query_string = ''
+
if #query_files > 0 then
- return ts.parse_query(ft, read_query_file(query_files[1]))
+ query_string = read_query_files(query_files)..query_string
+ end
+
+ for _, base_lang in ipairs(M.base_language_map[ft] or {}) do
+ local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), false)
+ if base_files and #base_files > 0 then
+ query_string = read_query_files(base_files)..query_string
+ end
+ end
+
+ if #query_string > 0 then
+ return ts.parse_query(ft, query_string)
end
end