diff --git a/README.md b/README.md index cdc1106..830770e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # dotfiles +## Requirements +- Neovim 0.12.0+ + ## How to use ```sh bash -c "$(curl -fsSL https://raw.githubusercontent.com/vmarlier/dotfiles/main/install.sh)" ``` + +## Neovim + +The Neovim configuration uses **native Tree-sitter support** (Neovim 0.12+) instead of the archived `nvim-treesitter` plugin. All required language parsers are installed automatically on the first run — no manual `:TSInstall` commands needed. diff --git a/nvim/lua/config/index.lua b/nvim/lua/config/index.lua index 53bbe5b..a749ff8 100644 --- a/nvim/lua/config/index.lua +++ b/nvim/lua/config/index.lua @@ -4,3 +4,4 @@ require("config.lazy") require("config.options") require("config.mappings") +require("config.treesitter") diff --git a/nvim/lua/config/treesitter.lua b/nvim/lua/config/treesitter.lua new file mode 100644 index 0000000..6dd1cd1 --- /dev/null +++ b/nvim/lua/config/treesitter.lua @@ -0,0 +1,85 @@ +----------------------------------- +-- Maintainer: Valentin Marlier -- +----------------------------------- +-- Native Tree-sitter configuration for Neovim 0.12+ +-- Replaces the archived nvim-treesitter plugin. + +-- All parsers to ensure are installed automatically. +local ensure_installed = { + "bash", + "diff", + "dockerfile", + "go", + "gomod", + "gosum", + "gowork", + "hcl", + "helm", + "json", + "lua", + "markdown", + "regex", + "terraform", + "yaml", + -- prop tech project + -- Core Logic: Highlighting for TypeScript, TSX, and JavaScript + "typescript", + "tsx", + "javascript", + -- Mobile Support: Syntax parsing for the project's Dart files + "dart", + -- Database: Highlighting for Ledger migrations and Kysely SQL snippets + "sql", + -- Config: Support for Firebase, TSConfig, and Package JSON files + "json5", +} + +-- Auto-install any missing parsers on startup (non-blocking). +local function install_missing_parsers() + for _, lang in ipairs(ensure_installed) do + local already_loaded = pcall(vim.treesitter.language.require_language, lang, nil, true) + if not already_loaded then + -- Use the native Neovim 0.12 API to install the parser. + pcall(vim.treesitter.language.install, lang) + end + end +end + +-- Run parser installation after the UI is ready so it doesn't block startup. +vim.api.nvim_create_autocmd("VimEnter", { + once = true, + callback = function() + install_missing_parsers() + end, +}) + +-- Enable Tree-sitter-based syntax highlighting for every buffer. +vim.api.nvim_create_autocmd("FileType", { + callback = function(ev) + local ok = pcall(vim.treesitter.start, ev.buf) + if not ok then + -- Silently fall back to legacy regex highlighting when no parser is + -- available for the current filetype. + end + end, +}) + +-- Incremental selection keymaps (replaces nvim-treesitter's incremental_selection). +-- – init / expand selection; – shrink selection (visual mode). +vim.keymap.set({ "n", "x" }, "", function() + local ok, sel = pcall(require, "vim.treesitter.incremental_selection") + if ok and sel then + if vim.fn.mode() == "n" then + sel.init_selection() + else + sel.node_incremental() + end + end +end, { noremap = true, silent = true, desc = "Increment Tree-sitter selection" }) + +vim.keymap.set("x", "", function() + local ok, sel = pcall(require, "vim.treesitter.incremental_selection") + if ok and sel then + sel.node_decremental() + end +end, { noremap = true, silent = true, desc = "Decrement Tree-sitter selection" }) diff --git a/nvim/lua/plugins/core.lua b/nvim/lua/plugins/core.lua index de9885a..8c8b03e 100644 --- a/nvim/lua/plugins/core.lua +++ b/nvim/lua/plugins/core.lua @@ -269,79 +269,4 @@ return { }, }, - { -- Syntax highlighting and code parsing - "nvim-treesitter/nvim-treesitter", - version = "v0.10.0", -- Use latest for best language support - build = ":TSUpdate", - event = { "BufReadPost", "BufNewFile" }, - lazy = vim.fn.argc(-1) == 0, - - init = function(plugin) - require("lazy.core.loader").add_to_rtp(plugin) - pcall(require, "nvim-treesitter.query_predicates") - end, - - cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" }, - - keys = { - { "", desc = "Increment Selection" }, - { "", desc = "Decrement Selection", mode = "x" }, - }, - - opts_extend = { "ensure_installed" }, - - opts = { - highlight = { - enable = true, - additional_vim_regex_highlighting = false -- Better performance - }, - indent = { enable = true }, - - -- Organize language list alphabetically - ensure_installed = { - "bash", - "diff", - "dockerfile", - "go", - "gomod", - "gosum", - "gowork", - "hcl", - "helm", - "json", - "lua", - "markdown", - "regex", - "terraform", - "yaml", - - -- prop tech project - -- Core Logic: Highlighting for TypeScript, TSX, and JavaScript - "typescript", "tsx", "javascript", - -- Mobile Support: Syntax parsing for the project's Dart files - "dart", - -- Database: Highlighting for Ledger migrations and Kysely SQL snippets - "sql", - -- Config: Support for Firebase, TSConfig, and Package JSON files - "json", "json5", - }, - - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = false, - node_decremental = "", - }, - }, - }, - - config = function(_, opts) - local ok, configs = pcall(require, "nvim-treesitter.configs") - if ok then - configs.setup(opts) - end - end - }, }