I'm using vanilla Emacs and I installed lsp-mode
as follows:
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:config (defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
:hook (
(lsp-mode . lsp-enable-which-key-integration)
(go-mode . lsp-deferred)
(go-mode . lsp-go-install-save-hooks)
(typescript-mode . lsp-deferred)
(python-mode . lsp-deferred)
)
)
For Python I installed this. Everything seems to be working fine, but the problem is that I'm not able to override the default pycodestyle
settings. For example, it complains about long lines > 79
so I tried adding in the root of the project the following setup.cfg
:
[pycodestyle]
max-line-length=99
But it's not taken into account, am I missing something? I saw that there's the possibility to change the setting globally, but I'd like to have it on a per-project basis.
UPDATE
If pycodestyle
is ran from the terminal it works as expected: it complains with the default line-length limit and it doesn't if I increase it to a value that is greater to the longest line that I have in the code.
The *lsp-log*
buffer doesn't seem to provide any meaningful information:
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Command "pyls" is not present on the path.
Command "pylsp" is present on the path.
Found the following clients for /<some path>/sample-app/sample_app/__init__.py: (server-id pylsp, priority -1)
The following clients were selected based on priority: (server-id pylsp, priority -1)
If I exec the flycheck-describe-checker
command this is the output:
lsp is a Flycheck syntax checker.
This syntax checker checks syntax in the major mode(s)
`python-mode', `lsp-placeholder-mode', and uses a custom predicate.
Documentation:
A syntax checker using the Language Server Protocol (LSP)
provided by lsp-mode.
See https://github.com/emacs-lsp/lsp-mode.
If I disable flycheck
by executing the command flycheck-disable-checker
indeed the warnings go away, but it stops all the checks. So it seems like flycheck
is the responsible for not honoring the setup.cfg
.
I was able to understand what it seems to be happening. It seems that under the hood
flycheck
is usingflake8
instead ofpycodestyle
. Indeed after I changesetup.cfg
into this:Everything started working as expected.
The problem is that according to the documentation of
python-lsp-server
by default it should usepycodestyle
. Moreover, checking throughflake8
seems to be requiring 3rd party plugins according to the doc that I didn't install.Not everything works as expected yet, as for example I have some complaints related to
D100
andD104
that if I put them as ignore in the configuration their not honored yet.