如何禁用 pylsp 中的 linter?
我的 neovim(0.6.1) 使用 nvim-lint 管理 pylint,使用 pylsp 完成。
编辑python文件时,使用numpy、scipy等,代码竞争、悬停、签名很慢,CPU使用率100%。该代码有两次相同的 lint 概念。我想在 pylsp 中禁用 linter,但它不起作用。我该怎么办?
这是我的配置:pylsp.lua
opts = {
cmd = { "pylsp" },
filetypes = { "python" },
root_dir = function()
return vim.fn.getcwd()
end,
single_file_support = true,
configurationSources = {""}, -- default is pycodestyle
rope = {extensionModules = "", ropeFolder = {} },
plugins = {
jedi_completion = {
enabled = true,
eager = true,
cache_for = {"numpy", "scipy"}
},
jedi_definition = {
enabled = true,
follow_imports = true,
follow_builtin_imports = true,
},
jedi_hover = { enabled = true },
jedi_references = { enabled = true },
jedi_signature_help = { enabled = true },
jedi_symbols = { enabled = true, all_scopes = true, include_import_symbols = true },
preload = { enabled = true, modules = {"numpy", "scipy"} },
mccabe = { enabled = false },
mypy = { enabled = false },
isort = { enabled = false },
spyder = { enabled = false },
memestra = { enabled = false },
pycodestyle = { enabled = false }, -- not work
flake8 = { enabled = false },
pyflakes = { enabled = false },
yapf = { enabled = false },
pylint = {
enabled = false,
args = {
"-f",
"json",
"--rcfile=" .. "~/.pylintrc"
}
},
rope = { enabled = false },
rope_completion = { enabled = false, eager = false },
},
}
pylsp.setup(opts)
My neovim(0.6.1) use nvim-lint manage pylint, use pylsp for completion.
When edit a python file, use numpy, scipy etc, the code competion, hover, signature is slow, and cpu use 100%. The code have same lint notion twice. I want disable linter in pylsp, but it not work. How can i do?
This is my config: pylsp.lua
opts = {
cmd = { "pylsp" },
filetypes = { "python" },
root_dir = function()
return vim.fn.getcwd()
end,
single_file_support = true,
configurationSources = {""}, -- default is pycodestyle
rope = {extensionModules = "", ropeFolder = {} },
plugins = {
jedi_completion = {
enabled = true,
eager = true,
cache_for = {"numpy", "scipy"}
},
jedi_definition = {
enabled = true,
follow_imports = true,
follow_builtin_imports = true,
},
jedi_hover = { enabled = true },
jedi_references = { enabled = true },
jedi_signature_help = { enabled = true },
jedi_symbols = { enabled = true, all_scopes = true, include_import_symbols = true },
preload = { enabled = true, modules = {"numpy", "scipy"} },
mccabe = { enabled = false },
mypy = { enabled = false },
isort = { enabled = false },
spyder = { enabled = false },
memestra = { enabled = false },
pycodestyle = { enabled = false }, -- not work
flake8 = { enabled = false },
pyflakes = { enabled = false },
yapf = { enabled = false },
pylint = {
enabled = false,
args = {
"-f",
"json",
"--rcfile=" .. "~/.pylintrc"
}
},
rope = { enabled = false },
rope_completion = { enabled = false, eager = false },
},
}
pylsp.setup(opts)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法在
lspconfig
设置中禁用pylst
linters:例如,如果您使用
nvim-lspconfig 的建议配置
,您可以更改lspconfig.pylsp.setup
并配置您喜欢的任何插件:希望它有效!
I managed to disable
pylst
linters inlspconfig
setup:For example, if you use the
suggested configuration of nvim-lspconfig
, you can change thelspconfig.pylsp.setup
and configure any plugin you like:Hope it works!
如果有人仍然遇到这个问题,可以通过 pycodestyle 进行 linting。它出现在 pylsp github 页面 (https://github.com/python- lsp/python-lsp-server#installation)默认情况下禁用 pylint,但 pydocstyle 不是,如果您像我一样对编码相当“松散”,它会提供大量错误和警告。要在我的配置中禁用此功能,我执行了以下操作:
因此,如果您使用 Mason 与 pylint 进行 linting,并且 pylsp 也正常工作,那么您可能会收到很多错误,其中一些错误可能会多次出现。在 lsp 和 linting 上观看对我有帮助的一个好视频是 https://www.youtube.com/watch?v=ybUE4D80XSk&t=1382s&ab_channel=JoseanMartinez 以及 https://youtu.be/NL8D8EkphUw。我的代码非常适合他在后面的视频中展示的示例,他使用pyright,我使用pylsp instad。他在后面的视频中执行此操作的具体部分是 26:38。
您还可以设置选项来保持 pylsp 和/或 pylint 的 linting,但禁用某些错误消息,例如“line to long”(谁没有超过 80 个屏幕字符可供使用?),其操作与上面的代码类似,但是在 linter 配置中,我使用 nvim-lint (老兄只在视频中简要提到了这一点):
这来自帖子:如何禁用 Pylint 警告?
此处的附加信息: https://docs.pylint.org/faq.html#can-i-give-pylint-a-file-as-an-argument-instead-of-a-module
If anyone is still having this issue there is linting being through pycodestyle. it appears from the pylsp github page (https://github.com/python-lsp/python-lsp-server#installation) that pylint is disabled by default but the pydocstyle is no which provides a load of errors and warnings if your quite "loose" with coding as i am. to disable this within my config i did the following:
so if you are using Mason to do linting with pylint and you have the pylsp working also then you may get a lot of errors and some of those might appear multiple times. a good video/videos to watch on lsp and linting that helped me is https://www.youtube.com/watch?v=ybUE4D80XSk&t=1382s&ab_channel=JoseanMartinez and also https://youtu.be/NL8D8EkphUw. My code fits his example he showed in that later video nicely where he uses pyright, i use pylsp instad. The specific part of that later video where he does this is 26:38.
you can also setup options for keeping linting with pylsp and/or pylint but disabling certain error messages like "line to long" (who hasn't got more than 80 chars of screen to use?) that is done similar to this above code but in the linter config, i use nvim-lint (dude only briefly mentions this in the videos):
this comes from the post : How do I disable a Pylint warning?
additional info here: https://docs.pylint.org/faq.html#can-i-give-pylint-a-file-as-an-argument-instead-of-a-module