forked from qt-creator/qt-creator
CodeAssist: Store processor state in specialized objects
Change-Id: I19de64b948599c833496ab8caabf3eaafc845658 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -128,8 +128,8 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface *
|
|||||||
m_interface.reset(static_cast<const ClangCompletionAssistInterface *>(interface));
|
m_interface.reset(static_cast<const ClangCompletionAssistInterface *>(interface));
|
||||||
|
|
||||||
if (interface->reason() != ExplicitlyInvoked && !accepts()) {
|
if (interface->reason() != ExplicitlyInvoked && !accepts()) {
|
||||||
setPerformWasApplicable(false);
|
m_requestSent = false;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return startCompletionHelper(); // == 0 if results are calculated asynchronously
|
return startCompletionHelper(); // == 0 if results are calculated asynchronously
|
||||||
@@ -246,16 +246,14 @@ IAssistProposal *ClangCompletionAssistProcessor::startCompletionHelper()
|
|||||||
case ClangCompletionContextAnalyzer::PassThroughToLibClang: {
|
case ClangCompletionContextAnalyzer::PassThroughToLibClang: {
|
||||||
m_addSnippets = m_completionOperator == T_EOF_SYMBOL;
|
m_addSnippets = m_completionOperator == T_EOF_SYMBOL;
|
||||||
m_sentRequestType = NormalCompletion;
|
m_sentRequestType = NormalCompletion;
|
||||||
const bool requestSent = sendCompletionRequest(analyzer.positionForClang(),
|
m_requestSent = sendCompletionRequest(analyzer.positionForClang(),
|
||||||
modifiedFileContent);
|
modifiedFileContent);
|
||||||
setPerformWasApplicable(requestSent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ClangCompletionContextAnalyzer::PassThroughToLibClangAfterLeftParen: {
|
case ClangCompletionContextAnalyzer::PassThroughToLibClangAfterLeftParen: {
|
||||||
m_sentRequestType = FunctionHintCompletion;
|
m_sentRequestType = FunctionHintCompletion;
|
||||||
const bool requestSent = sendCompletionRequest(analyzer.positionForClang(), QByteArray(),
|
m_requestSent = sendCompletionRequest(analyzer.positionForClang(), QByteArray(),
|
||||||
analyzer.functionNameStart());
|
analyzer.functionNameStart());
|
||||||
setPerformWasApplicable(requestSent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -590,16 +588,18 @@ bool ClangCompletionAssistProcessor::sendCompletionRequest(int position,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal(
|
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal(
|
||||||
CompletionCorrection neededCorrection) const
|
CompletionCorrection neededCorrection)
|
||||||
{
|
{
|
||||||
|
m_requestSent = false;
|
||||||
TextEditor::GenericProposalModelPtr model(new ClangAssistProposalModel(neededCorrection));
|
TextEditor::GenericProposalModelPtr model(new ClangAssistProposalModel(neededCorrection));
|
||||||
model->loadContent(m_completions);
|
model->loadContent(m_completions);
|
||||||
return new ClangAssistProposal(m_positionForProposal, model);
|
return new ClangAssistProposal(m_positionForProposal, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
IAssistProposal *ClangCompletionAssistProcessor::createFunctionHintProposal(
|
IAssistProposal *ClangCompletionAssistProcessor::createFunctionHintProposal(
|
||||||
const ClangBackEnd::CodeCompletions &completions) const
|
const ClangBackEnd::CodeCompletions &completions)
|
||||||
{
|
{
|
||||||
|
m_requestSent = false;
|
||||||
TextEditor::FunctionHintProposalModelPtr model(new ClangFunctionHintModel(completions));
|
TextEditor::FunctionHintProposalModelPtr model(new ClangFunctionHintModel(completions));
|
||||||
return new FunctionHintProposal(m_positionForProposal, model);
|
return new FunctionHintProposal(m_positionForProposal, model);
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
void handleAvailableCompletions(const CodeCompletions &completions,
|
void handleAvailableCompletions(const CodeCompletions &completions,
|
||||||
CompletionCorrection neededCorrection);
|
CompletionCorrection neededCorrection);
|
||||||
|
bool running() final { return m_requestSent; }
|
||||||
|
|
||||||
const TextEditor::TextEditorWidget *textEditorWidget() const;
|
const TextEditor::TextEditorWidget *textEditorWidget() const;
|
||||||
|
|
||||||
@@ -62,9 +63,9 @@ private:
|
|||||||
bool accepts() const;
|
bool accepts() const;
|
||||||
|
|
||||||
TextEditor::IAssistProposal *createProposal(
|
TextEditor::IAssistProposal *createProposal(
|
||||||
CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection) const;
|
CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection);
|
||||||
TextEditor::IAssistProposal *createFunctionHintProposal(
|
TextEditor::IAssistProposal *createFunctionHintProposal(
|
||||||
const CodeCompletions &completions) const;
|
const CodeCompletions &completions);
|
||||||
|
|
||||||
bool completeInclude(const QTextCursor &cursor);
|
bool completeInclude(const QTextCursor &cursor);
|
||||||
bool completeInclude(int position);
|
bool completeInclude(int position);
|
||||||
@@ -93,6 +94,7 @@ private:
|
|||||||
QScopedPointer<const ClangCompletionAssistInterface> m_interface;
|
QScopedPointer<const ClangCompletionAssistInterface> m_interface;
|
||||||
unsigned m_completionOperator;
|
unsigned m_completionOperator;
|
||||||
enum CompletionRequestType { NormalCompletion, FunctionHintCompletion } m_sentRequestType;
|
enum CompletionRequestType { NormalCompletion, FunctionHintCompletion } m_sentRequestType;
|
||||||
|
bool m_requestSent = false;
|
||||||
bool m_addSnippets = false; // For type == Type::NormalCompletion
|
bool m_addSnippets = false; // For type == Type::NormalCompletion
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -255,7 +255,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
|
|||||||
if (IAssistProposal *newProposal = processor->perform(assistInterface)) {
|
if (IAssistProposal *newProposal = processor->perform(assistInterface)) {
|
||||||
displayProposal(newProposal, reason);
|
displayProposal(newProposal, reason);
|
||||||
delete processor;
|
delete processor;
|
||||||
} else if (!processor->performWasApplicable()) {
|
} else if (!processor->running()) {
|
||||||
delete processor;
|
delete processor;
|
||||||
} else { // ...async request was triggered
|
} else { // ...async request was triggered
|
||||||
m_asyncProcessor = processor;
|
m_asyncProcessor = processor;
|
||||||
|
@@ -48,10 +48,12 @@ public:
|
|||||||
DocumentContentCompletionProcessor(const QString &snippetGroupId);
|
DocumentContentCompletionProcessor(const QString &snippetGroupId);
|
||||||
|
|
||||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||||
|
bool running() final { return m_running; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::SnippetAssistCollector m_snippetCollector;
|
TextEditor::SnippetAssistCollector m_snippetCollector;
|
||||||
IAssistProposal *createProposal(const AssistInterface *interface);
|
IAssistProposal *createProposal(const AssistInterface *interface);
|
||||||
|
bool m_running = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup)
|
DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup)
|
||||||
@@ -77,9 +79,10 @@ IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterfa
|
|||||||
Utils::onResultReady(Utils::runAsync(
|
Utils::onResultReady(Utils::runAsync(
|
||||||
&DocumentContentCompletionProcessor::createProposal, this, interface),
|
&DocumentContentCompletionProcessor::createProposal, this, interface),
|
||||||
[this](IAssistProposal *proposal){
|
[this](IAssistProposal *proposal){
|
||||||
|
m_running = false;
|
||||||
setAsyncProposalAvailable(proposal);
|
setAsyncProposalAvailable(proposal);
|
||||||
});
|
});
|
||||||
setPerformWasApplicable(true);
|
m_running = true;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -49,12 +49,10 @@ public:
|
|||||||
using AsyncCompletionsAvailableHandler = std::function<void (IAssistProposal *proposal)>;
|
using AsyncCompletionsAvailableHandler = std::function<void (IAssistProposal *proposal)>;
|
||||||
void setAsyncCompletionAvailableHandler(const AsyncCompletionsAvailableHandler &finalizer);
|
void setAsyncCompletionAvailableHandler(const AsyncCompletionsAvailableHandler &finalizer);
|
||||||
|
|
||||||
bool performWasApplicable() { return m_performWasApplicable; }
|
virtual bool running() { return false; }
|
||||||
void setPerformWasApplicable(bool applicable) { m_performWasApplicable = applicable; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncCompletionsAvailableHandler m_asyncCompletionsAvailableHandler;
|
AsyncCompletionsAvailableHandler m_asyncCompletionsAvailableHandler;
|
||||||
bool m_performWasApplicable = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // TextEditor
|
} // TextEditor
|
||||||
|
Reference in New Issue
Block a user