Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add customization point to retrieve next-checkers #1836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

damienrg
Copy link

@damienrg damienrg commented Nov 13, 2020

This PR introduce a customization point to retrieve next checkers.

In 0d250c9, the customization point is for a given checker based on new next-checkers-function property.

In 67ce045, the customization point is flycheck-next-checkers-function that is buffer local.

Related to:
#1660
#1762
emacs-lsp/lsp-mode#2329

@CLAassistant
Copy link

CLAassistant commented Nov 13, 2020

CLA assistant check
All committers have signed the CLA.

@wyuenho
Copy link
Contributor

wyuenho commented Feb 8, 2021

This is an interesting approach. Can you give a couple of examples of how one would use this to say, chain other checkers to lsp-mode's checker? I imagine python, JS and go devs will run into this issue the most.

@yyoncho
Copy link

yyoncho commented Feb 8, 2021

@wyuenho you may wanna check - #1762 (comment)

@damienrg
Copy link
Author

damienrg commented Feb 8, 2021

Can you give a couple of examples of how one would use this to say, chain other checkers to lsp-mode's checker? I imagine python, JS and go devs will run into this issue the most.

Example with lsp and the major-mode:

(defun my-flycheck-lsp-next-checkers (checker)
  (pcase major-mode
    ('sh-mode
     (pcase checker
       ('lsp '(sh-shellcheck sh-bash))
       ('sh-shellcheck '(sh-bash))
       ))
    ('web-mode '(javascript-eslint))
    )
  )

(defcustom my-lsp-flycheck-next-checkers-function nil
  "Variable to hold the function that returns flycheck next checkers for lsp."
  :type '(choice function (const nil)))

(make-variable-buffer-local 'my-lsp-flycheck-next-checkers-function)

;; in my case I only use this function for lsp checker
(defun my-lsp-flycheck-next-checkers (checker)
  "Function called by flycheck to find next checkers for CHECKER."
  (when (functionp my-lsp-flycheck-next-checkers-function)
    (funcall my-lsp-flycheck-next-checkers-function checker)))

(flycheck-set-next-checkers-function 'lsp #'my-lsp-flycheck-next-checkers)

(add-hook 'lsp-after-initialize-hook
          (lambda()
            (setq my-lsp-flycheck-next-checkers-function #'my-flycheck-lsp-next-checkers)))

@damienrg damienrg force-pushed the add-customization-point-to-retrieve-next-checkers branch from 0d250c9 to 67ce045 Compare February 9, 2021 17:05
@damienrg
Copy link
Author

damienrg commented Feb 9, 2021

With the previous code to have (lsp foo bar), you would also have to do: (flycheck-set-next-checkers-function 'foo #'your-function) because of the way flycheck works.

With the new code, you should be able to do :

(defun my-flycheck-lsp-next-checkers (checker)
  (pcase major-mode
    ('sh-mode
     (pcase checker
       ('lsp '(sh-shellcheck sh-bash))
       ('sh-shellcheck '(sh-bash))
       ))
    ('web-mode '(javascript-eslint))
    )
  )
  
  (add-hook 'lsp-after-initialize-hook
          (lambda()
            (setq flycheck-next-checkers-function #'my-flycheck-lsp-next-checkers)))

Anyway, I do not think this PR will land and you can use an advice as @yyoncho mentioned.

@wyuenho
Copy link
Contributor

wyuenho commented Feb 9, 2021

Why won't this land? Buffer local checker chain sounds like a great idea to me.

@cpitclaudel
Copy link
Member

Why won't this land? Buffer local checker chain sounds like a great idea to me.

Because none of the maintainers have found the time to review the code, unfortunately :/ I'm on the job market atm and finishing a PhD, so not much time for free software.

Additionally, what this PR does can already be achieved with advice; yyoncho posted sample code for that in his previous comment. With that and the buffer-local obarray options, there's a family of possible design choices that need to be evaluated.

@damienrg , thanks a lot for the PR. Have you had a look at the advice-based solution? Is there a reason to prefer this patch over that? Your example use case would work the same, just with advice-add instead of (setq flycheck-next-checkers-function. WDYT?

@damienrg
Copy link
Author

damienrg commented Feb 10, 2021

wyuenho:
Why won't this land? Buffer local checker chain sounds like a great idea to me.

I have opened this PR to have feedback about the solution I propose to chain checkers and it is maybe not the right way to do it.

cpitclaudel:
@damienrg , thanks a lot for the PR. Have you had a look at the advice-based solution? Is there a reason to prefer this patch over that? Your example use case would work the same, just with advice-add instead of (setq flycheck-next-checkers-function. WDYT?

Yes it works the same way. The main difference is that advice-based solution means it is not an official feature of flycheck.

From a user point of view, I would like to be able to do either:

  1. (setq flycheck-use-checkers '(foo bar baz))
  2. (setq flycheck-use-checkers-function #'my-fun) where my-fun returns a list of checkers
  3. (flycheck-use-checkers '(foo bar baz)) that automatically creates the correct chain.

With that and the buffer-local obarray options, there's a family of possible design choices that need to be evaluated.

I do not believe that changing properties of a checker is the way to go because the user has to change the properties on all the next checkers or flycheck should provide (flycheck-use-checkers '(foo bar baz)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants