Skip to content

Commit bdbf3fe

Browse files
lspsaga and using jedi?
1 parent 76a88ef commit bdbf3fe

File tree

3 files changed

+145
-66
lines changed

3 files changed

+145
-66
lines changed

lua/modules/lsp/config.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ function config.signature()
9090
hint_scheme = "String",
9191
hi_parameter = "Search",
9292
max_height = 22,
93+
94+
transparency = 1, -- disabled by default, allow floating win transparent value 1~100
9395
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
9496
handler_opts = {
9597
border = border, -- double, single, shadow, none
9698
},
97-
zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom
99+
zindex = 50, -- by default it will be on top of all floating windows, set to 50 send it to bottom
98100
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
99101
always_trigger = true,
102+
floating_window_above_cur_line = true, -- try to place the floating above the current line when possible Note:
100103
}
101104

102105
require("lsp_signature").setup(opts)

lua/modules/lsp/settings/main.lua

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local lspconfig = require("lspconfig")
2+
local py = require("modules.lsp.utils.python_help")
23

34
-- WARN: Dont remove this files
45
require("modules.lsp.installer")
@@ -38,6 +39,8 @@ local servers = {
3839
"--pch-storage=memory",
3940
},
4041
},
42+
-- basedpyright = {},
43+
-- pyright = {},
4144
}
4245
for server, config in pairs(servers) do
4346
lspconfig[server].setup(vim.tbl_deep_extend("force", {
@@ -49,9 +52,6 @@ end
4952
local pyright = {
5053
on_attach = on_attach,
5154
settings = {
52-
pyright = {
53-
disableOrganizeImports = false,
54-
},
5555
python = {
5656
analysis = {
5757
indexing = true,
@@ -71,73 +71,37 @@ local pyright = {
7171
},
7272
},
7373
},
74-
--[[ settings = {
75-
python = {
76-
analysis = {
77-
indexing = true,
78-
typecheckingmode = "basic",
79-
-- diagnosticmode = "openfilesonly",
80-
diagnosticmode = "workspace",
81-
inlayhints = {
82-
variabletypes = true,
83-
functionreturntypes = true,
84-
},
85-
stubpath = vim.fn.expand("$home/typings"),
86-
diagnosticseverityoverrides = {
87-
reportunusedimport = "information",
88-
reportunusedfunction = "information",
89-
reportunusedvariable = "information",
90-
},
91-
},
92-
},
93-
}, ]]
9474
}
9575

9676
local jedi = {
9777
on_attach = on_attach,
98-
capabilities = capabilities,
99-
settings = {
100-
python = {
101-
analysis = {
102-
indexing = true,
103-
typeCheckingMode = "basic",
104-
diagnosticMode = "workspace",
105-
inlayHints = {
106-
variableTypes = true,
107-
functionReturnTypes = true,
108-
},
109-
stubPath = vim.fn.expand("$HOME/typings"),
110-
diagnosticSeverityOverrides = {
111-
reportMissingTypeStubs = "information",
112-
reportGeneralTypeIssues = "warning",
113-
reportUnboundVariable = "warning",
114-
reportUndefinedVariable = "error",
115-
reportUnknownMemberType = "information",
116-
reportUnknownVariableType = "information",
117-
reportUntypedClassDecorator = "none",
118-
reportUntypedFunctionDecorator = "none",
119-
reportFunctionMemberAccess = "warning",
120-
reportUnknownArgumentType = "warning",
121-
reportUnknownParameterType = "warning",
122-
reportUnknownLambdaType = "warning",
123-
reportUnusedImport = "information",
124-
reportUnusedFunction = "information",
125-
reportUnusedVariable = "information",
126-
reportUnusedClass = "information",
127-
strictParameterNoneValue = false,
128-
reportOptionalSubscript = "warning",
129-
reportOptionalMemberAccess = "warning",
130-
reportOptionalIterable = "warning",
131-
reportOptionalCall = "none",
132-
},
133-
},
78+
-- capabilities = capabilities,
79+
init_options = {
80+
jediSettings = {
81+
case_insensitive_completion = true,
82+
add_bracket_after_function = true,
83+
dynamic_params = true,
84+
-- Allot of machine learning models that are set from default.
85+
autoImportModules = { "numpy", "matplotlib", "random", "math", "scipy" },
13486
},
13587
},
88+
89+
on_new_config = function(new_config, new_root_dir)
90+
new_config.settings.python.pythonPath = vim.fn.exepath("python")
91+
print(new_config.settings.python.pythonPath)
92+
new_config.cmd_env.PATH = py.env(new_root_dir) .. new_config.cmd_env.PATH
93+
94+
local pep582 = py.pep582(new_root_dir)
95+
if pep582 ~= nil then
96+
new_config.settings.python.analysis.extraPaths = { pep582 }
97+
end
98+
end,
13699
}
137100

138-
local use_pyright = true
139-
if use_pyright then
140-
require("lspconfig").pyright.setup(pyright)
141-
else
142-
require("lspconfig").jedi_language_server.setup(jedi)
143-
end
101+
require("lspconfig").jedi_language_server.setup(jedi)
102+
-- local use_pyright = true
103+
-- if use_pyright then
104+
-- require("lspconfig").pyright.setup(pyright)
105+
-- else
106+
-- require("lspconfig").jedi_language_server.setup(jedi)
107+
-- end

lua/modules/lsp/utils/python_help.lua

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
local M = {}
2+
3+
local path = require("lspconfig.util").path
4+
5+
local function get_pipenv_dir()
6+
return vim.fn.trim(vim.fn.system("pipenv --venv"))
7+
end
8+
9+
local function get_poetry_dir()
10+
return vim.fn.trim(vim.fn.system("poetry env info -p"))
11+
end
12+
13+
local function get_pdm_package()
14+
return vim.fn.trim(vim.fn.system("pdm info --packages"))
15+
end
16+
17+
local function in_conda_env()
18+
if
19+
vim.fn.trim(
20+
vim.fn.system(
21+
'[[ -n "$CONDA_PREFIX" ]] && echo "In a conda env: $CONDA_DEFAULT_ENV" || echo "Not in a conda env"'
22+
)
23+
)
24+
then
25+
return true
26+
end
27+
end
28+
29+
local function get_python_dir(workspace)
30+
local conda_match = in_conda_env()
31+
if conda_match then
32+
return vim.fn.trim(vim.fn.system("which python"))
33+
end
34+
35+
local poetry_match = vim.fn.glob(path.join(workspace, "poetry.lock"))
36+
if poetry_match ~= "" then
37+
return get_poetry_dir()
38+
end
39+
40+
local pipenv_match = vim.fn.glob(path.join(workspace, "Pipfile.lock"))
41+
if pipenv_match ~= "" then
42+
return get_pipenv_dir()
43+
end
44+
45+
-- Find and use virtualenv in workspace directory.
46+
for _, pattern in ipairs({ "*", ".*" }) do
47+
local match = vim.fn.glob(path.join(workspace, pattern, "pyvenv.cfg"))
48+
if match ~= "" then
49+
return path.dirname(match)
50+
end
51+
end
52+
53+
return ""
54+
end
55+
56+
local _virtual_env = ""
57+
local _package = ""
58+
59+
local function py_bin_dir()
60+
return path.join(_virtual_env, "bin:")
61+
end
62+
63+
M.in_any_env = function()
64+
return in_conda_env() or vim.fn.glob("Pipfile.lock") ~= "" or vim.fn.glob("poetry.lock") ~= ""
65+
end
66+
67+
M.env = function(root_dir)
68+
if not vim.env.VIRTUAL_ENV or vim.env.VIRTUAL_ENV == "" then
69+
_virtual_env = get_python_dir(root_dir)
70+
end
71+
72+
if _virtual_env ~= "" then
73+
vim.env.VIRTUAL_ENV = _virtual_env
74+
vim.env.PATH = py_bin_dir() .. vim.env.PATH
75+
end
76+
77+
if _virtual_env ~= "" and vim.env.PYTHONHOME then
78+
vim.env.old_PYTHONHOME = vim.env.PYTHONHOME
79+
vim.env.PYTHONHOME = ""
80+
end
81+
82+
return _virtual_env ~= "" and py_bin_dir() or ""
83+
end
84+
85+
-- PEP 582 support
86+
M.pep582 = function(root_dir)
87+
local pdm_match = vim.fn.glob(path.join(root_dir, "pdm.lock"))
88+
if pdm_match ~= "" then
89+
_package = get_pdm_package()
90+
end
91+
92+
if _package ~= "" then
93+
return path.join(_package, "lib")
94+
end
95+
end
96+
97+
M.conda = function(root_dir)
98+
local conda_match = in_conda_env()
99+
-- In a conda env: main
100+
-- or
101+
-- Not in a conda env
102+
103+
if conda_match then
104+
return vim.fn.trim(vim.fn.system("conda info --base"))
105+
.. "/envs/"
106+
.. vim.fn.trim(vim.fn.system("conda info --envs | grep '*' | awk '{print $1}'"))
107+
end
108+
109+
return ""
110+
end
111+
112+
return M

0 commit comments

Comments
 (0)