feat(home-manager): rework neovim configuration

Use new neovim option introduced in 0.11
This commit is contained in:
Yorick Barbanneau 2025-04-17 23:56:44 +02:00
parent 5ac9a372b9
commit 69493a7d84
No known key found for this signature in database
GPG key ID: 4447A19BBEDB8DBA
13 changed files with 208 additions and 194 deletions

View file

@ -10,13 +10,13 @@ let
url = "https://ftp.nluug.nl/vim/runtime/spell/fr.utf-8.sug";
sha256 = "0294bc32b42c90bbb286a89e23ca3773b7ef50eff1ab523b1513d6a25c6b3f58";
};
yaml-companion = pkgs.vimUtils.buildVimPlugin {
pname = "yaml-companion";
nvim-k8s-lsp = pkgs.vimUtils.buildVimPlugin {
pname = "nvim-k8s-lsp";
version = "main";
src = builtins.fetchGit {
url = "https://github.com/someone-stole-my-name/yaml-companion.nvim.git";
rev = "131b0d67bd2e0f1a02e0daf2f3460482221ce3c0";
ref = "main";
url = "https://github.com/tonychg/nvim-k8s-lsp.git";
rev = "5e8221cce09cb71b7604c0c7469bf9053dd877ca";
ref = "feat/add-helm-ls-support";
};
};
in
@ -27,6 +27,16 @@ in
config = mkIf cfg.enable {
home.file."${config.xdg.configHome}/nvim/spell/fr.utf-8.spl".source = nvim-spell-fr-utf8-dictionary;
home.file."${config.xdg.configHome}/nvim/spell/fr.utf-8.sug".source = nvim-spell-fr-utf8-suggestions;
home.file."${config.xdg.configHome}/nvim/lsp/bash.lua".source = ./files/lsp/bash.lua;
home.file."${config.xdg.configHome}/nvim/lsp/helm.lua".source = ./files/lsp/helm.lua;
home.file."${config.xdg.configHome}/nvim/lsp/lua.lua".source = ./files/lsp/lua.lua;
home.file."${config.xdg.configHome}/nvim/lsp/nills.lua".source = ./files/lsp/nills.lua;
home.file."${config.xdg.configHome}/nvim/lsp/pylsp.lua".source = ./files/lsp/pylsp.lua;
home.file."${config.xdg.configHome}/nvim/lsp/terraformls.lua".source = ./files/lsp/terraformls.lua;
home.file."${config.xdg.configHome}/nvim/lsp/tflint.lua".source = ./files/lsp/tflint.lua;
home.file."${config.xdg.configHome}/nvim/lsp/yaml.lua".source = ./files/lsp/yaml.lua;
programs.neovim = {
enable = true;
defaultEditor = true;
@ -103,16 +113,6 @@ in
}
'';
}
{
plugin = lsp_lines-nvim;
type = "lua";
config = (builtins.readFile ./files/lsp-line.lua);
}
{
plugin = nvim-lspconfig;
type = "lua";
config = (builtins.readFile ./files/lspconfig.lua);
}
{
plugin = lualine-nvim;
type = "lua";
@ -197,12 +197,9 @@ in
config = ( builtins.readFile ./files/whichkey.lua );
}
{
plugin = yaml-companion.overrideAttrs {
dependencies = [
nvim-lspconfig
];
};
plugin = nvim-k8s-lsp ;
type = "lua";
config = ( builtins.readFile files/nvim-k8s-lsp.lua );
}
vim-helm
];

View file

@ -0,0 +1,17 @@
return {
cmd = { 'bash-language-server', 'start' },
settings = {
bashIde = {
-- Glob pattern for finding and parsing shell script files in the workspace.
-- Used by the background analysis features across files.
-- Prevent recursive scanning which will cause issues when opening a file
-- directly in the home directory (e.g. ~/foo.sh).
--
-- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
},
},
filetypes = { 'bash', 'sh' },
root_markers = { '.git' },
}

View file

@ -0,0 +1,30 @@
return {
cmd = { 'helm_ls', 'serve' },
filetypes = { 'helm' },
root_markers = { 'Chart.yaml' },
capabilities = {
workspace = {
didChangeWatchedFiles = {
dynamicRegistration = true,
},
},
},
settings = {
['helm-ls'] = {
yamlls = {
enabled = true,
enabledforfilesglob = "*.{yaml,yml}",
diagnosticslimit = 50,
showdiagnosticsdirectly = false,
path = "yaml-language-server",
config = {
schemas = {
kubernetes = "template/**",
},
completion = true,
hover = true,
}
}
}
}
}

View file

@ -0,0 +1,32 @@
return {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = {
'.luarc.json',
'.luarc.jsonc',
'.luacheckrc',
'.stylua.toml',
'stylua.toml',
'selene.toml',
'selene.yml',
'.git',
},
settings = {
Lua = {
diagnostics = {
globals = {'vim'} -- Add any globals you want to ignore as undefined
},
workspace = {
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true
}
},
telemetry = {
enable = false -- Disable telemetry
}
}
},
flags = {
debounce_text_changes = 150,
}
}

View file

@ -0,0 +1,5 @@
return {
cmd = { 'marksman' },
filetypes = { 'markdown', 'markdown.mdx' },
root_markers = { '.marksman.toml', '.git' },
}

View file

@ -0,0 +1,15 @@
---@brief
---
-- https://github.com/oxalica/nil
--
-- A new language server for Nix Expression Language.
--
-- If you are using Nix with Flakes support, run `nix profile install github:oxalica/nil` to install.
-- Check the repository README for more information.
--
-- _See an example config at https://github.com/oxalica/nil/blob/main/dev/nvim-lsp.nix._
return {
cmd = { 'nil' },
filetypes = { 'nix' },
root_markers = { 'flake.nix', '.git' },
}

View file

@ -0,0 +1,21 @@
return {
cmd = { 'pylsp' },
filetypes = { 'python' },
root_markers = {
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
'.git',
},
settings = {
pylsp = {
plugins = {
pylint = {
enabled = true
}
}
}
}
}

View file

@ -0,0 +1,5 @@
return {
cmd = { 'terraform-ls', 'serve' },
filetypes = { 'terraform', 'terraform-vars' },
root_markers = { '.terraform', '.git' },
}

View file

@ -0,0 +1,5 @@
return {
cmd = { 'tflint', '--langserver' },
filetypes = { 'terraform' },
root_markers = { '.terraform', '.git', '.tflint.hcl' },
}

View file

@ -0,0 +1,33 @@
-- most used yaml schemas
local gitlab_ci = "https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"
local taskfile = "https://taskfile.dev/schema.json"
local lefthook = "https://raw.githubusercontent.com/evilmartians/lefthook/refs/heads/master/schema.json"
local github_workflow = "https://json.schemastore.org/github-workflow.json"
return {
cmd = { 'yaml-language-server', '--stdio' },
filetypes = { 'yaml', 'yaml.docker-compose', 'yaml.gitlab' },
root_markers = { '.git' },
settings = {
yaml = {
schemas = {
[gitlab_ci] = {
"ci/*.{yaml,yml}",
".gitlab/**/*.{yaml,yml}",
".gitlab-ci.{yaml,yml}",
},
[taskfile] = {
"Taskfile*.{yaml,yml}",
"taskfile*.{yaml,yml}",
"taskfiles/**/*.{yaml,yml}",
},
[lefthook] = {
"lefthook.{yaml,yml}",
},
[github_workflow] = {
".github/workflow/**/*.{yaml,yml}",
}
},
},
},
}

View file

@ -2,10 +2,6 @@ local lspconfig = require('lspconfig')
local capabilities = require("cmp_nvim_lsp").default_capabilities()
require("yaml-companion").open_ui_select()
lspconfig.bashls.setup {
capabilities = capabilities,
}
lspconfig.clangd.setup {
capabilities = capabilities,
}
@ -14,178 +10,8 @@ lspconfig.eslint.setup{
capabilities = capabilities,
}
-- YAML variables and Helm LS (quite big!)
local schemas = {}
local kubernetes = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.29.6-standalone-strict/all.json"
local flux2 = "https://raw.githubusercontent.com/fluxcd-community/flux2-schemas/refs/heads/main/all.json"
local gitlab_ci = "https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json"
local taskfile = "https://taskfile.dev/schema.json"
local podmonitor = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/podmonitor_v1.json"
local servicemonitor = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/servicemonitor_v1.json"
local prometheus = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/monitoring.coreos.com/prometheus_v1.json"
local ingress = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.30.1/ingress-networking-v1.json"
local lefthook = "https://raw.githubusercontent.com/evilmartians/lefthook/refs/heads/master/schema.json"
local github_workflow = "https://json.schemastore.org/github-workflow.json"
schemas[kubernetes] = {
"templates/*deployment.yaml",
"templates/*service.yaml",
"templates/*secret.yaml",
"templates/*configmap.yaml",
"templates/*daemonset.yaml",
"templates/*replicaset.yaml",
"templates/*persistentvolume.yaml",
"templates/*persistentvolumeclaim.yaml",
"templates/*serviceaccount.yaml",
"templates/*role.yaml",
"templates/*rolebinding.yaml",
"templates/*clusterrole.yaml",
"templates/*clusterrolebinding.yaml",
"templates/*job*.yaml",
}
schemas[podmonitor] = "templates/*podmonitor*"
schemas[servicemonitor] = "templates/*servicemonitor*"
schemas[ingress] = "templates/*ingress*"
lspconfig.helm_ls.setup {
capabilities = capabilities,
settings = {
['helm-ls'] = {
yamlls = {
enabled = true,
enabledForFilesGlob = "*.{yaml,yml}",
diagnosticsLimit = 50,
showDiagnosticsDirectly = false,
path = "yaml-language-server",
config = {
schemas = schemas,
completion = true,
hover = true,
}
}
}
}
}
-- restart LSP server avoir problems with Helm-ls
vim.api.nvim_create_autocmd("FileType", {
pattern = "helm",
command = "LspRestart",
})
lspconfig.lua_ls.setup {
capabilities = capabilities,
single_file_support = true,
settings = {
Lua = {
diagnostics = {
globals = {'vim'} -- Add any globals you want to ignore as undefined
},
workspace = {
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true
}
},
telemetry = {
enable = false -- Disable telemetry
}
}
},
flags = {
debounce_text_changes = 150,
}
}
lspconfig.marksman.setup{
capabilities = capabilities,
}
lspconfig.nil_ls.setup {
capabilities = capabilities,
}
lspconfig.pylsp.setup {
capabilities = capabilities,
settings = {
pylsp = {
plugins = {
pylint = {
enabled = true
}
}
}
}
}
lspconfig.terraformls.setup{
capabilities = capabilities,
}
lspconfig.tflint.setup{
capabilities = capabilities,
}
-- YAML configuration (quite big!)
local cfg = require("yaml-companion").setup({
schemas = {
{ name = "Flux2", uri = flux2 },
{ name = "Gitlab", uri = gitlab_ci },
{ name = "Taskfile", uri = taskfile },
{ name = "PodMonitor", uri = podmonitor },
{ name = "ServiceMonitor", uri = servicemonitor },
{ name = "Prometheus", uri = prometheus },
{ name = "Kubernetes", uri = kubernetes },
{ name = "Lefthook", uri = lefthook },
{ name = "Github Workflow", uri = github_workflow},
},
lspconfig = {
capabilities = capabilities,
settings = {
yaml = {
schemas = {
[flux2] = {
"*.{alert,provider,receiver,helmrelease,helmrepository,gitrepository}.yaml",
"gotk-sync.yaml",
"gotk-*.yaml",
},
[gitlab_ci] = {
"ci/*.{yaml,yml}",
".gitlab/**/*.{yaml,yml}",
".gitlab-ci.{yaml,yml}",
},
[taskfile] = {
"Taskfile*.{yaml,yml}",
"taskfile*.{yaml,yml}",
"taskfiles/**/*.{yaml,yml}",
},
[podmonitor] = {
"*podmonitor*.{yaml,yml}",
},
[servicemonitor] = {
"*servicemonitor*.{yaml,yml}",
},
[prometheus] = {
"*prometheus*.{yaml,yml}",
},
[ingress] = {
"*ingress*.{yaml,yml}",
},
[lefthook] = {
"lefthook.{yaml,yml}",
},
[github_workflow] = {
".github/workflow/**/*.{yaml,yml}",
}
},
},
},
},
})
lspconfig.yamlls.setup{cfg}
vim.api.nvim_create_autocmd('LspAttach', {
desc = 'LSP actions',
callback = function(ev)

View file

@ -0,0 +1,6 @@
require("nvim-k8s-lsp").setup({
kubernetes_version = "v1.32.2",
integrations = {
lualine = false,
}
})

View file

@ -121,3 +121,25 @@ vim.lsp.set_log_level("off")
-- define a timeout for match parens
vim.g.matchparen_timeout = 2
vim.g.matchparen_insert_timeout = 2
-- activate virtual lines for diagnistics
-- no more plugins needed
vim.diagnostic.config({
virtual_lines = true
-- Alternatively, customize specific options
-- virtual_lines = {
-- -- Only show virtual line diagnostics for the current cursor line
-- current_line = true,
-- },
})
-- LSP configuration
vim.lsp.enable('bash')
vim.lsp.enable('helm')
vim.lsp.enable('lua')
vim.lsp.enable('nills')
vim.lsp.enable('pylsp')
vim.lsp.enable('terraformls')
vim.lsp.enable('tflint')
vim.lsp.enable('yaml')