emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 872 forks source link

Invalid face reference: lsp-flycheck-info-unnecessary (again) #4056

Closed vjohansen closed 1 year ago

vjohansen commented 1 year ago

Thank you for the bug report

Bug description

I get a lot of Invalid face reference in the messages buffer. See also latest comment here #2255

Sometimes 50 message per second in typescript buffer with lsp-mode enabled.

LSP :: Connected to [ts-ls:34084/starting c:/code/TCW].
Package dash-functional is obsolete; use dash 2.18.0 instead
LSP :: ts-ls:34084 initialized successfully in folders: (c:/code/TCW)
Invalid face reference: quote [198 times]
Undo
Invalid face reference: quote [69 times]
Undo
Invalid face reference: quote [3 times]
Undo
Invalid face reference: quote [171 times]
Invalid face reference: lsp-flycheck-info-unnecessary [2 times]
Invalid face reference: quote [3 times]
Invalid face reference: lsp-flycheck-info-unnecessary [2 times]
Invalid face reference: quote [3 times]
Invalid face reference: lsp-flycheck-info-unnecessary [9 times]
Invalid face reference: quote [3 times]
Invalid face reference: lsp-flycheck-info-unnecessary [7 times]
Invalid face reference: quote [3 times]
Invalid face reference: lsp-flycheck-info-unnecessary [8 times]
Invalid face reference: quote [3 times]
Invalid face reference: lsp-flycheck-info-unnecessary

lsp-mode version 20221207.1707

Steps to reproduce

change a ts-file so it does not compile

Expected behavior

No error messages in messages buffer

Which Language Server did you use?

ts-ls it seems

OS

Windows

Error callstack

No response

Anything else?

No response

yyoncho commented 1 year ago

can you try deleting your elpa dir + restarting emacs + reinstalling the packages?

vjohansen commented 1 year ago

Just tried it (deleted entire .emacs.d folder that included elpa folder). Same results : a lot of warnings.

vjohansen commented 1 year ago

I got mislead by reading the comments in #2255. I did not actually have the fix from leungbk since it is not released yet. The lsp-mode version I get from melpa is 8.0.0. Some of the commentors in #2255 does not appear to know this.

If I change lsp-diagnostics.el to include the fix the "Invalid face reference: lsp-flycheck-info-unnecessary" issue is gone and I am left with a LOT of "Invalid face reference: quote"

For example if I open a tsx file and change a variable declaration name I get 'xx is declared but its value is never read'. When I move left or right while point is in the identifier 10 occurences of "Invalid face reference: quote" happen each time.

Maybe this bug report should be closed and I should make a new for "Invalid face reference: quote". But this issue seems difficult to debug.

pixel-ant commented 10 months ago

These are my findings.

Current situation

This is what lsp-mode does:

For each error of some level and tagged with some tags that LSP server yields:

  1. Generate a generated flycheck level, a generated category and a generated face named after level and tags.
    • E.g: lsp-flycheck-info-unnecessary, lsp-flycheck-info-unnecessary-category and lsp-flycheck-info-unnecessary-face respectively.
  2. Set property face of generated category to generated face.
    • E.g: lsp-flycheck-info-unnecessary-category.face <- lsp-flycheck-info-unnecessary-face.
  3. Create a symbol overlay to highlight the erroneous symbol.
    • E.g: symbol-overlay-1.
  4. Set category property of symbol overlay to generated category.
    • E.g: symbol-overlay-1.category <- lsp-flycheck-info-unnecessary-category.
  5. Create a sideline overlay to display error message near the erroneous line.
    • E.g: sideline-overlay-1.
  6. Set face property of error message to generated flycheck level. BUG?????
    • E.g: "very bad done".face <- lsp-flycheck-info-unnecessary.

Consequences

Emacs can't find the face named as generated flycheck level as many times as characters in error message? So many error messages like

   Invalid face reference: lsp-flycheck-info-unnecessary [38 times]

are emitted.

If authors pretended to use the same face for symbol overlay and sideline overlay, both face properties should be set to generated face.

Transient solution

To avoid changing the original source code, the referenced face can be defined in init file. E.g:

(defface lsp-flycheck-info-unnecessary
  '((t))
  "Face which apply to side line for symbols not used.
Possibly erroneously redundant of lsp-flycheck-info-unnecessary-face."
  :group 'lsp-ui-sideline)

Then it can be themed or customized. Remember this is the face for sideline overlay. This has stopped all error messages for me.

Permanent solution

I prefer different faces for symbol overlay and sideline overlay. But that of sideline overlay should be named lsp-ui-sideline-{level}-{tags}-face. If a generated flycheck level like lsp-flycheck-info-unnecessary is made a face name, it confuses users when looking for a face name related to sidelines.

jonmoore commented 8 months ago

Thanks @pixel-ant , your analysis and commentary were very helpful.