diff options
Diffstat (limited to 'nvim/lua/config')
| -rw-r--r-- | nvim/lua/config/autocmds.lua | 15 | ||||
| -rw-r--r-- | nvim/lua/config/filetypes.lua | 18 | ||||
| -rw-r--r-- | nvim/lua/config/treesitter.lua | 3 |
3 files changed, 33 insertions, 3 deletions
diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua index 53bf7a9..0835670 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 |
| 2 | local treesitter_languages = require("config.treesitter").languages | 2 | local treesitter_languages = require("config.treesitter").languages |
| 3 | local extra_filetypes = require("config.filetypes").extra | ||
| 3 | 4 | ||
| 4 | local function enable_treesitter_features() | 5 | local 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,20 @@ 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()" |
| 10 | end | 11 | end |
| 11 | 12 | ||
| 13 | -- Fuehrt zwei Listen zu einer neuen zusammen, ohne die Eingaben zu veraendern. | ||
| 14 | local function merge(list, extra) | ||
| 15 | local merged = {} | ||
| 16 | for _, item in ipairs(list) do | ||
| 17 | table.insert(merged, item) | ||
| 18 | end | ||
| 19 | for _, item in ipairs(extra) do | ||
| 20 | table.insert(merged, item) | ||
| 21 | end | ||
| 22 | return merged | ||
| 23 | end | ||
| 24 | |||
| 12 | vim.api.nvim_create_autocmd("FileType", { | 25 | vim.api.nvim_create_autocmd("FileType", { |
| 13 | pattern = treesitter_languages, | 26 | pattern = merge(treesitter_languages, extra_filetypes), |
| 14 | callback = enable_treesitter_features, | 27 | callback = enable_treesitter_features, |
| 15 | }) | 28 | }) |
| 16 | 29 | ||
diff --git a/nvim/lua/config/filetypes.lua b/nvim/lua/config/filetypes.lua index a8a059a..b3dec26 100644 --- a/nvim/lua/config/filetypes.lua +++ b/nvim/lua/config/filetypes.lua | |||
| @@ -1,6 +1,24 @@ | |||
| 1 | -- Custom Filetype-Erkennung fuer Dateien, die von der eingebauten Erkennung | ||
| 2 | -- abweichen sollen. | ||
| 3 | |||
| 4 | local M = {} | ||
| 5 | |||
| 6 | -- Filetypes, die hier zusaetzlich zur eingebauten Erkennung entstehen und | ||
| 7 | -- an anderer Stelle mitberuecksichtigt werden muessen (siehe config.autocmds, | ||
| 8 | -- Treesitter-Aktivierung). | ||
| 9 | M.extra = { "jsonc" } | ||
| 10 | |||
| 1 | vim.filetype.add({ | 11 | vim.filetype.add({ |
| 2 | extension = { | 12 | extension = { |
| 3 | j2 = "jinja", | 13 | j2 = "jinja", |
| 14 | -- .json als jsonc behandeln, damit Kommentare erlaubt sind (jsonls meldet | ||
| 15 | -- sie dann nicht als Fehler). | ||
| 4 | json = "jsonc", | 16 | json = "jsonc", |
| 5 | }, | 17 | }, |
| 6 | }) | 18 | }) |
| 19 | |||
| 20 | -- nvim-treesitter stellt keinen eigenen jsonc-Parser bereit. Der json-Parser | ||
| 21 | -- versteht // und /* */ Kommentare, deshalb wird er fuer jsonc mitbenutzt. | ||
| 22 | vim.treesitter.language.register("json", "jsonc") | ||
| 23 | |||
| 24 | return M | ||
diff --git a/nvim/lua/config/treesitter.lua b/nvim/lua/config/treesitter.lua index de71d50..e52d637 100644 --- a/nvim/lua/config/treesitter.lua +++ b/nvim/lua/config/treesitter.lua | |||
| @@ -10,8 +10,7 @@ M.languages = { | |||
| 10 | -- "jinja", | 10 | -- "jinja", |
| 11 | -- "jinja_inline", | 11 | -- "jinja_inline", |
| 12 | "jq", | 12 | "jq", |
| 13 | "json", -- weiterhin nötig für Injections, z.B. ```json in Markdown | 13 | "json", -- deckt auch den Dateityp jsonc ab (siehe lua/config/filetypes.lua) |
| 14 | "jsonc", | ||
| 15 | "lua", | 14 | "lua", |
| 16 | "make", | 15 | "make", |
| 17 | "markdown", | 16 | "markdown", |
