Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
chore(pylsp): cleanup (ayamir#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jint-lzxy authored and leavers committed May 31, 2023
1 parent def6dfd commit 455c9bb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 52 deletions.
100 changes: 58 additions & 42 deletions lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
return function()
local nvim_lsp = require("lspconfig")
local mason = require("mason")
local mason_registry = require("mason-registry")
local mason_lspconfig = require("mason-lspconfig")

require("lspconfig.ui.windows").default_options.border = "rounded"
require("lspconfig.ui.windows").default_options.border = "single"

local icons = {
ui = require("modules.utils.icons").get("ui", true),
Expand All @@ -12,7 +12,7 @@ return function()

mason.setup({
ui = {
border = "rounded",
border = "single",
icons = {
package_pending = icons.ui.Modified_alt,
package_installed = icons.ui.Check,
Expand All @@ -30,6 +30,59 @@ return function()
},
},
})

-- Additional plugins for pylsp
mason_registry:on(
"package:install:success",
vim.schedule_wrap(function(pkg)
if pkg.name ~= "python-lsp-server" then
return
end

local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv"
require("plenary.job")
:new({
command = venv .. "/bin/python",
args = {
"-m",
"pip",
"install",
"-U",
"--disable-pip-version-check",
"python-lsp-black",
"python-lsp-ruff",
"pylsp-rope",
},
cwd = venv,
env = { VIRTUAL_ENV = venv },
on_exit = function()
if
vim.fn.executable(venv .. "/bin/black") == 1
and vim.fn.executable(venv .. "/bin/ruff") == 1
then
vim.notify(
"Finished installing pylsp plugins",
vim.log.levels.INFO,
{ title = "[lsp] Install Status" }
)
return
end
end,
on_start = function()
vim.notify(
"Now installing pylsp plugins...",
vim.log.levels.INFO,
{ title = "[lsp] Install Status", timeout = 6000 }
)
end,
on_stderr = function(_, msg_stream)
vim.notify(msg_stream, vim.log.levels.ERROR, { title = "[lsp] Install Failure" })
end,
})
:start()
end)
)

mason_lspconfig.setup({
ensure_installed = require("core.settings").lsp_deps,
})
Expand All @@ -55,7 +108,7 @@ return function()
hint_enable = true,
hi_parameter = "Search",
handler_opts = {
border = "rounded",
border = "single",
},
})
end,
Expand Down Expand Up @@ -92,47 +145,10 @@ return function()

mason_lspconfig.setup_handlers({ mason_handler })

-- Set lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here.
-- Setup lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here.
if vim.fn.executable("dart") == 1 then
local _opts = require("completion.servers.dartls")
local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
nvim_lsp.dartls.setup(final_opts)
end

local function mason_post_install(pkg)
if pkg.name ~= "python-lsp-server" then
return
end

local venv = vim.fn.stdpath("data") .. "/mason/packages/python-lsp-server/venv"
local job = require("plenary.job")

job:new({
command = venv .. "/bin/pip",
args = {
"install",
"-U",
"--disable-pip-version-check",
"python-lsp-black",
"python-lsp-ruff",
"pylsp-rope",
},
cwd = venv,
env = { VIRTUAL_ENV = venv },
on_exit = function()
if vim.fn.executable(venv .. "/bin/black") == 1 and vim.fn.executable(venv .. "/bin/ruff") == 1 then
vim.notify("Finished installing pylsp plugins.")
return
end
end,
on_start = function()
vim.notify("Installing pylsp plugins...")
end,
on_stderr = function(_, data)
vim.notify(data, vim.log.levels.ERROR)
end,
}):start()
end

require("mason-registry"):on("package:install:success", mason_post_install)
end
20 changes: 10 additions & 10 deletions lua/modules/configs/completion/servers/pylsp.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
-- https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/pylsp.lua
return {
cmd = { "pylsp" },
filetypes = { "python" },
settings = {
pylsp = {
plugins = {
-- enabled tools
-- lint related
-- Lint
ruff = {
enabled = true,
select = {
Expand All @@ -25,18 +27,16 @@ return {
E501 = "I",
},
},
-- refactor related
rope = { enabled = true },
-- format related
black = { enabled = true },

-- disabled tools
-- lint related
flake8 = { enabled = false },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
mccabe = { enabled = false },
-- format related

-- Code refactor
rope = { enabled = true },

-- Formatting
black = { enabled = true },
pyls_isort = { enabled = false },
autopep8 = { enabled = false },
yapf = { enabled = false },
Expand Down

0 comments on commit 455c9bb

Please sign in to comment.