-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpyright.lua
More file actions
78 lines (70 loc) · 2.08 KB
/
pyright.lua
File metadata and controls
78 lines (70 loc) · 2.08 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
local M = {}
M._init_dap = false
local function get_python_path()
if vim.env.VIRTUAL_ENV then
return vim.fs.joinpath(vim.env.VIRTUAL_ENV, "bin", "python")
end
if vim.env.PY_BIN then
return vim.env.PY_BIN
end
local cwd = vim.loop.cwd()
if vim.fn.executable(vim.fs.joinpath(cwd, ".venv")) then
return vim.fs.joinpath(cwd, ".venv", "bin", "python")
end
local python = vim.fn.exepath("python3")
if python == nil or python == "" then
python = vim.fn.exepath("python")
end
return python
end
function M.init_dap()
if M._init_dap then
return
end
M._init_dap = true
require("dap-python").setup(get_python_path())
end
local me = require("kide.melspconfig")
-- see nvim-lspconfig
function M.organize_imports()
local params = {
command = "pyright.organizeimports",
arguments = { vim.uri_from_bufnr(0) },
}
local clients = vim.lsp.get_clients({
bufnr = vim.api.nvim_get_current_buf(),
name = "pyright",
})
for _, client in ipairs(clients) do
client:request("workspace/executeCommand", params, nil, 0)
end
end
M.config = {
name = "pyright",
cmd = { "pyright-langserver", "--stdio" },
root_dir = vim.fs.root(0, { ".git", "requirements.txt", "pyproject.toml" }) or vim.uv.cwd(),
on_attach = function(client, bufnr)
local dap_py = require("dap-python")
vim.keymap.set("n", "<leader>dc", dap_py.test_class, { desc = "Dap Test Class", buffer = bufnr })
vim.keymap.set("n", "<leader>dm", dap_py.test_method, { desc = "Dap Test Method", buffer = bufnr })
vim.keymap.set("v", "<leader>ds", dap_py.debug_selection, { desc = "Dap Debug Selection", buffer = bufnr })
local create_command = vim.api.nvim_buf_create_user_command
create_command(bufnr, "OR", M.organize_imports, {
nargs = 0,
})
me.on_attach(client, bufnr)
end,
on_init = me.on_init,
capabilities = me.capabilities(),
settings = {
python = {
pythonPath = get_python_path(),
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = "openFilesOnly",
},
},
},
}
return M