vscode-clangd
vscode-clangd copied to clipboard
show errors and warning for whole project
VSCode with clangd shows all compiler warnings and errors for currently opened files and I love this feature! It really saves a lot of time. Is it possible to show warnings and errors not only for currently opened files but for the whole project? I tried googleing if there is a VSCode setting but according to this issue (https://github.com/Microsoft/vscode/issues/3002), it's language service specific and and the only other reference I've found is an experimental feature for typescript.
While it sounds good in theory, this really doesn't scale well. In order to do this, clangd would need to parse all files in your project, which on large projects potentially takes hours. Maybe there is merit for storing it while building the index, but I'm even skeptical of that. Another issue is some projects use pre-build steps, clangd wouldn't be able to run those which will likely result in spurious compilation warnings/errors.
It could be an optional feature which the user can enable per project. Or there could be some ignorelist, clangd doesn't check at all. Or just the other way around, a list of files which gets checked even if they are not opened in the editor. For small projects this would be a really nice addition and it is up to the user to decide if clangd can handle their whole project.
@JohnDoe2991, I think you just need to configure a build task with problem matcher (you can use $gcc
if you have Microsoft's C/C++ extension installed) and simply launch it when you want to see all warnings/errors for the project.
Hi,
I was just searching for this feature too! It would be very useful for many projects. Or at least, have a way to run it as a "linter" as a VS Code custom task.
Just to point out: Microsoft's C/C++ extension is incompatible with this extension, so you cannot use the $gcc
problem matcher shipped with it. So we also need a problem matcher. It would be nice if this extension could provide one to use.
Regards.
Microsoft's C/C++ extension is incompatible with this extension, so you cannot use the
$gcc
problem matcher shipped with it.
You can disable its IntelliSense (I believe it is "C_Cpp.intelliSenseEngine": "Disabled"
, but I may be wrong), keeping problem matcher and debugging capabilities. This will allow clangd
extension to step in for code comprehension and both extensions will happily coexist.
Hi,
I didn't know this trick! It works fine. Thank you.
Nevertheless, also providing a dedicated problem matcher by this extension could be valuable feature.
Regards.
While it sounds good in theory, this really doesn't scale well. In order to do this, clangd would need to parse all files in your project, which on large projects potentially takes hours. Maybe there is merit for storing it while building the index, but I'm even skeptical of that. Another issue is some projects use pre-build steps, clangd wouldn't be able to run those which will likely result in spurious compilation warnings/errors.
Why are people pretending that other languages don't do the same thing? For example, Dart parses and caches all files in a project, shows errors throughout the project, even captures TODOs in the project and show those as infos. I have worked in 250000 loc dart projects without any problem. An understandable stance would be to make this an opt-in feature. The extension can easily show for extremely large projects that the scope is too big and that the feature will be disabled.
Also, C++ files are self-contained due to headers, meaning that if any language can do this efficiently, it's C++, since file dependency is explicit due to the design of the language. People shouldn't have to tolerate 40-year old tooling & reasoning just because the language is 40 years old
This feature would be really helpful. It doesn't necessarily have to be active at all times, not even active on open/load project, it could be an issuable command, like >clangd: Scan (parse?) all files on compile_commands.json
I'd also like this, and I think that having it as "run on demand" feature would work. I use these tools mainly through Qt creator so there's a little bit of abstraction, but clazy works this way with that. It happens automatically with the file you have open after a bit of processing, but you can also run it for the whole project at once via a menu option with the results compiled into a single window for easy inspection.
With clangd's checks however, if I wanted to analyze my entire project my only option right now is to open each file one-by-one and then sit there for a short bit on each one as I hear my PC fans rev up then down in order to be sure that the file was checked in the case there were no warnings.
This would certainly take much, much longer (as well as being absurdly annoying) than if I could just initiate analysis of all files and then wait for the process to be finished, viewing the results all in one place so I can go through them efficiently.
I feel like this should be possible. For example, ale with vim
and clangd
is able to detect issues from headers.
@GMbrianlaw that is interesting, though it has to do more with https://github.com/clangd/clangd/issues/137 than this issue (this issue is about errors in other translation units that are not open in the editor)
Oh, I believe you are right. I checked again, and it seems my configuration of ale
doesn't use clangd
but recompiles every couple of seconds and checks for compile errors.
I am also looking for a feature like this. Having the ability to run something like $ clangd --parse-all
from the command line would be great
I am also looking for a feature like this. Having the ability to run something like
$ clangd --parse-all
from the command line would be great
Do you envision that printing the diagnostics on the command line?
If so, how is that different from just running your project's build (maybe with -fsyntax-only
added to CFLAGS
to skip the work of the compiler back-end)?
Oh just realised this is the vscode-clangd
repo not clangd
But yeah probably print to command line (and pipe to file).
Difference is I am working in an embedded system with arm-none-eabi-gcc toolchain, and compiling with clang is not an option but the clangd lsp generates some warnings that gcc doesn't. Clangd also analyses and gives warnings/errors for code that isn't used, such as some template code that is currently not instantiated. I found a operator precedence bug in some unused templated code yesterday from clangd - didn't get any reporting from gcc that there was an issue
Clangd also analyses and gives warnings/errors for code that isn't used, such as some template code that is currently not instantiated.
I suspect that comes from a clang-tidy checker, which you can also run on the command line.
(I have no opposition to clangd gaining the described command-line functionality, just trying to suggest existing solutions that might be useful to you today.)
So turns out GCC just doesn't issue warnings the same as clang - someone else reported gcc not reporting any issues for a similar operator precedence issue to what I had https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105283
Very possible that it is from a clang-tidy checker - although this would only be if it is bundled with clangd and on by default. I will try installing it directly and seeing if it reports.
Either way having the ability to run clangd over the codebase and dump to file would be great. Not having to set up a new tool would be ideal
FYI, I filed a feature request for this at the clangd command line level here - https://github.com/clangd/clangd/issues/1973. Since clangd already indexes the entire project when --background-index is enabled (https://clangd.llvm.org/design/indexing#backgroundindex)? It doesn't seem a big lift to have clangd write all the warnings to a provided file path. I don'y know how hard it is to expose that in vscode though,