diff options
| author | Kiyan Yazdani <yazdani.kiyan@protonmail.com> | 2020-04-22 22:22:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-22 22:22:46 +0200 |
| commit | ee5e88dca242a3c9143b69af5811f5152175f574 (patch) | |
| tree | 0733f9d1bcd18f3afb853a74be77fb656d9bf1aa /lua | |
| parent | 8bb53c93d050cbc8c52db6972300de650c34b3a7 (diff) | |
| parent | f7424d23a143553552d238ae83b4fad8e99b32e0 (diff) | |
Merge pull request #7 from vigoux/feature/highlight
Syntax highlighting
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter.lua | 3 | ||||
| -rw-r--r-- | lua/nvim-treesitter/highlight.lua | 19 | ||||
| -rw-r--r-- | lua/nvim-treesitter/query.lua | 2 |
3 files changed, 23 insertions, 1 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 8f2fa05e..b053f39b 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -3,6 +3,7 @@ local parsers = require'nvim-treesitter.parsers' local configs = require 'nvim-treesitter.configs' local install = require'nvim-treesitter.install' local locals = require'nvim-treesitter.locals' +local highlight = require'nvim-treesitter.highlight' local M = {} @@ -14,6 +15,8 @@ end -- this is the main interface through the plugin function M.setup(lang) if parsers.has_parser(lang) then + local autocmd = "autocmd NvimTreesitter FileType %s lua require'nvim-treesitter.highlight'.setup()" + api.nvim_command(string.format(autocmd, lang)) end end diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua new file mode 100644 index 00000000..110954a6 --- /dev/null +++ b/lua/nvim-treesitter/highlight.lua @@ -0,0 +1,19 @@ +local api = vim.api +local queries = require'nvim-treesitter.query' +local ts = vim.treesitter + +local M = { + highlighters={} +} + +function M.setup(bufnr, ft) + local buf = bufnr or api.nvim_get_current_buf() + local ft = ft or api.nvim_buf_get_option(buf, 'ft') + + local query = queries.get_query(ft, "highlights") + if not query then return end + + M.highlighters[buf] = ts.TSHighlighter.new(query, buf, ft) +end + +return M diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index e9f671f9..277c2969 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -62,7 +62,7 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row) local preds = query.info.patterns[pattern] if preds then for _, pred in pairs(preds) do - if pred[1] == "set!" and pred[2] ~= nil then + if pred[1] == "set!" and type(pred[2]) == "string" then insert_to_path(prepared_match, split(pred[2]), pred[3]) end end |
