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

Inform user when clangd formatting fails #400

Open
ghentschke opened this issue Jan 25, 2025 · 3 comments
Open

Inform user when clangd formatting fails #400

ghentschke opened this issue Jan 25, 2025 · 3 comments

Comments

@ghentschke
Copy link
Contributor

As a user I want to be informed when clangd could not format my source file because the .clang-format file contains an invalid configuration.

Background: clangd uses a fallback config when the .clang-format file is missing or contains an invalid configuration. This happens silently.
See also the PR #399 and issue #398

@jonahgraham
Copy link
Member

An additional thought on here. Can we/should we capture stderr from clangd to some user feedback? In the case of the clang format file being invalid clangd does show errors on stderr. The errors are the same ones that you are now checking with --check call, but there may be others in the future, and clang format files may exist in parent directories outside of Eclipse project that clangd uses too.

Ideally clangd would not provide new formatting in the case of clang format errors. It seems vscode's extension suffers the same problem https://stackoverflow.com/a/78249405/2796832

@ghentschke
Copy link
Contributor Author

Yes. I am not sure how to solve this issue right now. IMO there are several use cases here:

  1. Run clangd --check=emptyFile. This is what we currently do to validate a .clang-format file editing.
    It can be done prior to the startup of clangd as well to check if the configuration settings under preferences -> clangd are valid. If it fails the user can be informed e.g. via a dialog. This won't work reliable for invalid .clangd-format files, as only the .clang-format file will be evaluated which clangd uses for the emtpyFile.
  2. Parse the clangd stderr output on a format file event for errors. This allows validation of all .cangd-files used for formatting by clangd. Here we have to listen to the stderr output only on a format event not to waste computing resources.

In this issue I would implement the second.

@ghentschke
Copy link
Contributor Author

Ideally clangd would not provide new formatting in the case of clang format errors. It seems vscode's extension suffers the same problem https://stackoverflow.com/a/78249405/2796832

Yes, that would be the best solution here.

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

No branches or pull requests

2 participants