aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-04-19 17:54:27 +0200
committerThomas Vigouroux <tomvig38@gmail.com>2020-04-19 17:55:38 +0200
commitd169c0614c55c69afd1cc880b6bef004e4184aa7 (patch)
treede7c44f256a357d9ce063a0be2ce5e44d3839355 /lua
parentstyle: avoid overindenting things (diff)
downloadnvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar.gz
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar.bz2
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar.lz
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar.xz
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.tar.zst
nvim-treesitter-d169c0614c55c69afd1cc880b6bef004e4184aa7.zip
fix: prepare injections mechanism
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/locals.lua2
-rw-r--r--lua/nvim-treesitter/parsers.lua10
2 files changed, 8 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua
index d4a23d65a..e58e5fc58 100644
--- a/lua/nvim-treesitter/locals.lua
+++ b/lua/nvim-treesitter/locals.lua
@@ -20,7 +20,7 @@ function M.collect_locals(bufnr)
if not ft then return end
local query = queries.get_query(ft, 'locals')
- local parser = parsers.get_parser(bufnr)
+ local parser = parsers.get_parser(bufnr, ft)
if not parser then return end
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index c85177733..e046ca45c 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -8,13 +8,17 @@ function M.has_parser(lang)
return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0
end
-function M.get_parser(bufnr)
+function M.get_parser(bufnr, lang)
if M.has_parser() then
local buf = bufnr or api.nvim_get_current_buf()
+ local lang = lang or api.nvim_buf_get_option(buf, 'ft')
if not M[buf] then
- M[buf] = ts.get_parser(buf)
+ M[buf] = {}
end
- return M[buf]
+ if not M[buf][lang] then
+ M[buf][lang] = ts.get_parser(buf, lang)
+ end
+ return M[buf][lang]
end
end