forked from qt-creator/qt-creator
ClangCodeModel: Introduce dedicated class for clangd LSP client
Makes sense for modularization purposes, and it will soon get additional functionality. Change-Id: Ie8163d352fc408b4167ee2ce6147aa1fb19528eb Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -55,6 +55,8 @@ QtcPlugin {
|
||||
"clangconstants.h",
|
||||
"clangcurrentdocumentfilter.cpp",
|
||||
"clangcurrentdocumentfilter.h",
|
||||
"clangdclient.cpp",
|
||||
"clangdclient.h",
|
||||
"clangdiagnosticfilter.cpp",
|
||||
"clangdiagnosticfilter.h",
|
||||
"clangdiagnosticmanager.cpp",
|
||||
|
71
src/plugins/clangcodemodel/clangdclient.cpp
Normal file
71
src/plugins/clangcodemodel/clangdclient.cpp
Normal file
@@ -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 <cpptools/cppcodemodelsettings.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <languageclient/languageclientinterface.h>
|
||||
|
||||
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
|
43
src/plugins/clangcodemodel/clangdclient.h
Normal file
43
src/plugins/clangcodemodel/clangdclient.h
Normal file
@@ -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 <languageclient/client.h>
|
||||
|
||||
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
|
@@ -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 <cpptools/editordocumenthandle.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
|
||||
#include <languageclient/client.h>
|
||||
#include <languageclient/languageclientinterface.h>
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
|
||||
#include <texteditor/quickfix.h>
|
||||
@@ -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<Client *> clients = Utils::filtered(
|
||||
LanguageClientManager::clientsForProject(project),
|
||||
[](const LanguageClient::Client *c) {
|
||||
return c->name().startsWith(clientName())
|
||||
return qobject_cast<const ClangdClient *>(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)
|
||||
|
Reference in New Issue
Block a user