forked from qt-creator/qt-creator
Editor: unify assist processor handling
Define the run type of the processor by its implementation instead of a enum value of the provider. The execution of a processor inside the assist now follows a unified procedure. Change-Id: Ibe9fab324c6072e77702c2663946d7a9f562a085 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -46,7 +46,7 @@ public:
|
|||||||
unsigned completionOperator, CustomAssistMode mode);
|
unsigned completionOperator, CustomAssistMode mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *perform(AssistInterface *interface) override;
|
||||||
|
|
||||||
AssistProposalItemInterface *createItem(const QString &text, const QIcon &icon) const;
|
AssistProposalItemInterface *createItem(const QString &text, const QIcon &icon) const;
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
~ClangdCompletionAssistProcessor();
|
~ClangdCompletionAssistProcessor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *perform(AssistInterface *interface) override;
|
||||||
QList<AssistProposalItemInterface *> generateCompletionItems(
|
QList<AssistProposalItemInterface *> generateCompletionItems(
|
||||||
const QList<LanguageServerProtocol::CompletionItem> &items) const override;
|
const QList<LanguageServerProtocol::CompletionItem> &items) const override;
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public:
|
|||||||
ClangdFunctionHintProcessor(ClangdClient *client);
|
ClangdFunctionHintProcessor(ClangdClient *client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *perform(AssistInterface *interface) override;
|
||||||
|
|
||||||
ClangdClient * const m_client;
|
ClangdClient * const m_client;
|
||||||
};
|
};
|
||||||
@@ -152,7 +152,7 @@ IAssistProcessor *ClangdCompletionAssistProvider::createProcessor(
|
|||||||
if (contextAnalyzer.completionAction()
|
if (contextAnalyzer.completionAction()
|
||||||
!= ClangCompletionContextAnalyzer::CompleteIncludePath) {
|
!= ClangCompletionContextAnalyzer::CompleteIncludePath) {
|
||||||
class NoOpProcessor : public IAssistProcessor {
|
class NoOpProcessor : public IAssistProcessor {
|
||||||
IAssistProposal *perform(const AssistInterface *) override { return nullptr; }
|
IAssistProposal *perform(AssistInterface *) override { return nullptr; }
|
||||||
};
|
};
|
||||||
return new NoOpProcessor;
|
return new NoOpProcessor;
|
||||||
}
|
}
|
||||||
@@ -402,7 +402,7 @@ CustomAssistProcessor::CustomAssistProcessor(ClangdClient *client, int position,
|
|||||||
, m_mode(mode)
|
, m_mode(mode)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *CustomAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *CustomAssistProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
QList<AssistProposalItemInterface *> completions;
|
QList<AssistProposalItemInterface *> completions;
|
||||||
switch (m_mode) {
|
switch (m_mode) {
|
||||||
@@ -568,7 +568,7 @@ ClangdCompletionAssistProcessor::~ClangdCompletionAssistProcessor()
|
|||||||
<< "ClangdCompletionAssistProcessor took: " << m_timer.elapsed() << " ms";
|
<< "ClangdCompletionAssistProcessor took: " << m_timer.elapsed() << " ms";
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *ClangdCompletionAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *ClangdCompletionAssistProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
if (m_client->testingEnabled()) {
|
if (m_client->testingEnabled()) {
|
||||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||||
@@ -614,7 +614,7 @@ ClangdFunctionHintProcessor::ClangdFunctionHintProcessor(ClangdClient *client)
|
|||||||
, m_client(client)
|
, m_client(client)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *ClangdFunctionHintProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *ClangdFunctionHintProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
if (m_client->testingEnabled()) {
|
if (m_client->testingEnabled()) {
|
||||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||||
|
|||||||
@@ -42,18 +42,12 @@ public:
|
|||||||
void resetData(bool resetFollowSymbolData);
|
void resetData(bool resetFollowSymbolData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *perform(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
delete interface;
|
delete interface;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProposal *immediateProposal(const AssistInterface *) override
|
|
||||||
{
|
|
||||||
return createProposal(false);
|
return createProposal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *immediateProposalImpl() const;
|
|
||||||
IAssistProposal *createProposal(bool final) const;
|
IAssistProposal *createProposal(bool final) const;
|
||||||
VirtualFunctionProposalItem *createEntry(const QString &name, const Link &link) const;
|
VirtualFunctionProposalItem *createEntry(const QString &name, const Link &link) const;
|
||||||
|
|
||||||
@@ -67,7 +61,6 @@ public:
|
|||||||
: m_followSymbol(followSymbol) {}
|
: m_followSymbol(followSymbol) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RunType runType() const override { return Asynchronous; }
|
|
||||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||||
|
|
||||||
const QPointer<ClangdFollowSymbol> m_followSymbol;
|
const QPointer<ClangdFollowSymbol> m_followSymbol;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *perform(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
m_interface = interface;
|
m_interface = interface;
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ using namespace ProjectExplorer;
|
|||||||
|
|
||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
class CMakeFileCompletionAssist : public TextEditor::KeywordsCompletionAssistProcessor
|
class CMakeFileCompletionAssist : public KeywordsCompletionAssistProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMakeFileCompletionAssist();
|
CMakeFileCompletionAssist();
|
||||||
|
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) final;
|
IAssistProposal *performAsync(AssistInterface *interface) final;
|
||||||
};
|
};
|
||||||
|
|
||||||
CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
||||||
@@ -34,7 +34,7 @@ CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
|||||||
setDynamicCompletionFunction(&TextEditor::pathComplete);
|
setDynamicCompletionFunction(&TextEditor::pathComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *interface)
|
IAssistProposal *CMakeFileCompletionAssist::performAsync(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
Keywords kw;
|
Keywords kw;
|
||||||
const Utils::FilePath &filePath = interface->filePath();
|
const Utils::FilePath &filePath = interface->filePath();
|
||||||
@@ -48,7 +48,7 @@ IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
setKeywords(kw);
|
setKeywords(kw);
|
||||||
return KeywordsCompletionAssistProcessor::perform(interface);
|
return KeywordsCompletionAssistProcessor::performAsync(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public:
|
|||||||
ai->recreateTextDocument();
|
ai->recreateTextDocument();
|
||||||
InternalCppCompletionAssistProcessor processor;
|
InternalCppCompletionAssistProcessor processor;
|
||||||
|
|
||||||
const QScopedPointer<IAssistProposal> proposal(processor.perform(ai));
|
const QScopedPointer<IAssistProposal> proposal(processor.performAsync(ai));
|
||||||
if (!proposal)
|
if (!proposal)
|
||||||
return completions;
|
return completions;
|
||||||
ProposalModelPtr model = proposal->model();
|
ProposalModelPtr model = proposal->model();
|
||||||
|
|||||||
@@ -794,7 +794,7 @@ InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor()
|
|||||||
|
|
||||||
InternalCppCompletionAssistProcessor::~InternalCppCompletionAssistProcessor() = default;
|
InternalCppCompletionAssistProcessor::~InternalCppCompletionAssistProcessor() = default;
|
||||||
|
|
||||||
IAssistProposal * InternalCppCompletionAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal * InternalCppCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
m_interface.reset(static_cast<const CppCompletionAssistInterface *>(interface));
|
m_interface.reset(static_cast<const CppCompletionAssistInterface *>(interface));
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
InternalCppCompletionAssistProcessor();
|
InternalCppCompletionAssistProcessor();
|
||||||
~InternalCppCompletionAssistProcessor() override;
|
~InternalCppCompletionAssistProcessor() override;
|
||||||
|
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::IAssistProposal *createContentProposal();
|
TextEditor::IAssistProposal *createContentProposal();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
|
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
#include <texteditor/snippets/snippetassistcollector.h>
|
#include <texteditor/snippets/snippetassistcollector.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -18,7 +18,7 @@ namespace CPlusPlus { struct LanguageFeatures; }
|
|||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT CppCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
class CPPEDITOR_EXPORT CppCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CppCompletionAssistProcessor(int snippetItemOrder = 0);
|
explicit CppCompletionAssistProcessor(int snippetItemOrder = 0);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Internal {
|
|||||||
// -------------------------
|
// -------------------------
|
||||||
class CppQuickFixAssistProcessor : public IAssistProcessor
|
class CppQuickFixAssistProcessor : public IAssistProcessor
|
||||||
{
|
{
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *perform(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
QSharedPointer<const AssistInterface> dummy(interface); // FIXME: Surely this cannot be our way of doing memory management???
|
QSharedPointer<const AssistInterface> dummy(interface); // FIXME: Surely this cannot be our way of doing memory management???
|
||||||
return GenericProposal::createProposal(interface, quickFixOperations(interface));
|
return GenericProposal::createProposal(interface, quickFixOperations(interface));
|
||||||
@@ -39,10 +39,6 @@ class CppQuickFixAssistProcessor : public IAssistProcessor
|
|||||||
// -------------------------
|
// -------------------------
|
||||||
// CppQuickFixAssistProvider
|
// CppQuickFixAssistProvider
|
||||||
// -------------------------
|
// -------------------------
|
||||||
IAssistProvider::RunType CppQuickFixAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return Synchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *CppQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *CppQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class CppQuickFixAssistProvider : public TextEditor::IAssistProvider
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CppQuickFixAssistProvider() = default;
|
CppQuickFixAssistProvider() = default;
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,10 @@
|
|||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/assistinterface.h>
|
||||||
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||||
#include <texteditor/codeassist/genericproposalwidget.h>
|
#include <texteditor/codeassist/genericproposalwidget.h>
|
||||||
#include <texteditor/codeassist/assistinterface.h>
|
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
#include <texteditor/codeassist/iassistproposal.h>
|
#include <texteditor/codeassist/iassistproposal.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
@@ -79,14 +80,14 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VirtualFunctionAssistProcessor : public IAssistProcessor
|
class VirtualFunctionAssistProcessor : public AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VirtualFunctionAssistProcessor(const VirtualFunctionAssistProvider::Parameters ¶ms)
|
VirtualFunctionAssistProcessor(const VirtualFunctionAssistProvider::Parameters ¶ms)
|
||||||
: m_params(params)
|
: m_params(params)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *immediateProposal(const AssistInterface *) override
|
IAssistProposal *immediateProposal(AssistInterface *) override
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_params.function, return nullptr);
|
QTC_ASSERT(m_params.function, return nullptr);
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ public:
|
|||||||
return new VirtualFunctionProposal(m_params.cursorPosition, items, m_params.openInNextSplit);
|
return new VirtualFunctionProposal(m_params.cursorPosition, items, m_params.openInNextSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *perform(const AssistInterface *assistInterface) override
|
IAssistProposal *performAsync(AssistInterface *assistInterface) override
|
||||||
{
|
{
|
||||||
delete assistInterface;
|
delete assistInterface;
|
||||||
|
|
||||||
@@ -162,11 +163,6 @@ bool VirtualFunctionAssistProvider::configure(const Parameters ¶meters)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType VirtualFunctionAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return AsynchronousWithThread;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *VirtualFunctionAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *VirtualFunctionAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
return new VirtualFunctionAssistProcessor(m_params);
|
return new VirtualFunctionAssistProcessor(m_params);
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public:
|
|||||||
Parameters params() const { return m_params; }
|
Parameters params() const { return m_params; }
|
||||||
void clearParams() { m_params = Parameters(); }
|
void clearParams() { m_params = Parameters(); }
|
||||||
|
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
#include <texteditor/codeassist/iassistproposal.h>
|
#include <texteditor/codeassist/iassistproposal.h>
|
||||||
@@ -120,11 +121,12 @@ public:
|
|||||||
|
|
||||||
AssistInterface *assistInterface
|
AssistInterface *assistInterface
|
||||||
= m_editorWidget->createAssistInterface(FollowSymbol, ExplicitlyInvoked);
|
= m_editorWidget->createAssistInterface(FollowSymbol, ExplicitlyInvoked);
|
||||||
const QScopedPointer<IAssistProcessor> processor(createProcessor(assistInterface));
|
const QScopedPointer<AsyncProcessor> processor(
|
||||||
|
dynamic_cast<AsyncProcessor *>(createProcessor(assistInterface)));
|
||||||
const QScopedPointer<IAssistProposal> immediateProposal(
|
const QScopedPointer<IAssistProposal> immediateProposal(
|
||||||
processor->immediateProposal(assistInterface));
|
processor->immediateProposal(assistInterface));
|
||||||
const QScopedPointer<IAssistProposal> finalProposal(processor->perform(assistInterface));
|
const QScopedPointer<IAssistProposal> finalProposal(
|
||||||
|
processor->performAsync(assistInterface));
|
||||||
|
|
||||||
VirtualFunctionAssistProvider::clearParams();
|
VirtualFunctionAssistProvider::clearParams();
|
||||||
|
|
||||||
|
|||||||
@@ -27,22 +27,23 @@
|
|||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/assistinterface.h>
|
||||||
|
#include <texteditor/codeassist/assistproposalitem.h>
|
||||||
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
|
#include <texteditor/codeassist/genericproposal.h>
|
||||||
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||||
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
#include <texteditor/displaysettings.h>
|
#include <texteditor/displaysettings.h>
|
||||||
|
#include <texteditor/icodestylepreferences.h>
|
||||||
|
#include <texteditor/indenter.h>
|
||||||
|
#include <texteditor/tabsettings.h>
|
||||||
#include <texteditor/textdocumentlayout.h>
|
#include <texteditor/textdocumentlayout.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <texteditor/textmark.h>
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/typingsettings.h>
|
|
||||||
#include <texteditor/tabsettings.h>
|
|
||||||
#include <texteditor/icodestylepreferences.h>
|
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/indenter.h>
|
#include <texteditor/textmark.h>
|
||||||
#include <texteditor/codeassist/assistproposalitem.h>
|
#include <texteditor/typingsettings.h>
|
||||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
|
||||||
#include <texteditor/codeassist/assistinterface.h>
|
|
||||||
#include <texteditor/codeassist/genericproposal.h>
|
|
||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
@@ -1037,14 +1038,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeVimCompletionAssistProcessor : public IAssistProcessor
|
class FakeVimCompletionAssistProcessor : public AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FakeVimCompletionAssistProcessor(const IAssistProvider *provider)
|
FakeVimCompletionAssistProcessor(const IAssistProvider *provider)
|
||||||
: m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider))
|
: m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *performAsync(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
const QString &needle = m_provider->needle();
|
const QString &needle = m_provider->needle();
|
||||||
|
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ static AssistProposalItem *createCompletionItem(const QString &text, const QIcon
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *GlslCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface));
|
m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface));
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/assistinterface.h>
|
||||||
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
#include <texteditor/codeassist/assistinterface.h>
|
|
||||||
#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
|
#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
|
||||||
|
|
||||||
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
@@ -67,12 +67,12 @@ public:
|
|||||||
bool isActivationCharSequence(const QString &sequence) const override;
|
bool isActivationCharSequence(const QString &sequence) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
class GlslCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~GlslCompletionAssistProcessor() override;
|
~GlslCompletionAssistProcessor() override;
|
||||||
|
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::IAssistProposal *createHintProposal(const QVector<GLSL::Function *> &symbols);
|
TextEditor::IAssistProposal *createHintProposal(const QVector<GLSL::Function *> &symbols);
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ static QString assistReasonString(AssistReason reason)
|
|||||||
return QString("unknown reason");
|
return QString("unknown reason");
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *LanguageClientCompletionAssistProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
m_assistInterface.reset(interface);
|
m_assistInterface.reset(interface);
|
||||||
QTC_ASSERT(m_client, return nullptr);
|
QTC_ASSERT(m_client, return nullptr);
|
||||||
@@ -454,11 +454,6 @@ IAssistProcessor *LanguageClientCompletionAssistProvider::createProcessor(
|
|||||||
m_snippetsGroup);
|
m_snippetsGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType LanguageClientCompletionAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return IAssistProvider::Asynchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LanguageClientCompletionAssistProvider::activationCharSequenceLength() const
|
int LanguageClientCompletionAssistProvider::activationCharSequenceLength() const
|
||||||
{
|
{
|
||||||
return m_activationCharSequenceLength;
|
return m_activationCharSequenceLength;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public:
|
|||||||
LanguageClientCompletionAssistProvider(Client *client);
|
LanguageClientCompletionAssistProvider(Client *client);
|
||||||
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
RunType runType() const override;
|
|
||||||
|
|
||||||
int activationCharSequenceLength() const override;
|
int activationCharSequenceLength() const override;
|
||||||
bool isActivationCharSequence(const QString &sequence) const override;
|
bool isActivationCharSequence(const QString &sequence) const override;
|
||||||
@@ -60,7 +59,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientCompletionAssistProcessor
|
|||||||
public:
|
public:
|
||||||
LanguageClientCompletionAssistProcessor(Client *client, const QString &snippetsGroup);
|
LanguageClientCompletionAssistProcessor(Client *client, const QString &snippetsGroup);
|
||||||
~LanguageClientCompletionAssistProcessor() override;
|
~LanguageClientCompletionAssistProcessor() override;
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||||
bool running() override;
|
bool running() override;
|
||||||
bool needsRestart() const override { return true; }
|
bool needsRestart() const override { return true; }
|
||||||
void cancel() override;
|
void cancel() override;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ FunctionHintProcessor::FunctionHintProcessor(Client *client)
|
|||||||
: m_client(client)
|
: m_client(client)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *FunctionHintProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
const QScopedPointer<const AssistInterface> deleter(interface);
|
const QScopedPointer<const AssistInterface> deleter(interface);
|
||||||
QTC_ASSERT(m_client, return nullptr);
|
QTC_ASSERT(m_client, return nullptr);
|
||||||
@@ -124,11 +124,6 @@ TextEditor::IAssistProcessor *FunctionHintAssistProvider::createProcessor(
|
|||||||
return new FunctionHintProcessor(m_client);
|
return new FunctionHintProcessor(m_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType FunctionHintAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return Asynchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FunctionHintAssistProvider::activationCharSequenceLength() const
|
int FunctionHintAssistProvider::activationCharSequenceLength() const
|
||||||
{
|
{
|
||||||
return m_activationCharSequenceLength;
|
return m_activationCharSequenceLength;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ public:
|
|||||||
explicit FunctionHintAssistProvider(Client *client);
|
explicit FunctionHintAssistProvider(Client *client);
|
||||||
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
RunType runType() const override;
|
|
||||||
|
|
||||||
int activationCharSequenceLength() const override;
|
int activationCharSequenceLength() const override;
|
||||||
bool isActivationCharSequence(const QString &sequence) const override;
|
bool isActivationCharSequence(const QString &sequence) const override;
|
||||||
@@ -45,7 +44,7 @@ class LANGUAGECLIENT_EXPORT FunctionHintProcessor : public TextEditor::IAssistPr
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FunctionHintProcessor(Client *client);
|
explicit FunctionHintProcessor(Client *client);
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||||
bool running() override { return m_currentRequest.has_value(); }
|
bool running() override { return m_currentRequest.has_value(); }
|
||||||
bool needsRestart() const override { return true; }
|
bool needsRestart() const override { return true; }
|
||||||
void cancel() override;
|
void cancel() override;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void CommandQuickFixOperation::perform()
|
|||||||
m_client->executeCommand(m_command);
|
m_client->executeCommand(m_command);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
m_assistInterface = QSharedPointer<const AssistInterface>(interface);
|
m_assistInterface = QSharedPointer<const AssistInterface>(interface);
|
||||||
|
|
||||||
@@ -122,11 +122,6 @@ LanguageClientQuickFixProvider::LanguageClientQuickFixProvider(Client *client)
|
|||||||
QTC_CHECK(client);
|
QTC_CHECK(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType LanguageClientQuickFixProvider::runType() const
|
|
||||||
{
|
|
||||||
return Asynchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *LanguageClientQuickFixProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *LanguageClientQuickFixProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
return new LanguageClientQuickFixAssistProcessor(m_client);
|
return new LanguageClientQuickFixAssistProcessor(m_client);
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class LANGUAGECLIENT_EXPORT LanguageClientQuickFixProvider : public TextEditor::
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LanguageClientQuickFixProvider(Client *client);
|
explicit LanguageClientQuickFixProvider(Client *client);
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -64,7 +63,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientQuickFixAssistProcessor
|
|||||||
public:
|
public:
|
||||||
explicit LanguageClientQuickFixAssistProcessor(Client *client) : m_client(client) {}
|
explicit LanguageClientQuickFixAssistProcessor(Client *client) : m_client(client) {}
|
||||||
bool running() override { return m_currentRequest.has_value(); }
|
bool running() override { return m_currentRequest.has_value(); }
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||||
void cancel() override;
|
void cancel() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class NimCompletionAssistProcessor : public QObject, public TextEditor::IAssistP
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) final
|
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) final
|
||||||
{
|
{
|
||||||
QTC_ASSERT(this->thread() == qApp->thread(), return nullptr);
|
QTC_ASSERT(this->thread() == qApp->thread(), return nullptr);
|
||||||
|
|
||||||
@@ -250,11 +250,6 @@ bool NimCompletionAssistProvider::isActivationCharSequence(const QString &sequen
|
|||||||
return !sequence.isEmpty() && isActivationChar(sequence.at(0));
|
return !sequence.isEmpty() && isActivationChar(sequence.at(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType NimCompletionAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return RunType::Asynchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "nimcompletionassistprovider.moc"
|
#include "nimcompletionassistprovider.moc"
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public:
|
|||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const final;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const final;
|
||||||
int activationCharSequenceLength() const final;
|
int activationCharSequenceLength() const final;
|
||||||
bool isActivationCharSequence(const QString &sequence) const final;
|
bool isActivationCharSequence(const QString &sequence) const final;
|
||||||
RunType runType() const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::createHintProposal(
|
|||||||
return new FunctionHintProposal(m_startPosition, model);
|
return new FunctionHintProposal(m_startPosition, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *assistInterface)
|
IAssistProposal *QmlJSCompletionAssistProcessor::performAsync(AssistInterface *assistInterface)
|
||||||
{
|
{
|
||||||
m_interface.reset(static_cast<const QmlJSCompletionAssistInterface *>(assistInterface));
|
m_interface.reset(static_cast<const QmlJSCompletionAssistInterface *>(assistInterface));
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
#include "qmljseditor_global.h"
|
#include "qmljseditor_global.h"
|
||||||
|
|
||||||
#include <qmljstools/qmljssemanticinfo.h>
|
#include <qmljstools/qmljssemanticinfo.h>
|
||||||
|
#include <texteditor/codeassist/assistinterface.h>
|
||||||
#include <texteditor/codeassist/assistproposalitem.h>
|
#include <texteditor/codeassist/assistproposalitem.h>
|
||||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
#include <texteditor/codeassist/asyncprocessor.h>
|
||||||
#include <texteditor/codeassist/completionassistprovider.h>
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||||
#include <texteditor/codeassist/iassistprocessor.h>
|
#include <texteditor/codeassist/iassistprocessor.h>
|
||||||
#include <texteditor/snippets/snippetassistcollector.h>
|
#include <texteditor/snippets/snippetassistcollector.h>
|
||||||
#include <texteditor/codeassist/assistinterface.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
@@ -51,13 +51,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class QmlJSCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
class QmlJSCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QmlJSCompletionAssistProcessor();
|
QmlJSCompletionAssistProcessor();
|
||||||
~QmlJSCompletionAssistProcessor() override;
|
~QmlJSCompletionAssistProcessor() override;
|
||||||
|
|
||||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::IAssistProposal *createContentProposal() const;
|
TextEditor::IAssistProposal *createContentProposal() const;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ QmlJSRefactoringFilePtr QmlJSQuickFixAssistInterface::currentFile() const
|
|||||||
// ---------------------------
|
// ---------------------------
|
||||||
class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
||||||
{
|
{
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *perform(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
return GenericProposal::createProposal(interface, findQmlJSQuickFixes(interface));
|
return GenericProposal::createProposal(interface, findQmlJSQuickFixes(interface));
|
||||||
}
|
}
|
||||||
@@ -58,11 +58,6 @@ class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
|||||||
// QmlJSQuickFixAssistProvider
|
// QmlJSQuickFixAssistProvider
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return Synchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
return new QmlJSQuickFixAssistProcessor;
|
return new QmlJSQuickFixAssistProcessor;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public:
|
|||||||
QmlJSQuickFixAssistProvider() = default;
|
QmlJSQuickFixAssistProvider() = default;
|
||||||
~QmlJSQuickFixAssistProvider() override = default;
|
~QmlJSQuickFixAssistProvider() override = default;
|
||||||
|
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ add_qtc_plugin(TextEditor
|
|||||||
codeassist/assistinterface.cpp codeassist/assistinterface.h
|
codeassist/assistinterface.cpp codeassist/assistinterface.h
|
||||||
codeassist/assistproposalitem.cpp codeassist/assistproposalitem.h
|
codeassist/assistproposalitem.cpp codeassist/assistproposalitem.h
|
||||||
codeassist/assistproposaliteminterface.h
|
codeassist/assistproposaliteminterface.h
|
||||||
|
codeassist/asyncprocessor.cpp codeassist/asyncprocessor.h
|
||||||
codeassist/codeassistant.cpp codeassist/codeassistant.h
|
codeassist/codeassistant.cpp codeassist/codeassistant.h
|
||||||
codeassist/completionassistprovider.cpp codeassist/completionassistprovider.h
|
codeassist/completionassistprovider.cpp codeassist/completionassistprovider.h
|
||||||
codeassist/documentcontentcompletion.cpp codeassist/documentcontentcompletion.h
|
codeassist/documentcontentcompletion.cpp codeassist/documentcontentcompletion.h
|
||||||
@@ -37,7 +38,6 @@ add_qtc_plugin(TextEditor
|
|||||||
codeassist/iassistprovider.cpp codeassist/iassistprovider.h
|
codeassist/iassistprovider.cpp codeassist/iassistprovider.h
|
||||||
codeassist/ifunctionhintproposalmodel.cpp codeassist/ifunctionhintproposalmodel.h
|
codeassist/ifunctionhintproposalmodel.cpp codeassist/ifunctionhintproposalmodel.h
|
||||||
codeassist/keywordscompletionassist.cpp codeassist/keywordscompletionassist.h
|
codeassist/keywordscompletionassist.cpp codeassist/keywordscompletionassist.h
|
||||||
codeassist/runner.cpp codeassist/runner.h
|
|
||||||
codeassist/textdocumentmanipulator.cpp codeassist/textdocumentmanipulator.h
|
codeassist/textdocumentmanipulator.cpp codeassist/textdocumentmanipulator.h
|
||||||
codeassist/textdocumentmanipulatorinterface.h
|
codeassist/textdocumentmanipulatorinterface.h
|
||||||
codecchooser.cpp codecchooser.h
|
codecchooser.cpp codecchooser.h
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
class ClipboardAssistProcessor: public IAssistProcessor
|
class ClipboardAssistProcessor: public IAssistProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override
|
IAssistProposal *perform(AssistInterface *interface) override
|
||||||
{
|
{
|
||||||
if (!interface)
|
if (!interface)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -86,11 +86,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IAssistProvider::RunType ClipboardAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return Synchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *ClipboardAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *ClipboardAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
return new ClipboardAssistProcessor;
|
return new ClipboardAssistProcessor;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class ClipboardAssistProvider: public IAssistProvider
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClipboardAssistProvider(QObject *parent = nullptr) : IAssistProvider(parent) {}
|
ClipboardAssistProvider(QObject *parent = nullptr) : IAssistProvider(parent) {}
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
58
src/plugins/texteditor/codeassist/asyncprocessor.cpp
Normal file
58
src/plugins/texteditor/codeassist/asyncprocessor.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "asyncprocessor.h"
|
||||||
|
|
||||||
|
#include "assistinterface.h"
|
||||||
|
#include "iassistproposal.h"
|
||||||
|
|
||||||
|
#include <utils/runextensions.h>
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
|
||||||
|
AsyncProcessor::AsyncProcessor()
|
||||||
|
{
|
||||||
|
QObject::connect(&m_watcher, &QFutureWatcher<IAssistProposal *>::finished, [this]() {
|
||||||
|
setAsyncProposalAvailable(m_watcher.result());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
IAssistProposal *AsyncProcessor::perform(AssistInterface *interface)
|
||||||
|
{
|
||||||
|
IAssistProposal *result = immediateProposal(interface);
|
||||||
|
m_interface = interface;
|
||||||
|
m_interface->prepareForAsyncUse();
|
||||||
|
m_watcher.setFuture(Utils::runAsync([this]() {
|
||||||
|
m_interface->recreateTextDocument();
|
||||||
|
return performAsync(m_interface);
|
||||||
|
}));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AsyncProcessor::running()
|
||||||
|
{
|
||||||
|
return m_watcher.isRunning();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncProcessor::cancel()
|
||||||
|
{
|
||||||
|
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal){
|
||||||
|
delete proposal;
|
||||||
|
QMetaObject::invokeMethod(QCoreApplication::instance(), [this] {
|
||||||
|
delete this;
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
IAssistProposal *AsyncProcessor::immediateProposal(AssistInterface *interface)
|
||||||
|
{
|
||||||
|
Q_UNUSED(interface)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AsyncProcessor::isCanceled() const
|
||||||
|
{
|
||||||
|
return m_watcher.isCanceled();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
32
src/plugins/texteditor/codeassist/asyncprocessor.h
Normal file
32
src/plugins/texteditor/codeassist/asyncprocessor.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "iassistprocessor.h"
|
||||||
|
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
|
||||||
|
class TEXTEDITOR_EXPORT AsyncProcessor : public TextEditor::IAssistProcessor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AsyncProcessor();
|
||||||
|
|
||||||
|
IAssistProposal *perform(AssistInterface *interface) final;
|
||||||
|
bool running() override;
|
||||||
|
void cancel() override;
|
||||||
|
|
||||||
|
virtual IAssistProposal *performAsync(AssistInterface *interface) = 0;
|
||||||
|
virtual IAssistProposal *immediateProposal(AssistInterface *interface);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool isCanceled() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AssistInterface *m_interface = nullptr;
|
||||||
|
QFutureWatcher<IAssistProposal *> m_watcher;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "iassistproposalwidget.h"
|
#include "iassistproposalwidget.h"
|
||||||
#include "assistinterface.h"
|
#include "assistinterface.h"
|
||||||
#include "assistproposalitem.h"
|
#include "assistproposalitem.h"
|
||||||
#include "runner.h"
|
|
||||||
#include "textdocumentmanipulator.h"
|
#include "textdocumentmanipulator.h"
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
@@ -81,10 +80,9 @@ private:
|
|||||||
private:
|
private:
|
||||||
CodeAssistant *q = nullptr;
|
CodeAssistant *q = nullptr;
|
||||||
TextEditorWidget *m_editorWidget = nullptr;
|
TextEditorWidget *m_editorWidget = nullptr;
|
||||||
Internal::ProcessorRunner *m_requestRunner = nullptr;
|
|
||||||
QMetaObject::Connection m_runnerConnection;
|
QMetaObject::Connection m_runnerConnection;
|
||||||
IAssistProvider *m_requestProvider = nullptr;
|
IAssistProvider *m_requestProvider = nullptr;
|
||||||
IAssistProcessor *m_asyncProcessor = nullptr;
|
IAssistProcessor *m_processor = nullptr;
|
||||||
AssistKind m_assistKind = TextEditor::Completion;
|
AssistKind m_assistKind = TextEditor::Completion;
|
||||||
IAssistProposalWidget *m_proposalWidget = nullptr;
|
IAssistProposalWidget *m_proposalWidget = nullptr;
|
||||||
QScopedPointer<IAssistProposal> m_proposal;
|
QScopedPointer<IAssistProposal> m_proposal;
|
||||||
@@ -207,92 +205,48 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
|
|||||||
m_requestProvider = provider;
|
m_requestProvider = provider;
|
||||||
IAssistProcessor *processor = provider->createProcessor(assistInterface);
|
IAssistProcessor *processor = provider->createProcessor(assistInterface);
|
||||||
|
|
||||||
switch (provider->runType()) {
|
processor->setAsyncCompletionAvailableHandler([this, reason, processor](
|
||||||
case IAssistProvider::Synchronous: {
|
IAssistProposal *newProposal) {
|
||||||
if (IAssistProposal *newProposal = processor->perform(assistInterface))
|
if (!processor->running()) {
|
||||||
displayProposal(newProposal, reason);
|
// do not delete this processor directly since this function is called from within the processor
|
||||||
delete processor;
|
QMetaObject::invokeMethod(QCoreApplication::instance(), [processor] {
|
||||||
break;
|
delete processor;
|
||||||
}
|
}, Qt::QueuedConnection);
|
||||||
case IAssistProvider::AsynchronousWithThread: {
|
|
||||||
if (IAssistProposal *newProposal = processor->immediateProposal(assistInterface))
|
|
||||||
displayProposal(newProposal, reason);
|
|
||||||
|
|
||||||
m_requestRunner = new ProcessorRunner;
|
|
||||||
m_runnerConnection = connect(m_requestRunner, &ProcessorRunner::finished,
|
|
||||||
this, [this, reason, sender = m_requestRunner] {
|
|
||||||
// Since the request runner is a different thread, there's still a gap in which the
|
|
||||||
// queued signal could be processed after an invalidation of the current request.
|
|
||||||
if (!m_requestRunner || m_requestRunner != sender)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IAssistProposal *proposal = m_requestRunner->proposal();
|
|
||||||
invalidateCurrentRequestData();
|
|
||||||
displayProposal(proposal, reason);
|
|
||||||
emit q->finished();
|
|
||||||
});
|
|
||||||
connect(m_requestRunner, &ProcessorRunner::finished,
|
|
||||||
m_requestRunner, &ProcessorRunner::deleteLater);
|
|
||||||
assistInterface->prepareForAsyncUse();
|
|
||||||
m_requestRunner->setProcessor(processor);
|
|
||||||
m_requestRunner->setAssistInterface(assistInterface);
|
|
||||||
m_requestRunner->start();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IAssistProvider::Asynchronous: {
|
|
||||||
processor->setAsyncCompletionAvailableHandler([this, reason, processor](
|
|
||||||
IAssistProposal *newProposal) {
|
|
||||||
if (!processor->running()) {
|
|
||||||
// do not delete this processor directly since this function is called from within the processor
|
|
||||||
QMetaObject::invokeMethod(QCoreApplication::instance(), [processor] {
|
|
||||||
delete processor;
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
if (processor != m_asyncProcessor)
|
|
||||||
return;
|
|
||||||
invalidateCurrentRequestData();
|
|
||||||
if (processor->needsRestart() && m_receivedContentWhileWaiting) {
|
|
||||||
delete newProposal;
|
|
||||||
m_receivedContentWhileWaiting = false;
|
|
||||||
requestProposal(reason, m_assistKind, m_requestProvider);
|
|
||||||
} else {
|
|
||||||
displayProposal(newProposal, reason);
|
|
||||||
if (processor->running())
|
|
||||||
m_asyncProcessor = processor;
|
|
||||||
else
|
|
||||||
emit q->finished();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// If there is a proposal, nothing asynchronous happened...
|
|
||||||
if (IAssistProposal *newProposal = processor->perform(assistInterface)) {
|
|
||||||
displayProposal(newProposal, reason);
|
|
||||||
delete processor;
|
|
||||||
} else if (!processor->running()) {
|
|
||||||
if (isUpdate)
|
|
||||||
destroyContext();
|
|
||||||
delete processor;
|
|
||||||
} else { // ...async request was triggered
|
|
||||||
if (IAssistProposal *newProposal = processor->immediateProposal(assistInterface))
|
|
||||||
displayProposal(newProposal, reason);
|
|
||||||
QTC_CHECK(!m_asyncProcessor);
|
|
||||||
m_asyncProcessor = processor;
|
|
||||||
}
|
}
|
||||||
|
if (processor != m_processor)
|
||||||
|
return;
|
||||||
|
invalidateCurrentRequestData();
|
||||||
|
if (processor->needsRestart() && m_receivedContentWhileWaiting) {
|
||||||
|
delete newProposal;
|
||||||
|
m_receivedContentWhileWaiting = false;
|
||||||
|
requestProposal(reason, m_assistKind, m_requestProvider);
|
||||||
|
} else {
|
||||||
|
displayProposal(newProposal, reason);
|
||||||
|
if (processor->running())
|
||||||
|
m_processor = processor;
|
||||||
|
else
|
||||||
|
emit q->finished();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
if (IAssistProposal *newProposal = processor->perform(assistInterface))
|
||||||
|
displayProposal(newProposal, reason);
|
||||||
|
if (!processor->running()) {
|
||||||
|
if (isUpdate)
|
||||||
|
destroyContext();
|
||||||
|
delete processor;
|
||||||
|
} else {
|
||||||
|
QTC_CHECK(!m_processor);
|
||||||
|
m_processor = processor;
|
||||||
}
|
}
|
||||||
} // switch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeAssistantPrivate::cancelCurrentRequest()
|
void CodeAssistantPrivate::cancelCurrentRequest()
|
||||||
{
|
{
|
||||||
if (m_requestRunner) {
|
if (m_processor) {
|
||||||
m_requestRunner->setDiscardProposal(true);
|
m_processor->cancel();
|
||||||
disconnect(m_runnerConnection);
|
if (!m_processor->running())
|
||||||
}
|
delete m_processor;
|
||||||
if (m_asyncProcessor) {
|
|
||||||
m_asyncProcessor->cancel();
|
|
||||||
delete m_asyncProcessor;
|
|
||||||
}
|
}
|
||||||
invalidateCurrentRequestData();
|
invalidateCurrentRequestData();
|
||||||
}
|
}
|
||||||
@@ -424,7 +378,7 @@ bool CodeAssistantPrivate::isDisplayingProposal() const
|
|||||||
|
|
||||||
bool CodeAssistantPrivate::isWaitingForProposal() const
|
bool CodeAssistantPrivate::isWaitingForProposal() const
|
||||||
{
|
{
|
||||||
return m_requestRunner != nullptr || m_asyncProcessor != nullptr;
|
return m_processor != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CodeAssistantPrivate::proposalPrefix() const
|
QString CodeAssistantPrivate::proposalPrefix() const
|
||||||
@@ -437,8 +391,7 @@ QString CodeAssistantPrivate::proposalPrefix() const
|
|||||||
|
|
||||||
void CodeAssistantPrivate::invalidateCurrentRequestData()
|
void CodeAssistantPrivate::invalidateCurrentRequestData()
|
||||||
{
|
{
|
||||||
m_asyncProcessor = nullptr;
|
m_processor = nullptr;
|
||||||
m_requestRunner = nullptr;
|
|
||||||
m_requestProvider = nullptr;
|
m_requestProvider = nullptr;
|
||||||
m_receivedContentWhileWaiting = false;
|
m_receivedContentWhileWaiting = false;
|
||||||
}
|
}
|
||||||
@@ -492,7 +445,7 @@ void CodeAssistantPrivate::notifyChange()
|
|||||||
|
|
||||||
bool CodeAssistantPrivate::hasContext() const
|
bool CodeAssistantPrivate::hasContext() const
|
||||||
{
|
{
|
||||||
return m_requestRunner || m_asyncProcessor || m_proposalWidget;
|
return m_processor || m_proposalWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeAssistantPrivate::destroyContext()
|
void CodeAssistantPrivate::destroyContext()
|
||||||
|
|||||||
@@ -13,11 +13,6 @@ CompletionAssistProvider::CompletionAssistProvider(QObject *parent)
|
|||||||
|
|
||||||
CompletionAssistProvider::~CompletionAssistProvider() = default;
|
CompletionAssistProvider::~CompletionAssistProvider() = default;
|
||||||
|
|
||||||
IAssistProvider::RunType CompletionAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return AsynchronousWithThread;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CompletionAssistProvider::activationCharSequenceLength() const
|
int CompletionAssistProvider::activationCharSequenceLength() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public:
|
|||||||
CompletionAssistProvider(QObject *parent = nullptr);
|
CompletionAssistProvider(QObject *parent = nullptr);
|
||||||
~CompletionAssistProvider() override;
|
~CompletionAssistProvider() override;
|
||||||
|
|
||||||
IAssistProvider::RunType runType() const override;
|
|
||||||
virtual int activationCharSequenceLength() const;
|
virtual int activationCharSequenceLength() const;
|
||||||
virtual bool isActivationCharSequence(const QString &sequence) const;
|
virtual bool isActivationCharSequence(const QString &sequence) const;
|
||||||
virtual bool isContinuationChar(const QChar &c) const;
|
virtual bool isContinuationChar(const QChar &c) const;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include "assistinterface.h"
|
#include "assistinterface.h"
|
||||||
#include "assistproposalitem.h"
|
#include "assistproposalitem.h"
|
||||||
|
#include "asyncprocessor.h"
|
||||||
#include "genericproposal.h"
|
#include "genericproposal.h"
|
||||||
#include "genericproposalmodel.h"
|
|
||||||
#include "iassistprocessor.h"
|
#include "iassistprocessor.h"
|
||||||
#include "../snippets/snippetassistcollector.h"
|
#include "../snippets/snippetassistcollector.h"
|
||||||
#include "../completionsettings.h"
|
#include "../completionsettings.h"
|
||||||
@@ -23,30 +23,22 @@
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
class DocumentContentCompletionProcessor final : public IAssistProcessor
|
class DocumentContentCompletionProcessor final : public AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DocumentContentCompletionProcessor(const QString &snippetGroupId);
|
DocumentContentCompletionProcessor(const QString &snippetGroupId);
|
||||||
~DocumentContentCompletionProcessor() final;
|
~DocumentContentCompletionProcessor() final;
|
||||||
|
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *performAsync(AssistInterface *interface) override;
|
||||||
bool running() final { return m_watcher.isRunning(); }
|
|
||||||
void cancel() final;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_snippetGroup;
|
QString m_snippetGroup;
|
||||||
QFutureWatcher<QStringList> m_watcher;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup)
|
DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup)
|
||||||
: m_snippetGroup(snippetGroup)
|
: m_snippetGroup(snippetGroup)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
IAssistProvider::RunType DocumentContentCompletionProvider::runType() const
|
|
||||||
{
|
|
||||||
return Asynchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *DocumentContentCompletionProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *DocumentContentCompletionProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
return new DocumentContentCompletionProcessor(m_snippetGroup);
|
return new DocumentContentCompletionProcessor(m_snippetGroup);
|
||||||
@@ -61,38 +53,9 @@ DocumentContentCompletionProcessor::~DocumentContentCompletionProcessor()
|
|||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createProposal(QFutureInterface<QStringList> &future, const QString &text,
|
IAssistProposal *DocumentContentCompletionProcessor::performAsync(AssistInterface *interface)
|
||||||
const QString &wordUnderCursor)
|
|
||||||
{
|
{
|
||||||
const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
|
QScopedPointer<AssistInterface> interfaceDeleter(interface);
|
||||||
|
|
||||||
QSet<QString> words;
|
|
||||||
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
|
|
||||||
int wordUnderCursorFound = 0;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
if (future.isCanceled())
|
|
||||||
return;
|
|
||||||
QRegularExpressionMatch match = it.next();
|
|
||||||
const QString &word = match.captured();
|
|
||||||
if (word == wordUnderCursor) {
|
|
||||||
// Only add the word under cursor if it
|
|
||||||
// already appears elsewhere in the text
|
|
||||||
if (++wordUnderCursorFound < 2)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!words.contains(word))
|
|
||||||
words.insert(word);
|
|
||||||
}
|
|
||||||
|
|
||||||
future.reportResult(Utils::toList(words));
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterface *interface)
|
|
||||||
{
|
|
||||||
QScopedPointer<const AssistInterface> assistInterface(interface);
|
|
||||||
if (running())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
int pos = interface->position();
|
int pos = interface->position();
|
||||||
|
|
||||||
@@ -113,27 +76,36 @@ IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterfa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TextEditor::SnippetAssistCollector snippetCollector(
|
||||||
|
m_snippetGroup, QIcon(":/texteditor/images/snippet.png"));
|
||||||
|
QList<AssistProposalItemInterface *> items = snippetCollector.collect();
|
||||||
|
|
||||||
const QString wordUnderCursor = interface->textAt(pos, length);
|
const QString wordUnderCursor = interface->textAt(pos, length);
|
||||||
const QString text = interface->textDocument()->toPlainText();
|
const QString text = interface->textDocument()->toPlainText();
|
||||||
|
|
||||||
m_watcher.setFuture(Utils::runAsync(&createProposal, text, wordUnderCursor));
|
const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
|
||||||
QObject::connect(&m_watcher, &QFutureWatcher<QStringList>::resultReadyAt,
|
QSet<QString> words;
|
||||||
&m_watcher, [this, pos](int index){
|
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
|
||||||
const TextEditor::SnippetAssistCollector snippetCollector(
|
int wordUnderCursorFound = 0;
|
||||||
m_snippetGroup, QIcon(":/texteditor/images/snippet.png"));
|
while (it.hasNext()) {
|
||||||
QList<AssistProposalItemInterface *> items = snippetCollector.collect();
|
if (isCanceled())
|
||||||
for (const QString &word : m_watcher.resultAt(index)) {
|
return nullptr;
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
const QString &word = match.captured();
|
||||||
|
if (word == wordUnderCursor) {
|
||||||
|
// Only add the word under cursor if it
|
||||||
|
// already appears elsewhere in the text
|
||||||
|
if (++wordUnderCursorFound < 2)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!words.contains(word)) {
|
||||||
auto item = new AssistProposalItem();
|
auto item = new AssistProposalItem();
|
||||||
item->setText(word);
|
item->setText(word);
|
||||||
items.append(item);
|
items.append(item);
|
||||||
|
words.insert(word);
|
||||||
}
|
}
|
||||||
setAsyncProposalAvailable(new GenericProposal(pos, items));
|
}
|
||||||
});
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentContentCompletionProcessor::cancel()
|
return new GenericProposal(pos, items);
|
||||||
{
|
|
||||||
if (running())
|
|
||||||
m_watcher.cancel();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public:
|
|||||||
DocumentContentCompletionProvider(
|
DocumentContentCompletionProvider(
|
||||||
const QString &snippetGroup = QString(Constants::TEXT_SNIPPET_GROUP_ID));
|
const QString &snippetGroup = QString(Constants::TEXT_SNIPPET_GROUP_ID));
|
||||||
|
|
||||||
RunType runType() const override;
|
|
||||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ public:
|
|||||||
IAssistProcessor();
|
IAssistProcessor();
|
||||||
virtual ~IAssistProcessor();
|
virtual ~IAssistProcessor();
|
||||||
|
|
||||||
virtual IAssistProposal *immediateProposal(const AssistInterface *) { return nullptr; }
|
virtual IAssistProposal *perform(AssistInterface *interface) = 0; // takes ownership
|
||||||
virtual IAssistProposal *perform(const AssistInterface *interface) = 0; // takes ownership
|
|
||||||
|
|
||||||
void setAsyncProposalAvailable(IAssistProposal *proposal);
|
void setAsyncProposalAvailable(IAssistProposal *proposal);
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,6 @@ class TEXTEDITOR_EXPORT IAssistProvider : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
IAssistProvider(QObject *parent = nullptr) : QObject(parent) {}
|
IAssistProvider(QObject *parent = nullptr) : QObject(parent) {}
|
||||||
|
|
||||||
enum RunType {
|
|
||||||
Synchronous,
|
|
||||||
Asynchronous,
|
|
||||||
AsynchronousWithThread
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual RunType runType() const = 0;
|
|
||||||
virtual IAssistProcessor *createProcessor(const AssistInterface *assistInterface) const = 0;
|
virtual IAssistProcessor *createProcessor(const AssistInterface *assistInterface) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ KeywordsCompletionAssistProcessor::KeywordsCompletionAssistProcessor(const Keywo
|
|||||||
, m_keywords(keywords)
|
, m_keywords(keywords)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IAssistProposal *KeywordsCompletionAssistProcessor::perform(const AssistInterface *interface)
|
IAssistProposal *KeywordsCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||||
{
|
{
|
||||||
QScopedPointer<const AssistInterface> assistInterface(interface);
|
QScopedPointer<const AssistInterface> assistInterface(interface);
|
||||||
if (isInComment(interface))
|
if (isInComment(interface))
|
||||||
@@ -257,11 +257,6 @@ void KeywordsCompletionAssistProvider::setDynamicCompletionFunction(
|
|||||||
m_completionFunc = func;
|
m_completionFunc = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProvider::RunType KeywordsCompletionAssistProvider::runType() const
|
|
||||||
{
|
|
||||||
return Synchronous;
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProcessor *KeywordsCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
IAssistProcessor *KeywordsCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
||||||
{
|
{
|
||||||
auto processor = new KeywordsCompletionAssistProcessor(m_keyWords);
|
auto processor = new KeywordsCompletionAssistProcessor(m_keyWords);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "iassistprocessor.h"
|
|
||||||
#include "assistproposalitem.h"
|
#include "assistproposalitem.h"
|
||||||
#include "ifunctionhintproposalmodel.h"
|
#include "asyncprocessor.h"
|
||||||
#include "completionassistprovider.h"
|
#include "completionassistprovider.h"
|
||||||
|
#include "ifunctionhintproposalmodel.h"
|
||||||
#include "../snippets/snippetassistcollector.h"
|
#include "../snippets/snippetassistcollector.h"
|
||||||
|
|
||||||
#include "texteditor/texteditorconstants.h"
|
#include "texteditor/texteditorconstants.h"
|
||||||
@@ -71,8 +71,6 @@ public:
|
|||||||
|
|
||||||
void setDynamicCompletionFunction(const DynamicCompletionFunction &func);
|
void setDynamicCompletionFunction(const DynamicCompletionFunction &func);
|
||||||
|
|
||||||
// IAssistProvider interface
|
|
||||||
RunType runType() const override;
|
|
||||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -81,13 +79,13 @@ private:
|
|||||||
DynamicCompletionFunction m_completionFunc;
|
DynamicCompletionFunction m_completionFunc;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public IAssistProcessor
|
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public AsyncProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeywordsCompletionAssistProcessor(const Keywords &keywords);
|
KeywordsCompletionAssistProcessor(const Keywords &keywords);
|
||||||
~KeywordsCompletionAssistProcessor() override = default;
|
~KeywordsCompletionAssistProcessor() override = default;
|
||||||
|
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *performAsync(AssistInterface *interface) override;
|
||||||
|
|
||||||
void setSnippetGroup(const QString &id);
|
void setSnippetGroup(const QString &id);
|
||||||
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "runner.h"
|
|
||||||
#include "iassistprocessor.h"
|
|
||||||
#include "iassistproposal.h"
|
|
||||||
#include "assistinterface.h"
|
|
||||||
#include "iassistproposalmodel.h"
|
|
||||||
|
|
||||||
using namespace TextEditor;
|
|
||||||
using namespace Internal;
|
|
||||||
|
|
||||||
ProcessorRunner::ProcessorRunner() = default;
|
|
||||||
|
|
||||||
ProcessorRunner::~ProcessorRunner()
|
|
||||||
{
|
|
||||||
delete m_processor;
|
|
||||||
if (m_discardProposal && m_proposal)
|
|
||||||
delete m_proposal;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessorRunner::setProcessor(IAssistProcessor *computer)
|
|
||||||
{
|
|
||||||
m_processor = computer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessorRunner::run()
|
|
||||||
{
|
|
||||||
m_interface->recreateTextDocument();
|
|
||||||
m_proposal = m_processor->perform(m_interface);
|
|
||||||
}
|
|
||||||
|
|
||||||
IAssistProposal *ProcessorRunner::proposal() const
|
|
||||||
{
|
|
||||||
return m_proposal;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessorRunner::setDiscardProposal(bool discard)
|
|
||||||
{
|
|
||||||
m_discardProposal = discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessorRunner::setAssistInterface(AssistInterface *interface)
|
|
||||||
{
|
|
||||||
m_interface = interface;
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "iassistproposalwidget.h"
|
|
||||||
|
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
namespace TextEditor {
|
|
||||||
|
|
||||||
class IAssistProcessor;
|
|
||||||
class IAssistProposal;
|
|
||||||
class AssistInterface;
|
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class ProcessorRunner : public QThread
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
ProcessorRunner();
|
|
||||||
~ProcessorRunner() override;
|
|
||||||
|
|
||||||
void setProcessor(IAssistProcessor *processor); // Takes ownership of the processor.
|
|
||||||
void setAssistInterface(AssistInterface *interface);
|
|
||||||
void setDiscardProposal(bool discard);
|
|
||||||
|
|
||||||
void run() override;
|
|
||||||
|
|
||||||
IAssistProposal *proposal() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
IAssistProcessor *m_processor = nullptr;
|
|
||||||
AssistInterface *m_interface = nullptr;
|
|
||||||
bool m_discardProposal = false;
|
|
||||||
IAssistProposal *m_proposal = nullptr;
|
|
||||||
AssistReason m_reason = IdleEditor;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Internal
|
|
||||||
} // TextEditor
|
|
||||||
@@ -156,6 +156,8 @@ Project {
|
|||||||
"assistproposalitem.cpp",
|
"assistproposalitem.cpp",
|
||||||
"assistproposalitem.h",
|
"assistproposalitem.h",
|
||||||
"assistproposaliteminterface.h",
|
"assistproposaliteminterface.h",
|
||||||
|
"asyncprocessor.cpp",
|
||||||
|
"asyncprocessor.h",
|
||||||
"codeassistant.cpp",
|
"codeassistant.cpp",
|
||||||
"codeassistant.h",
|
"codeassistant.h",
|
||||||
"completionassistprovider.cpp",
|
"completionassistprovider.cpp",
|
||||||
@@ -186,8 +188,6 @@ Project {
|
|||||||
"ifunctionhintproposalmodel.h",
|
"ifunctionhintproposalmodel.h",
|
||||||
"keywordscompletionassist.cpp",
|
"keywordscompletionassist.cpp",
|
||||||
"keywordscompletionassist.h",
|
"keywordscompletionassist.h",
|
||||||
"runner.cpp",
|
|
||||||
"runner.h",
|
|
||||||
"textdocumentmanipulator.cpp",
|
"textdocumentmanipulator.cpp",
|
||||||
"textdocumentmanipulator.h",
|
"textdocumentmanipulator.h",
|
||||||
"textdocumentmanipulatorinterface.h",
|
"textdocumentmanipulatorinterface.h",
|
||||||
|
|||||||
Reference in New Issue
Block a user