diff --git a/.config/nvim/.gitignore b/.config/nvim/.gitignore deleted file mode 100644 index a2da31c..0000000 --- a/.config/nvim/.gitignore +++ /dev/null @@ -1 +0,0 @@ -plugin/ \ No newline at end of file diff --git a/.config/nvim/after/plugin/treesitter.lua b/.config/nvim/after/plugin/treesitter.lua new file mode 100644 index 0000000..81b7be0 --- /dev/null +++ b/.config/nvim/after/plugin/treesitter.lua @@ -0,0 +1,46 @@ +-- Configure nvim-treesitter with defaults +require("nvim-treesitter").setup() + +-- Register the custom x12 parser for the nvim-treesitter main branch API +vim.api.nvim_create_autocmd("User", { + pattern = "TSUpdate", + callback = function() + require("nvim-treesitter.parsers").x12 = { + install_info = { + url = "https://github.com/hugginsio/tree-sitter-x12", + files = {"src/parser.c"}, + branch = "main", + generate_requires_npm = false, + requires_generate_from_grammar = false + }, + filetype = "x12" + } + end +}) + +-- Explicitly trigger installation for the required parsers +require("nvim-treesitter").install({"bash", "c", "c_sharp", "diff", "go", "html", "javascript", "jsdoc", "json", "lua", + "luadoc", "luap", "markdown", "markdown_inline", "python", "query", "regex", "toml", + "tsx", "typescript", "vim", "vimdoc", "xml", "yaml", "x12"}) + +-- Automatically enable treesitter features for all buffers +local ts_group = vim.api.nvim_create_augroup("TreesitterStart", { + clear = true +}) +vim.api.nvim_create_autocmd("FileType", { + group = ts_group, + callback = function(args) + -- Bypass treesitter if the file exceeds 200 MiB + local max_filesize = 200 * 1024 * 1024 + local filepath = vim.api.nvim_buf_get_name(args.buf) + local ok, stats = pcall(vim.uv.fs_stat, filepath) + + if ok and stats and stats.size > max_filesize then + return + end + + -- Start treesitter highlighting + -- Using pcall prevents errors if a parser is missing for the current filetype + pcall(vim.treesitter.start, args.buf) + end +}) diff --git a/.config/nvim/after/treestitter.lua b/.config/nvim/after/treestitter.lua deleted file mode 100644 index f9ead24..0000000 --- a/.config/nvim/after/treestitter.lua +++ /dev/null @@ -1,27 +0,0 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "javascript", "typescript", "go", "rust", "c", "lua", "vim", "vimdoc", "query" }, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, - - -- List of parsers to ignore installing (or "all") - -- ignore_install = { "javascript" }, - - ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) - -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! - - highlight = { - enable = true, - - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, -} diff --git a/.config/nvim/lua/cole/filetype.lua b/.config/nvim/lua/cole/filetype.lua new file mode 100644 index 0000000..5c8e541 --- /dev/null +++ b/.config/nvim/lua/cole/filetype.lua @@ -0,0 +1,7 @@ +-- Register custom filetypes for EDI documents +vim.filetype.add({ + extension = { + edi = "x12", + dat = "x12" + } +}) diff --git a/.config/nvim/lua/cole/init.lua b/.config/nvim/lua/cole/init.lua index 7bbfaef..bad9a3d 100644 --- a/.config/nvim/lua/cole/init.lua +++ b/.config/nvim/lua/cole/init.lua @@ -1,4 +1,5 @@ require("cole.remap") require("cole.set") +require("cole.filetype") require("cole.lazy") diff --git a/.config/nvim/queries/x12/highlights.scm b/.config/nvim/queries/x12/highlights.scm new file mode 100644 index 0000000..486d992 --- /dev/null +++ b/.config/nvim/queries/x12/highlights.scm @@ -0,0 +1,10 @@ +(segment_header) @keyword + +[ + (element_separator) + (component_element_separator) + (segment_separator) +] @comment + +(alphanumeric) @string +(numeric) @number