aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2026-08-31 17:19:43 +0200
committerThomas Schmucker <ts@its1.de>2026-08-31 17:19:43 +0200
commit78477ffd834fbb71563c04f18572f1838b5b3d7c (patch)
tree7ff81e17fad745295b82bf4574dfecb036b17636
parenta5fcfee3f33f95b9ad41f42e6676ef0b579904e5 (diff)
downloaddotfiles-78477ffd834fbb71563c04f18572f1838b5b3d7c.tar.gz
dotfiles-78477ffd834fbb71563c04f18572f1838b5b3d7c.tar.bz2
dotfiles-78477ffd834fbb71563c04f18572f1838b5b3d7c.zip
neovim: Support für Ansible
-rw-r--r--nvim/init.lua1
-rw-r--r--nvim/lua/config/autocmds.lua12
-rw-r--r--nvim/lua/config/filetypes.lua36
-rw-r--r--nvim/lua/plugins/lsp.lua16
4 files changed, 64 insertions, 1 deletions
diff --git a/nvim/init.lua b/nvim/init.lua
index e56561e..3535671 100644
--- a/nvim/init.lua
+++ b/nvim/init.lua
@@ -1,4 +1,5 @@
1require("config.options") 1require("config.options")
2require("config.filetypes")
2 3
3local keymaps = require("config.keymaps") 4local keymaps = require("config.keymaps")
4keymaps.global() 5keymaps.global()
diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua
index 53bf7a9..29532f9 100644
--- a/nvim/lua/config/autocmds.lua
+++ b/nvim/lua/config/autocmds.lua
@@ -1,5 +1,6 @@
1-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt 1-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt
2local treesitter_languages = require("config.treesitter").languages 2local treesitter_languages = require("config.treesitter").languages
3local extra_filetypes = require("config.filetypes").extra
3 4
4local function enable_treesitter_features() 5local function enable_treesitter_features()
5 if not pcall(vim.treesitter.start) then return end 6 if not pcall(vim.treesitter.start) then return end
@@ -9,8 +10,17 @@ local function enable_treesitter_features()
9 vim.bo.indentexpr = "v:lua.require('nvim-treesitter').indentexpr()" 10 vim.bo.indentexpr = "v:lua.require('nvim-treesitter').indentexpr()"
10end 11end
11 12
13-- Fuehrt zwei Listen zu einer neuen zusammen, ohne die Eingaben zu veraendern.
14local function merge(list, extra)
15 local merged = { table.unpack(list) }
16 for _, item in ipairs(extra) do
17 table.insert(merged, item)
18 end
19 return merged
20end
21
12vim.api.nvim_create_autocmd("FileType", { 22vim.api.nvim_create_autocmd("FileType", {
13 pattern = treesitter_languages, 23 pattern = merge(treesitter_languages, extra_filetypes),
14 callback = enable_treesitter_features, 24 callback = enable_treesitter_features,
15}) 25})
16 26
diff --git a/nvim/lua/config/filetypes.lua b/nvim/lua/config/filetypes.lua
new file mode 100644
index 0000000..a850028
--- /dev/null
+++ b/nvim/lua/config/filetypes.lua
@@ -0,0 +1,36 @@
1-- Custom Filetype-Erkennung fuer Dateien, die sich nicht allein anhand ihrer
2-- Endung unterscheiden lassen (z.B. Ansible-YAML vs. normales YAML).
3
4local M = {}
5
6-- Name des zusammengesetzten Filetypes fuer Ansible-YAML-Dateien. Wird auch
7-- von plugins/lsp.lua (vim.lsp.config.ansiblels.filetypes) referenziert, damit
8-- Erkennung und LSP-Konfiguration nicht auseinanderlaufen koennen.
9M.ANSIBLE_YAML = "yaml.ansible"
10
11-- Filetypes, die hier zusaetzlich zur eingebauten Erkennung entstehen und
12-- an anderer Stelle mitberuecksichtigt werden muessen (siehe config.autocmds,
13-- Treesitter-Aktivierung).
14M.extra = { M.ANSIBLE_YAML }
15
16-- Ansible-Dateien haben die Endung .yml/.yaml wie normales YAML, sind aber
17-- ueber ihren Pfad erkennbar.
18vim.filetype.add({
19 pattern = {
20 [".*/roles/.*/tasks/.*%.ya?ml"] = M.ANSIBLE_YAML,
21 [".*/roles/.*/handlers/.*%.ya?ml"] = M.ANSIBLE_YAML,
22 [".*/tasks/.*%.ya?ml"] = M.ANSIBLE_YAML,
23 [".*/handlers/.*%.ya?ml"] = M.ANSIBLE_YAML,
24 [".*/group_vars/.*%.ya?ml"] = M.ANSIBLE_YAML,
25 [".*/host_vars/.*%.ya?ml"] = M.ANSIBLE_YAML,
26 [".*/playbooks/.*%.ya?ml"] = M.ANSIBLE_YAML,
27 ["playbook%.ya?ml"] = M.ANSIBLE_YAML,
28 ["site%.ya?ml"] = M.ANSIBLE_YAML,
29 ["requirements%.ya?ml"] = M.ANSIBLE_YAML,
30 },
31})
32
33-- yaml.ansible soll den regulaeren yaml-Parser von Treesitter verwenden.
34vim.treesitter.language.register("yaml", M.ANSIBLE_YAML)
35
36return M
diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua
index b301b68..d4bb9fd 100644
--- a/nvim/lua/plugins/lsp.lua
+++ b/nvim/lua/plugins/lsp.lua
@@ -109,7 +109,23 @@ return {
109 }, 109 },
110 } 110 }
111 111
112 vim.lsp.config.ansiblels = {
113 capabilities = capabilities,
114 filetypes = { require("config.filetypes").ANSIBLE_YAML },
115 settings = {
116 ansible = {
117 validation = {
118 lint = {
119 enabled = true,
120 path = "ansible-lint",
121 },
122 },
123 },
124 },
125 }
126
112 vim.lsp.enable({ 127 vim.lsp.enable({
128 "ansiblels", -- npm install -g @ansible/ansible-language-server & (brew install ansible-lint, pkg install py-ansible-lint)
113 "basedpyright", -- npm install -g basedpyright, brew install basedpyright 129 "basedpyright", -- npm install -g basedpyright, brew install basedpyright
114 "bashls", -- npm install -g bash-language-server, pkg install hs-ShellCheck 130 "bashls", -- npm install -g bash-language-server, pkg install hs-ShellCheck
115 "clangd", -- pkg install llvm 131 "clangd", -- pkg install llvm