linuxqtgccclangd

clangd code completion in vscode gives incorrect tips when developing Qt application


I use VSCodium and gcc complier to develop c++ in linux, clangd server and clangd vscode plugin have been installed. My example code is shown below.

QByteArray bytearray;
configFile.open(QIODevice::WriteOnly); //configFile is a QFile
configFile.write(bytearray);

Clangd doesn't mark the open() function as incorrect, but it tells me that the call to write() is incorrect with the following error message. However, building of my project is successful.

No matching member function for call to 'write'clang(ovl_no_viable_member_function_in_call)
qiodevice.h(90, 12): Candidate function not viable: no known conversion from 'QFile' to 'QIODevice' for object argument
qiodevice.h(89, 12): Candidate function not viable: no known conversion from 'QFile' to 'QIODevice' for object argument
qiodevice.h(88, 12): Candidate function not viable: requires 2 arguments, but 1 was provided

The QFile class inherits QFileDevice which inherits QIODevice, so the write() function should also exist in QFile. But clangd seems to not recognize the function. In qiodevice.h

qint64 write(const char *data, qint64 len);
qint64 write(const char *data);
qint64 write(const QByteArray &data);

My CMakeLists.txt

cmake_minimum_required(VERSION 3.21)
project(ClevoFanControl VERSION 2.0.4 LANGUAGES CXX)

set(CMAKE_BUILD_TYPE "Debug")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)

include_directories("include")

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
include_directories("/home/main/Applications/Qt/6.7.2/gcc_64/include")
set(CMAKE_PREFIX_PATH "/home/main/Applications/Qt/6.7.2/gcc_64/lib/cmake")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
include_directories("D:\\Applications\\Qt\\6.7.2\\mingw_64\\include")
set(CMAKE_PREFIX_PATH "D:\\Applications\\Qt\\6.7.2\\mingw_64\\lib\\cmake")
set(CMAKE_C_COMPILER "D:\\Applications\\Qt\\Tools\\mingw1120_64\\bin\\gcc.exe") #using custom gcc can cause error
set(CMAKE_CXX_COMPILER "D:\\Applications\\Qt\\Tools\\mingw1120_64\\bin\\g++.exe")
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
endif()
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

if(CMAKE_BUILD_TYPE MATCHES "Release")
add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()

find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui)
add_executable(ClevoFanControl main.cpp ClevoFanControl.cpp ClevoFanControl.qrc ClevoFanControl.rc config.ui monitor.ui)
target_link_libraries(ClevoFanControl PRIVATE Qt6::Core Qt6::Widgets Qt6::Gui)

clangd log

I[17:40:57.700] Debian clangd version 14.0.6
I[17:40:57.700] Features: linux+grpc
I[17:40:57.700] PID: 61201
I[17:40:57.700] Working directory: /home/main/User/Program/DevelopingProjects/ClevoFanControl
I[17:40:57.700] argv[0]: /usr/bin/clangd
I[17:40:57.700] Starting LSP over stdin/stdout
I[17:40:57.700] <-- initialize(0)
I[17:40:57.701] --> reply:initialize(0) 0 ms
I[17:40:57.703] <-- initialized
I[17:40:57.709] <-- textDocument/didOpen
I[17:40:57.709] --> textDocument/publishDiagnostics
I[17:40:57.710] Loaded compilation database from /home/main/User/Program/DevelopingProjects/ClevoFanControl/build/compile_commands.json
I[17:40:57.710] ASTWorker building file /home/main/User/Program/DevelopingProjects/ClevoFanControl/ClevoFanControl.cpp version 1 with command 
[/home/main/User/Program/DevelopingProjects/ClevoFanControl/build]
/usr/bin/g++ --driver-mode=g++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I/home/main/User/Program/DevelopingProjects/ClevoFanControl/build -I/home/main/User/Program/DevelopingProjects/ClevoFanControl -I/home/main/User/Program/DevelopingProjects/ClevoFanControl/build/ClevoFanControl_autogen/include -I/home/main/User/Program/DevelopingProjects/ClevoFanControl/include -isystem /home/main/Applications/Qt/6.7.2/gcc_64/include -isystem /home/main/Applications/Qt/6.7.2/gcc_64/include/QtCore -isystem /home/main/Applications/Qt/6.7.2/gcc_64/mkspecs/linux-g++ -isystem /home/main/Applications/Qt/6.7.2/gcc_64/include/QtWidgets -isystem /home/main/Applications/Qt/6.7.2/gcc_64/include/QtGui -g -fPIC -o CMakeFiles/ClevoFanControl.dir/ClevoFanControl.cpp.o -c -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.6 -- /home/main/User/Program/DevelopingProjects/ClevoFanControl/ClevoFanControl.cpp
I[17:40:57.710] Loaded compilation database from /home/main/User/Program/DevelopingProjects/ClevoFanControl/build/compile_commands.json
I[17:40:57.710] --> window/workDoneProgress/create(0)
I[17:40:57.710] Enqueueing 2 commands for indexing
I[17:40:57.712] --> textDocument/clangd.fileStatus
I[17:40:57.712] <-- reply(0)
I[17:40:57.712] --> $/progress
I[17:40:57.712] --> $/progress
I[17:40:58.090] --> $/progress
I[17:40:58.090] --> $/progress
I[17:40:58.160] <-- textDocument/documentLink(1)
I[17:40:58.161] <-- clangd/inlayHints(2)
I[17:40:58.396] <-- $/cancelRequest
I[17:40:58.408] <-- textDocument/documentLink(3)
I[17:40:58.451] <-- $/setTrace
I[17:40:58.452] unhandled notification $/setTrace
I[17:40:58.452] <-- textDocument/documentSymbol(4)
I[17:40:58.452] <-- textDocument/semanticTokens/full(5)
I[17:40:58.494] <-- textDocument/codeAction(6)
I[17:40:58.559] <-- $/setTrace
I[17:40:58.559] unhandled notification $/setTrace
I[17:40:58.816] <-- $/cancelRequest
I[17:40:58.817] <-- textDocument/codeAction(7)
I[17:40:58.818] <-- $/cancelRequest
I[17:40:58.818] <-- textDocument/codeAction(8)
I[17:40:59.447] <-- $/cancelRequest
I[17:40:59.448] <-- textDocument/codeAction(9)
I[17:40:59.449] <-- textDocument/documentSymbol(10)
I[17:40:59.477] <-- $/setTrace
I[17:40:59.477] unhandled notification $/setTrace
I[17:40:59.874] --> workspace/semanticTokens/refresh(1)
I[17:40:59.874] --> textDocument/clangd.fileStatus
I[17:40:59.875] <-- reply(1)
I[17:40:59.969] --> textDocument/publishDiagnostics
I[17:40:59.971] --> reply:textDocument/documentLink(1) 1810 ms, error: Task was cancelled.
[Error - 17:40:59] Request textDocument/documentLink failed.
[object Object]
I[17:40:59.972] --> reply:clangd/inlayHints(2) 1811 ms
I[17:40:59.972] --> reply:textDocument/documentLink(3) 1563 ms
I[17:40:59.973] --> reply:textDocument/documentSymbol(4) 1521 ms
I[17:40:59.974] --> reply:textDocument/semanticTokens/full(5) 1522 ms
I[17:40:59.975] --> reply:textDocument/codeAction(6) 1481 ms, error: Task was cancelled.
I[17:40:59.975] --> reply:textDocument/codeAction(7) 1157 ms, error: Task was cancelled.
I[17:40:59.975] --> reply:textDocument/codeAction(8) 1156 ms, error: Task was cancelled.
I[17:40:59.975] --> reply:textDocument/codeAction(9) 527 ms
I[17:40:59.975] --> reply:textDocument/documentSymbol(10) 526 ms
I[17:40:59.975] --> textDocument/clangd.fileStatus
[Error - 17:40:59] Request textDocument/codeAction failed.
[object Object]
[Error - 17:40:59] Request textDocument/codeAction failed.
[object Object]
[Error - 17:40:59] Request textDocument/codeAction failed.
[object Object]
I[17:41:00.227] <-- textDocument/codeAction(11)
I[17:41:00.227] --> reply:textDocument/codeAction(11) 0 ms
I[17:41:00.227] --> textDocument/clangd.fileStatus
I[17:41:01.654] <-- textDocument/semanticTokens/full/delta(12)
I[17:41:01.657] --> reply:textDocument/semanticTokens/full/delta(12) 3 ms
I[17:41:01.658] --> textDocument/clangd.fileStatus


OS: debian12 Qt: 6.7.2 gcc: 12.2.0

I included the qiodevice.h and qfiledevice.h but nothing changed.

I want the clangd language server to give correct message, help me ,thanks.


Solution

  • I finally solve the problem by using another clangd package. It seems that debian12's software package clangd doesn't work for me, while clangd-16 works well.