mirror of
https://github.com/itme-brain/nvim.git
synced 2026-05-08 07:00:13 -04:00
Compare commits
No commits in common. "ef4972deb980915b328958b469cc280fd2bb7a68" and "376b9c5c16b9d8b121b73516219082e57b397bc9" have entirely different histories.
ef4972deb9
...
376b9c5c16
7 changed files with 183 additions and 176 deletions
19
README.md
19
README.md
|
|
@ -1,6 +1,6 @@
|
|||
# Neovim Configuration
|
||||
|
||||
Portable Neovim configuration using lazy.nvim, Mason-managed tooling, native LSP, native Treesitter, Telescope, and DAP (Neovim 0.11+, tested on 0.12.1).
|
||||
Portable Neovim configuration using lazy.nvim, Mason-managed tooling, native LSP, Treesitter, Telescope, and DAP (Neovim 0.11+, tested on 0.12.1).
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ git clone --recurse-submodules git@github.com:itme-brain/nixos.git
|
|||
- **Native LSP** (`vim.lsp.config` / `vim.lsp.enable`) - no manual server list needed
|
||||
- **Smart LSP picker** (`<leader>css`) - auto-detects installed servers for current filetype
|
||||
- **Neovim 0.12 compatible** - uses built-in `:lsp` commands and keeps legacy `:Lsp*` aliases working
|
||||
- **Portable** - Mason is the source of truth for LSP servers and debug adapters
|
||||
- **Treesitter** - uses native `vim.treesitter.*` APIs with community fork provisioning
|
||||
- **Portable** - Mason is the source of truth for LSP servers, debug adapters, and tree-sitter-cli
|
||||
- **Treesitter** - starts via Neovim's native `vim.treesitter.start`
|
||||
- **Debugging** - lazy-loaded `nvim-dap` stack with Mason-managed adapters
|
||||
|
||||
## LSP Setup
|
||||
|
|
@ -43,14 +43,10 @@ On Neovim 0.12+, start/stop/restart uses the built-in `:lsp` commands under the
|
|||
|
||||
## Treesitter
|
||||
|
||||
Treesitter uses Neovim's native API:
|
||||
Treesitter uses the current `nvim-treesitter` main branch API:
|
||||
- Parsers are installed with `nvim-treesitter`
|
||||
- Highlighting starts through `vim.treesitter.start`
|
||||
- Parser/filetype mappings use `vim.treesitter.language.register`
|
||||
- Parsers and queries are provisioned by the community `neovim-treesitter/nvim-treesitter` fork
|
||||
|
||||
Neovim loads compiled parser libraries from `parser/` directories on `runtimepath` and query files from `queries/<language>/`.
|
||||
`tree-sitter-cli` is only needed by the provisioner when installing or updating parsers; it is not required at runtime for highlighting.
|
||||
Mason bootstraps `tree-sitter-cli` when parser installation is needed.
|
||||
- `tree-sitter-cli` is bootstrapped through Mason when needed for parser installs/updates
|
||||
|
||||
## Debugging
|
||||
|
||||
|
|
@ -98,8 +94,7 @@ Mason installs:
|
|||
- **nvim-lspconfig** - LSP configurations
|
||||
- **nvim-cmp** - completion
|
||||
- **telescope.nvim** - fuzzy finder
|
||||
- **Native Treesitter** - syntax highlighting
|
||||
- **neovim-treesitter** - parser and query provisioning
|
||||
- **nvim-treesitter** - syntax highlighting
|
||||
- **nvim-dap** - debug adapter client
|
||||
- **nvim-dap-ui** - debugging UI panes
|
||||
- **mason-nvim-dap.nvim** - Mason debug adapter integration
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
"mason-lspconfig.nvim": { "branch": "main", "commit": "0c2823e0418f3d9230ff8b201c976e84de1cb401" },
|
||||
"mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" },
|
||||
"mason.nvim": { "branch": "main", "commit": "cb8445f8ce85d957416c106b780efd51c6298f89" },
|
||||
"neovim-treesitter": { "branch": "main", "commit": "df7489eeea351bece7fd0f9c825be5cb6a1438f0" },
|
||||
"nvim-dap": { "branch": "master", "commit": "45a69eba683a2c448dd9ecfc4de89511f0646b5f" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "31026a13eefb20681124706a79fc1df6bf11ab27" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "cf12346a3414fa1b06af75c79faebe7f76df080a" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "4fc505ac7bd7692824a142e96e5f529c133862f8" },
|
||||
"oil.nvim": { "branch": "master", "commit": "0fcc83805ad11cf714a949c98c605ed717e0b83e" },
|
||||
"pi.nvim": { "branch": "main", "commit": "6e86a704ed6ff488fda78b64f4e564d6ee620785" },
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
local treesitter_languages = require("config.treesitter_languages")
|
||||
|
||||
for filetype, language in pairs(treesitter_languages.language_by_filetype) do
|
||||
vim.treesitter.language.register(language, filetype)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = vim.api.nvim_create_augroup("config_treesitter", { clear = true }),
|
||||
pattern = treesitter_languages.filetypes,
|
||||
callback = function(event)
|
||||
local language = vim.treesitter.language.get_lang(vim.bo[event.buf].filetype)
|
||||
if not language then
|
||||
return
|
||||
end
|
||||
|
||||
local ok, has_parser = pcall(vim.treesitter.language.add, language)
|
||||
if ok and has_parser then
|
||||
pcall(vim.treesitter.start, event.buf, language)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
M.install_parsers = {
|
||||
"bash",
|
||||
"cpp",
|
||||
"css",
|
||||
"git_config",
|
||||
"git_rebase",
|
||||
"gitattributes",
|
||||
"gitcommit",
|
||||
"gitignore",
|
||||
"html",
|
||||
"javascript",
|
||||
"json",
|
||||
"nix",
|
||||
"python",
|
||||
"rust",
|
||||
"toml",
|
||||
"yaml",
|
||||
}
|
||||
|
||||
M.filetypes = {
|
||||
"lua",
|
||||
"c",
|
||||
"cpp",
|
||||
"python",
|
||||
"nix",
|
||||
"rust",
|
||||
"bash",
|
||||
"markdown",
|
||||
"html",
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"css",
|
||||
"json",
|
||||
"toml",
|
||||
"yaml",
|
||||
"vim",
|
||||
"gitconfig",
|
||||
"gitrebase",
|
||||
"gitattributes",
|
||||
"gitcommit",
|
||||
"gitignore",
|
||||
}
|
||||
|
||||
M.language_by_filetype = {
|
||||
gitconfig = "git_config",
|
||||
gitrebase = "git_rebase",
|
||||
javascriptreact = "javascript",
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
@ -14,7 +14,181 @@ local mason_ensure_installed = {
|
|||
"yamlls", -- YAML
|
||||
}
|
||||
|
||||
local treesitter_parsers = {
|
||||
"lua",
|
||||
"c",
|
||||
"cpp",
|
||||
"python",
|
||||
"nix",
|
||||
"rust",
|
||||
"bash",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"html",
|
||||
"javascript",
|
||||
"css",
|
||||
"vim",
|
||||
"git_config",
|
||||
"git_rebase",
|
||||
"gitattributes",
|
||||
"gitcommit",
|
||||
"gitignore",
|
||||
}
|
||||
|
||||
return {
|
||||
{
|
||||
"neovim-treesitter/nvim-treesitter",
|
||||
name = "nvim-treesitter",
|
||||
dependencies = {
|
||||
"neovim-treesitter/treesitter-parser-registry",
|
||||
"williamboman/mason.nvim",
|
||||
},
|
||||
lazy = false,
|
||||
build = ":TSUpdate",
|
||||
init = function()
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = vim.api.nvim_create_augroup("config_treesitter", { clear = true }),
|
||||
pattern = {
|
||||
"lua",
|
||||
"c",
|
||||
"cpp",
|
||||
"python",
|
||||
"nix",
|
||||
"rust",
|
||||
"bash",
|
||||
"markdown",
|
||||
"html",
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"css",
|
||||
"vim",
|
||||
"gitconfig",
|
||||
"gitrebase",
|
||||
"gitattributes",
|
||||
"gitcommit",
|
||||
"gitignore",
|
||||
},
|
||||
callback = function(event)
|
||||
if pcall(vim.treesitter.start, event.buf) then
|
||||
vim.bo[event.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
config = function()
|
||||
require("nvim-treesitter").setup()
|
||||
|
||||
local function has_c_compiler()
|
||||
return vim.fn.executable("cc") == 1
|
||||
or vim.fn.executable("gcc") == 1
|
||||
or vim.fn.executable("clang") == 1
|
||||
end
|
||||
|
||||
local function install_missing_parsers(missing)
|
||||
if not has_c_compiler() then
|
||||
vim.notify_once(
|
||||
"A C compiler is required to install or update Treesitter parsers",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
require("nvim-treesitter.install").ensure_installed(missing)
|
||||
end
|
||||
|
||||
local function tree_sitter_cli_works()
|
||||
if vim.fn.executable("tree-sitter") == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
local result = vim.system({ "tree-sitter", "--version" }, { text = true }):wait()
|
||||
if result.code == 0 then
|
||||
return true
|
||||
end
|
||||
|
||||
vim.notify_once(
|
||||
"tree-sitter CLI is installed but cannot run. On NixOS, enable nix-ld so Mason-installed binaries can execute.",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return false
|
||||
end
|
||||
|
||||
local function ensure_treesitter_cli(callback)
|
||||
if tree_sitter_cli_works() then
|
||||
callback()
|
||||
return
|
||||
end
|
||||
|
||||
if #vim.api.nvim_list_uis() == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_ok, mason = pcall(require, "mason")
|
||||
local registry_ok, registry = pcall(require, "mason-registry")
|
||||
if not mason_ok or not registry_ok then
|
||||
vim.notify_once(
|
||||
"tree-sitter CLI is required to install or update parsers; install tree-sitter-cli or enable mason.nvim",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
mason.setup()
|
||||
registry.refresh(function()
|
||||
local package_ok, package = pcall(registry.get_package, "tree-sitter-cli")
|
||||
if not package_ok then
|
||||
vim.notify_once(
|
||||
"Mason registry does not include tree-sitter-cli; install tree-sitter-cli before running :TSUpdate",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
if package:is_installed() then
|
||||
if tree_sitter_cli_works() then
|
||||
callback()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if package:is_installing() then
|
||||
vim.notify_once("tree-sitter-cli is already being installed by Mason", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
vim.notify_once("Installing tree-sitter-cli with Mason for Treesitter parser updates", vim.log.levels.INFO)
|
||||
package:install({}, function(success, error)
|
||||
if success and tree_sitter_cli_works() then
|
||||
callback()
|
||||
else
|
||||
vim.notify(
|
||||
"Failed to install tree-sitter-cli with Mason: " .. tostring(error),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
local installed = require("nvim-treesitter.info").installed_parsers()
|
||||
local missing = vim.iter(treesitter_parsers)
|
||||
:filter(function(parser)
|
||||
return not vim.tbl_contains(installed, parser)
|
||||
end)
|
||||
:totable()
|
||||
|
||||
if #missing == 0 and #vim.api.nvim_list_uis() == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
ensure_treesitter_cli(function()
|
||||
if #missing > 0 then
|
||||
install_missing_parsers(missing)
|
||||
end
|
||||
end)
|
||||
end
|
||||
},
|
||||
|
||||
{
|
||||
"m4xshen/autoclose.nvim",
|
||||
config = function()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ return {
|
|||
"MeanderingProgrammer/render-markdown.nvim",
|
||||
ft = { "markdown" },
|
||||
dependencies = {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
"nvim-tree/nvim-web-devicons",
|
||||
},
|
||||
opts = {
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
local treesitter_languages = require("config.treesitter_languages")
|
||||
|
||||
local function tree_sitter_cli_works()
|
||||
if vim.fn.executable("tree-sitter") == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
local result = vim.system({ "tree-sitter", "--version" }, { text = true }):wait()
|
||||
return result.code == 0
|
||||
end
|
||||
|
||||
local function ensure_tree_sitter_cli(callback)
|
||||
if tree_sitter_cli_works() then
|
||||
callback()
|
||||
return
|
||||
end
|
||||
|
||||
if #vim.api.nvim_list_uis() == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local mason_ok, mason = pcall(require, "mason")
|
||||
local registry_ok, registry = pcall(require, "mason-registry")
|
||||
if not mason_ok or not registry_ok then
|
||||
vim.notify_once("tree-sitter CLI is required to install Treesitter parsers", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
mason.setup()
|
||||
registry.refresh(function()
|
||||
local package_ok, package = pcall(registry.get_package, "tree-sitter-cli")
|
||||
if not package_ok then
|
||||
vim.notify_once("Mason registry does not include tree-sitter-cli", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
if package:is_installed() then
|
||||
if tree_sitter_cli_works() then
|
||||
callback()
|
||||
else
|
||||
vim.notify_once("tree-sitter CLI is installed but cannot run", vim.log.levels.WARN)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if package:is_installing() then
|
||||
return
|
||||
end
|
||||
|
||||
package:install({}, function(success, error)
|
||||
if success and tree_sitter_cli_works() then
|
||||
callback()
|
||||
else
|
||||
vim.notify("Failed to install tree-sitter-cli with Mason: " .. tostring(error), vim.log.levels.WARN)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
"neovim-treesitter/nvim-treesitter",
|
||||
name = "neovim-treesitter",
|
||||
dependencies = {
|
||||
"neovim-treesitter/treesitter-parser-registry",
|
||||
"williamboman/mason.nvim",
|
||||
},
|
||||
lazy = false,
|
||||
build = ":TSUpdate",
|
||||
config = function()
|
||||
local treesitter = require("nvim-treesitter")
|
||||
treesitter.setup()
|
||||
|
||||
local installed = treesitter.get_installed("parsers")
|
||||
local missing = vim.iter(treesitter_languages.install_parsers)
|
||||
:filter(function(parser)
|
||||
return not vim.tbl_contains(installed, parser)
|
||||
end)
|
||||
:totable()
|
||||
|
||||
if #missing == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
ensure_tree_sitter_cli(function()
|
||||
treesitter.install(missing)
|
||||
end)
|
||||
end,
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue