Open palapapa opened 1 year ago
i'm using vscode-clangd in remote linux, same issue as you posted. Moreover, Errors in the following came up periodically.
Clangd version (from the log, or clangd --version): 16.0.0 clangd extension version: 0.1.23 Operating system: centos 2.6
Could you attach complete logs please (the snippet you posted does not contain, for example, the textDocument/publishDiagnostics
message), as well as the source file you have open?
@HighCommand Log.txt
As for the source file, a file with only the main function and printf("", 1);
causes this issue, too.
I'm seeing a lot of diagnostics in the system headers, including ones like this:
V[17:43:51.062] Dropped diagnostic: C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/include\stdio.h: 'format' attribute argument not supported: gnu_printf
I wonder if perhaps these indicate that clangd is not parsing your system headers correctly, and this is what leads to its inability to issue warnings like -Wformat.
I notice also the following in the log:
I[17:43:47.105] Failed to find compilation database for d:\Desktop\C\College\Vending Machine\Test.c I[17:43:47.105] ASTWorker building file d:\Desktop\C\College\Vending Machine\Test.c version 2 with command clangd fallback [d:\Desktop\C\College\Vending Machine] "C:\TDM-GCC-64\bin\clang" -Weverything -Wno-used-but-marked-unused -Wno-declaration-after-statement -Wno-vla -Wno-missing-prototypes -IC:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/include -IC:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../include -IC:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/include-fixed -IC:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/include -nostdinc -target x86_64-pc-windows-gnu "-resource-dir=c:\Users\User\AppData\Roaming\Code\User\globalStorage\llvm-vs-code-extensions.vscode-clangd\install\15.0.3\clangd_15.0.3\lib\clang\15.0.3" -- "d:\Desktop\C\College\Vending Machine\Test.c"
Where are these flags, such as the TDM-GCC include paths and -nostdinc
, coming from -- did you specify them in C:\Users\User\AppData\Local\clangd\config.yaml?
If so, you may want to try using --query-driver
as described at https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc as an alternative to overriding the standard library include paths manually. (Note that using --query-driver
requires you to have a compile_commands.json
, see https://clangd.llvm.org/installation#project-setup for more about that.)
I am using compile_flags.txt
to set the -nostdinc
flags etc. to override the headers because otherwise, clangd would always pick up the MSVC headers. And it's only a single file project so I thought using compile_commands.json
would be an overkill.
And it's only a single file project so I thought using
compile_commands.json
would be an overkill.
Yeah, that's understandable. In clangd 16 you can use --query-driver
without compile_commands.json
, by setting the path of the compiler to be queried using the Compiler:
key (under CompileFlags:
) in the clangd config file. You can get a pre-release version of clangd 16 from the releases page (e.g. https://github.com/clangd/clangd/releases/tag/snapshot_20221127 is the current latest weekly snapshot), so that's an option to try.
Alternatively, if you use something like make
to build your single file, you can generate a compile_commands.json
using a tool such as https://github.com/nickdiego/compiledb.
One way or another, I would suggest trying --query-driver
as the way to get clangd to use the TDM-GCC header paths, rather than specifying them manually.
The same problem occurs when I Ctrl-click a function to access the library.
I use clangd via the compile_command.json file generated by cmake.
// compile_command.json
[
{
"directory": "C:/Users/xxx/source/repos/CLANG/HelloWorld/build",
"command": "C:\\Users\\xxx\\scoop\\apps\\mingw-winlibs-llvm-ucrt\\current\\bin\\clang++.exe -Wall -fcolor-diagnostics -g -std=c++17 -o CMakeFiles\\HelloWorld.dir\\main.cpp.obj -c C:\\Users\\xxx\\source\\repos\\CLANG\\HelloWorld\\main.cpp",
"file": "C:\\Users\\xxx\\source\\repos\\CLANG\\HelloWorld\\main.cpp"
}
]
File contents for testing:
// main.cpp
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello,world!" << std::endl;
return 1;
}
This is the relevant log information I checked:
I[16:14:27.019] --> textDocument/clangd.fileStatus
V[16:14:27.019] >>> {
"jsonrpc": "2.0",
"method": "textDocument/clangd.fileStatus",
"params": {
"state": "idle",
"uri": "file:///c:/Users/xxx/scoop/apps/mingw-winlibs-llvm-ucrt/12.2.0-15.0.6-10.0.0-r3/include/c%2B%2B/12.2.0/ostream"
}
}
[Error - 16:14:27] Request textDocument/codeAction failed.
[object Object]
V[16:14:27.978] <<< {
"id": 30,
"jsonrpc": "2.0",
"method": "textDocument/semanticTokens/full/delta",
"params": {
"previousResultId": "1",
"textDocument": {
"uri": "file:///c%3A/Users/xxx/scoop/apps/mingw-winlibs-llvm-ucrt/12.2.0-15.0.6-10.0.0-r3/include/c%2B%2B/12.2.0/ostream"
}
}
}
I[16:14:27.978] <-- textDocument/semanticTokens/full/delta(30)
V[16:14:27.980] ASTWorker running SemanticHighlights on version 1 of c:/Users/xxx/scoop/apps/mingw-winlibs-llvm-ucrt/12.2.0-15.0.6-10.0.0-r3/include/c++/12.2.0/ostream
I[16:14:27.985] --> reply:textDocument/semanticTokens/full/delta(30) 6 ms
V[16:14:27.985] >>> {
"id": 30,
"jsonrpc": "2.0",
"result": {
"edits": [],
"resultId": "2"
}
}
I[16:14:27.985] --> textDocument/clangd.fileStatus
V[16:14:27.985] >>> {
"jsonrpc": "2.0",
"method": "textDocument/clangd.fileStatus",
"params": {
"state": "idle",
"uri": "file:///c:/Users/xxx/scoop/apps/mingw-winlibs-llvm-ucrt/12.2.0-15.0.6-10.0.0-r3/include/c%2B%2B/12.2.0/ostream"
}
}
The same problem occurs when I Ctrl-click a function to access the library.
The "Request XXX failed" errors in the linked screenshot don't seem to be related to this issue (which is about -Wformat
), probably best to file a new issue for it.
I recently changed from using TDM-GCC to mingw-w64 10.0.0 and this stopped happening. I wonder if that's related.
-Wformat does not trigger with very obviously wrong
printf
formats. Likeprintf("", 1);
Logs
System information Clangd version (from the log, or
clangd --version
): 15.0.3 clangd extension version: 0.1.23 Operating system: Windows 10