-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.lua
More file actions
153 lines (140 loc) · 4.32 KB
/
config.lua
File metadata and controls
153 lines (140 loc) · 4.32 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---@diagnostic disable: missing-fields, inject-field
---@type python.Config
local PythonConfig = {}
--- Python.nvim config
--- Default values:
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
---@class python.Config
PythonConfig.defaults = {
-- Should return a list of tables with a `name` and a `path` entry each.
-- Gets the argument `venvs_path` set below.
-- By default just lists the entries in `venvs_path`.
---@return VEnv[]
get_venvs = function(venvs_path)
return require("python.venv").get_venvs(venvs_path)
end,
-- Path for venvs picker
venvs_path = vim.fn.expand("~/.virtualenvs"),
-- Something to do after setting an environment
post_set_venv = false,
-- base path for creating new venvs
auto_create_venv_path = function(parent_dir)
return vim.fs.joinpath(parent_dir, ".venv")
end,
-- Patterns for autocmd LspAttach that trigger the auto venv logic
-- Add onto this list if you depend on venvs for other file types
-- like .yaml, .yml for ansible
auto_venv_lsp_attach_patterns = { "*.py" },
-- Buffer patterns to activate commands for python.nvim
command_setup_buf_pattern = { "*.py" },
-- Load python.nvim python snippets
python_lua_snippets = false,
-- List of text actions to take on InsertLeave, TextChanged
-- Put in empty table or nil to disable
enabled_text_actions = {
"f-strings", -- When inserting {}, put in an f-string
},
-- Adjust when enabled_text_actions is triggered
enabled_text_actions_autocmd_events = { "InsertLeave" },
treesitter = {
functions = {
-- Wrap treesitter identifier under cursor using substitute_options
wrapper = {
-- Substitute options for PythonTSWrapWithFunc
substitute_options = {
"print(%s)",
"log.debug(%s)",
"log.info(%s)",
"log.warning(%s)",
"log.error(%s)",
"np.array(%s)",
},
-- Look for tree-sitter types to wrap
find_types = {
"tuple",
"string",
"true",
"false",
"list",
"call",
"parenthesized_expression",
"expression_statement",
"integer",
},
},
},
},
-- Settings regarding ui handling
ui = {
-- Amount of time to pause closing of ui after a finished task
ui_close_timeout = 5000,
-- Default ui style for interfaces created by python.nvim
---@alias python_ui_default_style "'popup'|'split'|nil"
default_ui_style = "popup",
-- Customize the position and behavior of the ui style
popup = {
win_opts = {
-- border = "rounded",
-- relative = "win",
-- focusable = true,
-- title = "python.nvim",
-- anchor = "SE",
-- zindex = 999,
-- width = 40,
-- height = 20,
-- row = vim.o.lines - 3,
-- col = vim.o.columns -2,
},
},
split = {
win_opts = {
-- split = 'below',
-- win = 0,
-- width = 40,
-- height = 10,
-- focusable = true,
},
},
},
-- Tell neotest-python which test runner to use
test = {
test_runner = "pytest",
},
}
--minidoc_afterlines_end
-- Only for existing keys in `target`.
local function tbl_deep_extend_existing(target, source, prev_key)
-- Return if source or target is not a table or is nil
if type(target) ~= "table" or type(source) ~= "table" then
return target
end
for key, value in pairs(source) do
-- Only update keys that already exist in the target table
if target[key] ~= nil then
if type(target[key]) == "table" and type(value) == "table" then
prev_key = prev_key .. "." .. key
-- Recurse for nested tables
tbl_deep_extend_existing(target[key], value, prev_key)
else
-- Overwrite existing key
target[key] = value
end
else
error(("python.nvim: user inputted config key: %s is not found in config table: %s"):format(key, prev_key))
end
end
return target
end
---@param opts? python.Config
function PythonConfig.setup(opts)
opts = opts or {}
PythonConfig.config = tbl_deep_extend_existing(PythonConfig.defaults, opts, "config")
end
return setmetatable(PythonConfig, {
__index = function(_, key)
if PythonConfig.config == nil then
PythonConfig.setup()
end
return PythonConfig.config[key]
end,
})