Merge pull request #7 from vigoux/feature/highlight

Syntax highlighting
This commit is contained in:
Kiyan Yazdani 2020-04-22 22:22:46 +02:00 committed by GitHub
commit ee5e88dca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,60 @@
;;; Highlighting for lua
;;; Builtins
;; Keywords
"local" @keyword
"if" @keyword
"then" @keyword
"else" @keyword
"elseif" @keyword
"end" @keyword
"return" @keyword
"do" @keyword
"while" @keyword
"repeat" @keyword
"for" @keyword
(break_statement) @keyword
"goto" @keyword
;; Operators
"~=" @operator
"==" @operator
"<=" @operator
">=" @operator
"not" @operator
"and" @operator
"or" @operator
"<" @operator
">" @operator
"+" @operator
"-" @operator
"%" @operator
"/" @operator
"//" @operator
"*" @operator
"^" @operator
"&" @operator
"~" @operator
"|" @operator
">>" @operator
"<<" @operator
".." @operator
"#" @operator
;; Constants
(false) @constant
(true) @constant
(nil) @constant
(spread) @constant ;; "..."
;; Nodes
(function "function" @function "end" @function)
(table "{" @operator "}" @operator)
(comment) @comment
(string) @string
(number) @number
(label_statement) @label
;; Error
(ERROR) @Error