summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/parsers.lua
diff options
context:
space:
mode:
authorkiyan42 <yazdani.kiyan@protonmail.com>2020-06-29 14:46:25 +0200
committerThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-06-29 17:18:22 +0200
commit7f6f7596dac5a45ae914336dc986ebb30881b1a3 (patch)
tree4570e65eca2f5ad56261fcff992f17336b2b5604 /lua/nvim-treesitter/parsers.lua
parenta2f09312540822e9c579fee4534832fefd492250 (diff)
add used_by key to parsers
Enables the use of multiple filetypes for one parser.
Diffstat (limited to 'lua/nvim-treesitter/parsers.lua')
-rw-r--r--lua/nvim-treesitter/parsers.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 9097d335..7fa09df9 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -64,6 +64,7 @@ list.bash = {
url = "https://github.com/tree-sitter/tree-sitter-bash",
files = { "src/parser.c", "src/scanner.cc" },
},
+ used_by = { "zsh" },
filetype = 'sh'
}
@@ -205,10 +206,10 @@ list.nix = {
}
list.regex = {
- install_info = {
- url = "https://github.com/tree-sitter/tree-sitter-regex",
- files = { "src/parser.c" }
- }
+ install_info = {
+ url = "https://github.com/tree-sitter/tree-sitter-regex",
+ files = { "src/parser.c" }
+ }
}
local M = {
@@ -216,12 +217,14 @@ local M = {
}
local ft_to_parsername = {}
+
for name, obj in pairs(M.list) do
- if obj.filetype then
- ft_to_parsername[obj.filetype] = name
- else
- ft_to_parsername[name] = name
+ if type(obj.used_by) == 'table' then
+ for _, ft in pairs(obj.used_by) do
+ ft_to_parsername[ft] = name
+ end
end
+ ft_to_parsername[obj.filetype or name] = name
end
function M.ft_to_lang(ft)
@@ -229,7 +232,17 @@ function M.ft_to_lang(ft)
end
function M.lang_to_ft(lang)
- return M.list[lang].filetype or lang
+ local obj = M.list[lang]
+ return vim.tbl_flatten({{obj.filetype or lang}, obj.used_by or {}})
+end
+
+function M.lang_match_ft(lang, ft)
+ for _, f in pairs(M.lang_to_ft(lang)) do
+ if ft == f then
+ return true
+ end
+ end
+ return false
end
function M.available_parsers()