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

[#408] add clangd command line options validator #411

Merged
merged 9 commits into from
Feb 2, 2025

Conversation

ghentschke
Copy link
Contributor

if clangd version >= 11, then the clangd binary will be called with configured command line options plus --check and --log=error. If the stderr stream remains empty everything is fine and we can go on. Otherwise we through an IOException in the start() method. This leads to an error dialog with the strings returned from stderr stream.

fixes #408

if clangd version >= 11, then the clangd binary will be called with
configured command line options plus --check and --log=error.
If the stderr stream remains empty everything is fine and we can go on.
Otherwise we through an IOException in the start() method. This leads to
an error dialog with the strings returned from stderr stream.

fixes eclipse-cdt#408
@ghentschke
Copy link
Contributor Author

I want to add some unit tests.

@ghentschke
Copy link
Contributor Author

ghentschke commented Feb 1, 2025

If clangd version <= 11 then you'll see this log entry:

!ENTRY org.eclipse.cdt.lsp.clangd 2 0 2025-02-01 18:48:32.865
!MESSAGE The clangd version does not support command line option check!

and this is the error message for clangd versions >= 12:
image

to support for example `Ubuntu clangd version`
Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghentschke I have left some line comments. However I have concerns that the overall design of this is too harsh. By that I mean it can stop LSP4E from trying to start clangd because clangd --check reports an error.

There are a few cases that concern me:

  1. This use of temp files means .clangd and .clang-format will be picked up from /tmp on Linux or even home directory on Windows. This will cause false negatives if that clangd/clangformat file has validation errors.
  2. It seems reasonable that there are some arrangement of command line options that may cause error logging, but not stop functioning of clangd

For 1. here is some terminal commands I tried:

$ echo "nonesense" > .clangd
$ clangd --check=a.c --log=error
E[15:27:07.145] config error at /tmp/.clangd:1:0: Config should be a dictionary
$ rm .clangd
$ echo "nonesense" > .clang-format
$ clangd --check=a.c --log=error
/tmp/.clang-format:1:1: error: not a mapping
nonesense
^~~~~~~~~
/tmp/.clang-format:1:1: error: not a mapping
nonesense
^~~~~~~~~

And with the .clangd left in /tmp this is what I see in the UI:

image

The mitigating factor is that the error message shows that there is an errant dot file in /tmp (or presumably home directory on Windows)

@ghentschke
Copy link
Contributor Author

There are a few cases that concern me:

  • This use of temp files means .clangd and .clang-format will be picked up from /tmp on Linux or even home directory on Windows. This will cause false negatives if that clangd/clangformat file has validation errors.
  • It seems reasonable that there are some arrangement of command line options that may cause error logging, but not stop functioning of clangd

I agree. I'll add a regex to filter only for the clangd(.exe)?: <error> messages. These errors seems to prevent clangd from being executed and are the cause for the behavior described in #408.

@ghentschke
Copy link
Contributor Author

ghentschke commented Feb 2, 2025

Maybe we should add an option flag to enable this pre-launch check. But I would enable it as default. When the check causes trouble on some OS or clangd versions it can be deactivated.

* @param clangdBinaryPath absolute path to clangd binary
* @return IStatus.OK if validation is supported for the given clangd binary, otherwise IStatus.CANCEL
*/
public IStatus supportsValidation(final String clangdBinaryPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can remove this method to simplify API and return IStatus.CANCEL from validateCommandLineOptions if binary doesn't support validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add an option flag to enable this pre-launch check. But I would enable it as default. When the check causes trouble on some OS or clangd versions it can be deactivated.

Sounds like a good idea - definitely default to on, but this does allow us to field disable an over aggressive command line validation failure.

BTW it would be great if LSP4E could detect the excessive restart problem and prompt user to disable language server. Not sure what that would take.

@ghentschke
Copy link
Contributor Author

Any objections @jonahgraham or @ruspl-afed ? Otherwise I would merge it

@ghentschke ghentschke merged commit 000f3a8 into eclipse-cdt:main Feb 2, 2025
3 checks passed
@ghentschke
Copy link
Contributor Author

@jonahgraham and @ruspl-afed Thank you both for your fast and excellent reviews!

@ghentschke ghentschke deleted the fix-repetitive-start-errors branch February 2, 2025 19:46
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.

Repetitive error messages on faulty clangd start
3 participants