From 4f33ea54ab3807c911c61e7b732c4d36afbe4f42 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Mon, 22 May 2023 18:05:21 +0300 Subject: [PATCH] add detection of uci files --- init.lua | 1 + lua/personal/uci.lua | 31 +++++++++++++++++++++++++++++++ queries/uci/highlights.scm | 4 ++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 lua/personal/uci.lua diff --git a/init.lua b/init.lua index 05f0d2a..92deaba 100644 --- a/init.lua +++ b/init.lua @@ -17,6 +17,7 @@ require("bindings") require("personal.pludin-dev") require("personal.add-guard") require("personal.cmacro-align") +require("personal.uci") -- THEME_BEGIN cmd("colorscheme srcery") diff --git a/lua/personal/uci.lua b/lua/personal/uci.lua new file mode 100644 index 0000000..bb288e7 --- /dev/null +++ b/lua/personal/uci.lua @@ -0,0 +1,31 @@ + +-- Setup tree sitter +local parser_config = require("nvim-treesitter.parsers").get_parser_configs() +parser_config.uci = { + install_info = { + url = "git@rpuzonas.com:rpuzonas/tree-sitter-uci.git", + files = {"src/parser.c"}, + branch = "main", + generate_requires_npm = false, + requires_generate_from_grammar = false, + }, + filetype = "uci", +} + +-- Determine UCI filetype by contents of file. +-- If file has no extension and at least one line contains the word "config" +vim.filetype.add({ + pattern = { + [".*/etc/config/.*"] = "uci", + [".*/[^%.]+"] = { + priority = -math.huge, + function(_, bufnr) + for _, line in ipairs(vim.filetype.getlines(bufnr)) do + if line:find("config") ~= nil then + return "uci" + end + end + end + } + } +}) diff --git a/queries/uci/highlights.scm b/queries/uci/highlights.scm index eebc621..01610c2 100644 --- a/queries/uci/highlights.scm +++ b/queries/uci/highlights.scm @@ -1,8 +1,8 @@ ; This is mandatory to have, If I want "https://git.rpuzonas.com/rpuzonas/tree-sitter-uci" to work :/ "package" @keyword "config" @keyword -"option" @keyword -"list" @keyword +"option" @type +"list" @type (name) @string (string) @string