diff --git a/src/plugins/clangcodemodel/CMakeLists.txt b/src/plugins/clangcodemodel/CMakeLists.txt index 7659ef06cc7..c8c8d9ec7fd 100644 --- a/src/plugins/clangcodemodel/CMakeLists.txt +++ b/src/plugins/clangcodemodel/CMakeLists.txt @@ -19,6 +19,7 @@ add_qtc_plugin(ClangCodeModel clangcompletionchunkstotextconverter.cpp clangcompletionchunkstotextconverter.h clangcompletioncontextanalyzer.cpp clangcompletioncontextanalyzer.h clangconstants.h + clangdclient.cpp clangdclient.h clangcurrentdocumentfilter.cpp clangcurrentdocumentfilter.h clangdiagnosticfilter.cpp clangdiagnosticfilter.h clangdiagnosticmanager.cpp clangdiagnosticmanager.h diff --git a/src/plugins/clangcodemodel/clangcodemodel.pro b/src/plugins/clangcodemodel/clangcodemodel.pro index 64254e131fd..298a2fef3fb 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.pro +++ b/src/plugins/clangcodemodel/clangcodemodel.pro @@ -41,6 +41,7 @@ SOURCES += \ clanguiheaderondiskmanager.cpp \ clangutils.cpp \ clangoverviewmodel.cpp \ + clangdclient.cpp clanggloballocatorfilters.cpp HEADERS += \ @@ -81,6 +82,7 @@ HEADERS += \ clanguiheaderondiskmanager.h \ clangutils.h \ clangoverviewmodel.h \ + clangdclient.h clanggloballocatorfilters.h FORMS += clangprojectsettingswidget.ui diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index e434fced5d4..d291d50fc0d 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -55,6 +55,8 @@ QtcPlugin { "clangconstants.h", "clangcurrentdocumentfilter.cpp", "clangcurrentdocumentfilter.h", + "clangdclient.cpp", + "clangdclient.h", "clangdiagnosticfilter.cpp", "clangdiagnosticfilter.h", "clangdiagnosticmanager.cpp", diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp new file mode 100644 index 00000000000..1368baa3e90 --- /dev/null +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "clangdclient.h" + +#include +#include +#include + +using namespace LanguageClient; + +namespace ClangCodeModel { +namespace Internal { + +static Q_LOGGING_CATEGORY(clangdLog, "qtc.clangcodemodel.clangd", QtWarningMsg); + +static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir) +{ + QString clangdArgs = "--index --background-index --limit-results=0"; + if (!jsonDbDir.isEmpty()) + clangdArgs += " --compile-commands-dir=" + jsonDbDir.toString(); + if (clangdLog().isDebugEnabled()) + clangdArgs += " --log=verbose --pretty"; + const auto interface = new StdIOClientInterface; + interface->setExecutable(CppTools::codeModelSettings()->clangdFilePath().toString()); + interface->setArguments(clangdArgs); + return interface; +} + +ClangdClient::ClangdClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir) + : Client(clientInterface(jsonDbDir)) +{ + setName(tr("clangd")); + LanguageFilter langFilter; + langFilter.mimeTypes = QStringList{"text/x-chdr", "text/x-c++hdr", "text/x-c++src", + "text/x-objc++src", "text/x-objcsrc"}; + setSupportedLanguage(langFilter); + LanguageServerProtocol::ClientCapabilities caps = Client::defaultClientCapabilities(); + caps.clearExperimental(); + caps.clearTextDocument(); + setClientCapabilities(caps); + setLocatorsEnabled(false); + setDocumentActionsEnabled(false); + setCurrentProject(project); + start(); +} + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangdclient.h b/src/plugins/clangcodemodel/clangdclient.h new file mode 100644 index 00000000000..b1d3bfc24d4 --- /dev/null +++ b/src/plugins/clangcodemodel/clangdclient.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +namespace ProjectExplorer { class Project; } + +namespace ClangCodeModel { +namespace Internal { + +class ClangdClient : public LanguageClient::Client +{ + Q_OBJECT +public: + ClangdClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir); +}; + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index aab88ea91d3..f934d0c54d8 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -26,6 +26,7 @@ #include "clangmodelmanagersupport.h" #include "clangconstants.h" +#include "clangdclient.h" #include "clangeditordocumentprocessor.h" #include "clangutils.h" #include "clangfollowsymbol.h" @@ -47,8 +48,6 @@ #include #include -#include -#include #include #include @@ -74,7 +73,6 @@ using namespace ClangCodeModel; using namespace ClangCodeModel::Internal; using namespace LanguageClient; -static Q_LOGGING_CATEGORY(clangdLog, "qtc.clangcodemodel.clangd", QtWarningMsg); static ClangModelManagerSupport *m_instance = nullptr; static CppTools::CppModelManager *cppModelManager() @@ -242,8 +240,6 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget } } -static QString clientName() { return "ccm-clangd"; } - void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project, const CppTools::ProjectInfo &projectInfo) { @@ -336,7 +332,7 @@ LanguageClient::Client *ClangModelManagerSupport::clientForProject( const QList clients = Utils::filtered( LanguageClientManager::clientsForProject(project), [](const LanguageClient::Client *c) { - return c->name().startsWith(clientName()) + return qobject_cast(c) && c->state() != Client::ShutdownRequested && c->state() != Client::Shutdown; }); @@ -347,29 +343,7 @@ LanguageClient::Client *ClangModelManagerSupport::clientForProject( Client *ClangModelManagerSupport::createClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir) { - QString clangdArgs = "--index --background-index --limit-results=0"; - if (!jsonDbDir.isEmpty()) - clangdArgs += " --compile-commands-dir=" + jsonDbDir.toString(); - if (clangdLog().isDebugEnabled()) - clangdArgs += " --log=verbose --pretty"; - const auto clientInterface = new StdIOClientInterface; - clientInterface->setExecutable(CppTools::codeModelSettings()->clangdFilePath().toString()); - clientInterface->setArguments(clangdArgs); - const auto client = new Client(clientInterface); - client->setName(clientName()); - LanguageFilter langFilter; - langFilter.mimeTypes = QStringList{"text/x-chdr", "text/x-c++hdr", "text/x-c++src", - "text/x-objc++src", "text/x-objcsrc"}; - client->setSupportedLanguage(langFilter); - LanguageServerProtocol::ClientCapabilities caps = Client::defaultClientCapabilities(); - caps.clearExperimental(); - caps.clearTextDocument(); - client->setClientCapabilities(caps); - client->setLocatorsEnabled(false); - client->setDocumentActionsEnabled(false); - client->setCurrentProject(project); - client->start(); - return client; + return new ClangdClient(project, jsonDbDir); } void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)