Skip to content

Commit

Permalink
feat: set default config for pylsp. (ayamir#770)
Browse files Browse the repository at this point in the history
* feat: add default config for pylsp.

Signed-off-by: ayamir <[email protected]>

* clean old config of black in null-ls.

* feat: install pylsp plugins automatically.

* perf: remove isort for pylsp, add E501 and F401 to ignore.

* perf: remove E501 and F401 from ignore list.

---------

Signed-off-by: ayamir <[email protected]>
  • Loading branch information
ayamir authored and csyJoy committed Jun 4, 2023
1 parent 41b38c8 commit 47a2b78
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ settings["server_formatting_block_list"] = {
lua_ls = true,
tsserver = true,
clangd = true,
pylsp = true,
}

-- Set the language servers that will be installed during bootstrap here.
Expand All @@ -90,7 +89,6 @@ settings["lsp_deps"] = {
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins
---@type string[]
settings["null_ls_deps"] = {
"black",
"clang_format",
"prettier",
"rustfmt",
Expand Down
37 changes: 37 additions & 0 deletions lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,41 @@ return function()
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
3 changes: 0 additions & 3 deletions lua/modules/configs/completion/null-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ return function()
-- Please set additional flags for the supported servers here
-- Don't specify any config here if you are using the default one.
local sources = {
btns.formatting.black.with({
extra_args = { "--fast" },
}),
btns.formatting.clang_format.with({
filetypes = { "c", "cpp" },
extra_args = require("completion.formatters.clang_format"),
Expand Down
41 changes: 41 additions & 0 deletions lua/modules/configs/completion/servers/pylsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
return {
settings = {
pylsp = {
plugins = {
-- enabled tools
-- lint related
ruff = {
enabled = true,
select = {
-- enable pycodestyle
"E",
-- enable pyflakes
"F",
},
ignore = {
-- ignore E501 (line too long)
-- "E501",
-- ignore F401 (imported but unused)
-- "F401",
},
extendSelect = { "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
pyls_isort = { enabled = false },
autopep8 = { enabled = false },
yapf = { enabled = false },
},
},
},
}

0 comments on commit 47a2b78

Please sign in to comment.