syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.63k stars 4.89k forks source link

Flycheck enabled by default in python-mode #16129

Closed guibor closed 7 months ago

guibor commented 1 year ago

Description :octocat:

Flycheck is enabled by default

Reproduction guide :beetle:

In python-mode, despite my having configured syntax-checking-enabled-by-default to nil (and as a result global-flycheck-mode is off), flycheck-mode is on in Python-mode. In order to solve, I need to explicitly (add-hook 'python-mode-hook (lambda () (flycheck-mode -1)))

Observed behaviour: :eyes: :broken_heart: flycheck-mode is on

Expected behaviour: :heart: :smile: flycheck mode if off

System Info :computer:

Backtrace :paw_prints:

<<BACKTRACE IF RELEVANT>>
emacs18 commented 1 year ago

How was syntax-checking-enabled-by-default set to nil?

In my testing setting this to nil early on is the key. If set early on, e.g., beginning of init.el, then flycheck-mode is not enabled. More specifically if this is set to nil prior to (configuration-layer/load) line, then flycheck-mode is not enabled.

emacs18 commented 1 year ago

I think we have a race condition in that syntax-checking-enable-by-default is referenced before it is set. As far as I can tell flycheck-mode is enabled by the following code.

(defun spacemacs/enable-flycheck (mode)
  "Use flycheck in MODE by default, if `syntax-checking-enable-by-default' t."
  (when (and syntax-checking-enable-by-default
             (listp flycheck-global-modes)
             (not (eq 'not (car flycheck-global-modes))))
    (add-to-list 'flycheck-global-modes mode)))

When this function is called, syntax-checking-enable-by-default is t rather than nil unless it is set to nil early enough.

guibor commented 1 year ago

Perhaps. I wonder if it's not related to lsp?

I think this is the culprit: lsp-mode-20230812.1018/lsp-diagnostics.el:240: (add-hook 'lsp-managed-mode-hook #'lsp-diagnostics--flycheck-report nil t))

This essentially makes all the flycheck setup meaningless if lsp is used (which is default for Python).

Update: Removing the hook doesn't seem to help

emacs18 commented 1 year ago

Please ignore my previous comments. I cannot reproduce my previous results!

I tested all over again using a vanilla startup file. syntax-checking-enabled-by-default seems to be working as expected, i.e., global-flycheck-mode has the same value as syntax-checking-enabled-by-default within python buffers. This is the case whether lsp is used or not.

guibor commented 1 year ago

Hi, one possible option is to (setq lsp-diagnostics-provider :none). Basically in practice the default lsp provider in lsp is flycheck and as a result this activates flycheck even the user disabled it. I would consider dealing with this, because the outcome was unexpected to me as a user.

smile13241324 commented 7 months ago

I have added some clarifying comments to the lsp layer. I don't think that we can safely limit the IDE features the LSP layer provides i.e. even if someone does not want to have flycheck in place lsp may use a different provider like flymake to do its job.

If only a part of the IDE feature should be used user's are expected to do manual configuration in there dotfile, the standard use-case should be the full range of IDE features.