-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lua
118 lines (108 loc) · 2.72 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---@module "ninjection.config"
---@brief
--- The config module contains the default ninjection configuration table and
--- functions to merge user config options and reload config changes.
---
local M = {}
local vc = require("ninjection.health").validate_config
---@nodoc
---@type Ninjection.Config
---@tag default_config
local default_config = {
---@type boolean
preserve_indents = true,
---@type boolean
auto_format = true,
---@type string
format_cmd = "_G.format_with_conform()",
---@type integer
injected_comment_lines = 1,
---@type string
register = "z",
---@type boolean
debug = true,
---@type EditorStyle
editor_style = "floating",
---@type table<string, string>
inj_lang_queries = {
nix = [[
(
(comment) @injection.language
.
[
(indented_string_expression
(string_fragment) @injection.content)
(string_expression
(string_fragment) @injection.content)
]
(#gsub! @injection.language "#%s*([%w%p]+)%s*" "%1")
(#set! injection.combined)
)
]],
},
---@type table<string,string>
lsp_map = {
bash = "bashls",
c = "clangd",
cpp = "clangd",
javascript = "ts_ls",
json = "jsonls",
lua = "lua_ls",
python = "ruff",
rust = "rust_analyzer",
sh = "bashls",
typescript = "ts_ls",
yaml = "yamlls",
zig = "zls",
},
}
---@nodoc
--- Provide default_config for inspection, primarily for documentation.
---@return Ninjection.Config
M.get_default = function()
return default_config
end
---@eval return (function()
--- local s = vim.inspect(require("ninjection.config").get_default())
--- s = s:gsub("\\t", " ")
--- s = s:gsub("\\n", "\n")
--- local lines = vim.split(s, "\n")
--- for i, line in ipairs(lines) do
--- lines[i] = "`" .. line -- Prefix each line with a backtick.
--- end
--- return lines
--- end)()
---@minidoc_afterlines_end
---@tag config.reload()
---@brief
--- Reloads all ninjection modules to flush caches and apply a new config.
---
---@return nil
---
M.reload = function()
for key in pairs(package.loaded) do
if key:match("^ninjection") then
package.loaded[key] = nil
end
end
end
---@nodoc
--- Merges user provided configuration overrides with the default configuration.
---@param cfg_overrides? Ninjection.Config
---@return nil
M._merge_config = function(cfg_overrides)
---@type Ninjection.Config
local user_config = vim.g.ninjection or cfg_overrides or {}
---@type Ninjection.Config
local config = vim.tbl_deep_extend("force", default_config, user_config)
local is_valid, err
is_valid, err = vc(config)
if not is_valid then
error(err, 2)
end
M.values = config
return M.values
end
-- Provide default config in the event no user overrides are provided.
M.values = M._merge_config()
return M