forked from qt-creator/qt-creator
Clangd: add quick fix factory
Change-Id: Idea71364b0e3f528e9dd366d46a2797f5056dfed Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -6,8 +6,8 @@ endif()
|
||||
add_qtc_plugin(ClangCodeModel
|
||||
CONDITION TARGET libclang
|
||||
DEPENDS ClangSupport CPlusPlus
|
||||
PLUGIN_DEPENDS Core CppTools LanguageClient ${TEST_LINK_DEPENDS} TextEditor
|
||||
PLUGIN_TEST_DEPENDS CppEditor QmakeProjectManager
|
||||
PLUGIN_DEPENDS Core CppEditor CppTools LanguageClient ${TEST_LINK_DEPENDS} TextEditor
|
||||
PLUGIN_TEST_DEPENDS QmakeProjectManager
|
||||
SOURCES
|
||||
clangactivationsequencecontextprocessor.cpp clangactivationsequencecontextprocessor.h
|
||||
clangactivationsequenceprocessor.cpp clangactivationsequenceprocessor.h
|
||||
@@ -24,11 +24,12 @@ add_qtc_plugin(ClangCodeModel
|
||||
clangcompletionchunkstotextconverter.cpp clangcompletionchunkstotextconverter.h
|
||||
clangcompletioncontextanalyzer.cpp clangcompletioncontextanalyzer.h
|
||||
clangconstants.h
|
||||
clangdclient.cpp clangdclient.h
|
||||
clangcurrentdocumentfilter.cpp clangcurrentdocumentfilter.h
|
||||
clangdclient.cpp clangdclient.h
|
||||
clangdiagnosticfilter.cpp clangdiagnosticfilter.h
|
||||
clangdiagnosticmanager.cpp clangdiagnosticmanager.h
|
||||
clangdiagnostictooltipwidget.cpp clangdiagnostictooltipwidget.h
|
||||
clangdquickfixfactory.cpp clangdquickfixfactory.h
|
||||
clangeditordocumentparser.cpp clangeditordocumentparser.h
|
||||
clangeditordocumentprocessor.cpp clangeditordocumentprocessor.h
|
||||
clangfixitoperation.cpp clangfixitoperation.h
|
||||
|
||||
@@ -42,7 +42,8 @@ SOURCES += \
|
||||
clangutils.cpp \
|
||||
clangoverviewmodel.cpp \
|
||||
clangdclient.cpp \
|
||||
clanggloballocatorfilters.cpp
|
||||
clangdquickfixfactory.cpp \
|
||||
clanggloballocatorfilters.cpp \
|
||||
|
||||
HEADERS += \
|
||||
clangactivationsequencecontextprocessor.h \
|
||||
@@ -83,7 +84,8 @@ HEADERS += \
|
||||
clangutils.h \
|
||||
clangoverviewmodel.h \
|
||||
clangdclient.h \
|
||||
clanggloballocatorfilters.h
|
||||
clangdquickfixfactory.h \
|
||||
clanggloballocatorfilters.h \
|
||||
|
||||
FORMS += clangprojectsettingswidget.ui
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ QtcPlugin {
|
||||
Depends { name: "Utils" }
|
||||
Depends { name: "ClangSupport" }
|
||||
Depends { name: "LanguageClient" }
|
||||
Depends { name: "CppEditor" }
|
||||
|
||||
Depends { name: "libclang"; required: false }
|
||||
Depends { name: "clang_defines" }
|
||||
|
||||
pluginTestDepends: [
|
||||
"CppEditor",
|
||||
"QmakeProjectManager",
|
||||
]
|
||||
|
||||
@@ -64,6 +64,8 @@ QtcPlugin {
|
||||
"clangdiagnosticmanager.h",
|
||||
"clangdiagnostictooltipwidget.cpp",
|
||||
"clangdiagnostictooltipwidget.h",
|
||||
"clangdquickfixfactory.cpp",
|
||||
"clangdquickfixfactory.h",
|
||||
"clangeditordocumentparser.cpp",
|
||||
"clangeditordocumentparser.h",
|
||||
"clangeditordocumentprocessor.cpp",
|
||||
|
||||
@@ -4,11 +4,11 @@ QTC_LIB_DEPENDS += \
|
||||
clangsupport
|
||||
QTC_PLUGIN_DEPENDS += \
|
||||
coreplugin \
|
||||
cppeditor \
|
||||
cpptools \
|
||||
languageclient \
|
||||
texteditor
|
||||
QTC_TEST_DEPENDS += \
|
||||
cppeditor \
|
||||
qmakeprojectmanager
|
||||
|
||||
equals(TEST, 1): QTC_PLUGIN_DEPENDS += qtsupport
|
||||
|
||||
62
src/plugins/clangcodemodel/clangdquickfixfactory.cpp
Normal file
62
src/plugins/clangcodemodel/clangdquickfixfactory.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clangdquickfixfactory.h"
|
||||
|
||||
#include "clangdclient.h"
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include <languageclient/languageclientquickfix.h>
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
ClangdQuickFixFactory::ClangdQuickFixFactory() = default;
|
||||
|
||||
void ClangdQuickFixFactory::match(const CppEditor::Internal::CppQuickFixInterface &interface,
|
||||
QuickFixOperations &result)
|
||||
{
|
||||
const auto client = ClangModelManagerSupport::instance()->clientForFile(interface.filePath());
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
const auto uri = DocumentUri::fromFilePath(interface.filePath());
|
||||
QTextCursor cursor(interface.textDocument());
|
||||
cursor.setPosition(interface.position());
|
||||
cursor.select(QTextCursor::LineUnderCursor);
|
||||
const QList<Diagnostic> &diagnostics = client->diagnosticsAt(uri, cursor);
|
||||
for (const Diagnostic &diagnostic : diagnostics) {
|
||||
ClangdDiagnostic clangdDiagnostic(diagnostic);
|
||||
if (const auto actions = clangdDiagnostic.codeActions()) {
|
||||
for (const CodeAction &action : *actions)
|
||||
result << new LanguageClient::CodeActionQuickFixOperation(action, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
43
src/plugins/clangcodemodel/clangdquickfixfactory.h
Normal file
43
src/plugins/clangcodemodel/clangdquickfixfactory.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 <cppeditor/cppquickfix.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
class ClangdQuickFixFactory : public CppEditor::CppQuickFixFactory
|
||||
{
|
||||
public:
|
||||
ClangdQuickFixFactory();
|
||||
|
||||
void match(const CppEditor::Internal::CppQuickFixInterface &interface,
|
||||
QuickFixOperations &result) override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
@@ -26,16 +26,17 @@
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include "clangconstants.h"
|
||||
#include "clangcurrentdocumentfilter.h"
|
||||
#include "clangdclient.h"
|
||||
#include "clangdquickfixfactory.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangutils.h"
|
||||
#include "clangfollowsymbol.h"
|
||||
#include "clanggloballocatorfilters.h"
|
||||
#include "clanghoverhandler.h"
|
||||
#include "clangoverviewmodel.h"
|
||||
#include "clangprojectsettings.h"
|
||||
#include "clangrefactoringengine.h"
|
||||
#include "clangcurrentdocumentfilter.h"
|
||||
#include "clanggloballocatorfilters.h"
|
||||
#include "clangoverviewmodel.h"
|
||||
#include "clangutils.h"
|
||||
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -128,6 +129,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
||||
// TODO: Enable this once we do document-level stuff with clangd (highlighting etc)
|
||||
// createClient(nullptr, {});
|
||||
m_generatorSynchronizer.setCancelOnWait(true);
|
||||
new ClangdQuickFixFactory(); // memory managed by CppEditor::g_cppQuickFixFactories
|
||||
}
|
||||
|
||||
ClangModelManagerSupport::~ClangModelManagerSupport()
|
||||
|
||||
Reference in New Issue
Block a user