diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index 350ce9d5ab2..4cae74725cc 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -128,8 +128,8 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface * m_interface.reset(static_cast(interface)); if (interface->reason() != ExplicitlyInvoked && !accepts()) { - setPerformWasApplicable(false); - return 0; + m_requestSent = false; + return nullptr; } return startCompletionHelper(); // == 0 if results are calculated asynchronously @@ -246,16 +246,14 @@ IAssistProposal *ClangCompletionAssistProcessor::startCompletionHelper() case ClangCompletionContextAnalyzer::PassThroughToLibClang: { m_addSnippets = m_completionOperator == T_EOF_SYMBOL; m_sentRequestType = NormalCompletion; - const bool requestSent = sendCompletionRequest(analyzer.positionForClang(), - modifiedFileContent); - setPerformWasApplicable(requestSent); + m_requestSent = sendCompletionRequest(analyzer.positionForClang(), + modifiedFileContent); break; } case ClangCompletionContextAnalyzer::PassThroughToLibClangAfterLeftParen: { m_sentRequestType = FunctionHintCompletion; - const bool requestSent = sendCompletionRequest(analyzer.positionForClang(), QByteArray(), - analyzer.functionNameStart()); - setPerformWasApplicable(requestSent); + m_requestSent = sendCompletionRequest(analyzer.positionForClang(), QByteArray(), + analyzer.functionNameStart()); break; } default: @@ -590,16 +588,18 @@ bool ClangCompletionAssistProcessor::sendCompletionRequest(int position, } TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal( - CompletionCorrection neededCorrection) const + CompletionCorrection neededCorrection) { + m_requestSent = false; TextEditor::GenericProposalModelPtr model(new ClangAssistProposalModel(neededCorrection)); model->loadContent(m_completions); return new ClangAssistProposal(m_positionForProposal, model); } IAssistProposal *ClangCompletionAssistProcessor::createFunctionHintProposal( - const ClangBackEnd::CodeCompletions &completions) const + const ClangBackEnd::CodeCompletions &completions) { + m_requestSent = false; TextEditor::FunctionHintProposalModelPtr model(new ClangFunctionHintModel(completions)); return new FunctionHintProposal(m_positionForProposal, model); } diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.h b/src/plugins/clangcodemodel/clangcompletionassistprocessor.h index 3e20caa37b8..d406422aa32 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.h +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.h @@ -52,6 +52,7 @@ public: void handleAvailableCompletions(const CodeCompletions &completions, CompletionCorrection neededCorrection); + bool running() final { return m_requestSent; } const TextEditor::TextEditorWidget *textEditorWidget() const; @@ -62,9 +63,9 @@ private: bool accepts() const; TextEditor::IAssistProposal *createProposal( - CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection) const; + CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection); TextEditor::IAssistProposal *createFunctionHintProposal( - const CodeCompletions &completions) const; + const CodeCompletions &completions); bool completeInclude(const QTextCursor &cursor); bool completeInclude(int position); @@ -93,6 +94,7 @@ private: QScopedPointer m_interface; unsigned m_completionOperator; enum CompletionRequestType { NormalCompletion, FunctionHintCompletion } m_sentRequestType; + bool m_requestSent = false; bool m_addSnippets = false; // For type == Type::NormalCompletion }; diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index 3ba37005582..4a5a23bf4d7 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -255,7 +255,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason, if (IAssistProposal *newProposal = processor->perform(assistInterface)) { displayProposal(newProposal, reason); delete processor; - } else if (!processor->performWasApplicable()) { + } else if (!processor->running()) { delete processor; } else { // ...async request was triggered m_asyncProcessor = processor; diff --git a/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp b/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp index fb0e35acfb9..cdb69be9b93 100644 --- a/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp +++ b/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp @@ -48,10 +48,12 @@ public: DocumentContentCompletionProcessor(const QString &snippetGroupId); IAssistProposal *perform(const AssistInterface *interface) override; + bool running() final { return m_running; } private: TextEditor::SnippetAssistCollector m_snippetCollector; IAssistProposal *createProposal(const AssistInterface *interface); + bool m_running = false; }; DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup) @@ -77,9 +79,10 @@ IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterfa Utils::onResultReady(Utils::runAsync( &DocumentContentCompletionProcessor::createProposal, this, interface), [this](IAssistProposal *proposal){ + m_running = false; setAsyncProposalAvailable(proposal); }); - setPerformWasApplicable(true); + m_running = true; return nullptr; } diff --git a/src/plugins/texteditor/codeassist/iassistprocessor.h b/src/plugins/texteditor/codeassist/iassistprocessor.h index a05c0bf8261..31b8998778d 100644 --- a/src/plugins/texteditor/codeassist/iassistprocessor.h +++ b/src/plugins/texteditor/codeassist/iassistprocessor.h @@ -49,12 +49,10 @@ public: using AsyncCompletionsAvailableHandler = std::function; void setAsyncCompletionAvailableHandler(const AsyncCompletionsAvailableHandler &finalizer); - bool performWasApplicable() { return m_performWasApplicable; } - void setPerformWasApplicable(bool applicable) { m_performWasApplicable = applicable; } + virtual bool running() { return false; } private: AsyncCompletionsAvailableHandler m_asyncCompletionsAvailableHandler; - bool m_performWasApplicable = true; }; } // TextEditor