Clang: Correct member access operator if possible

1 struct Foo { int member; };
 2 void f(Foo *foo)
 3 {
 4     foo.<REQUEST COMPLETION> // correct '.' to '->' and provide results
 5 }

The preferred approach would be to check if "foo" in line 4 is of
pointer type, but there is no suitable cursor (only CompoundStmt) at
that position since the code is usually not yet parsed and thus invalid.

Thus, just run the completion as is. If there are not any results for a
dot completion, re-run the completion with "." exchanged by "->". This
approach is inherently slower than the preferred approach implemented in
the built-in code model.

The following rare cases are not handled:

 1) Requesting completion after white space:
      Works: foo.<COMPLETE HERE>
      Fails: foo. <COMPLETE HERE>

 2) Opening a file and requesting completion (ctrl+space) without prior
    editing. No editing before triggering completion means that no
    unsaved file is generated on the backend side, which is a
    requirement for the correction.

Task-number: QTCREATORBUG-11581
Change-Id: I6bc8e8594778774ab342755fdb01a8a3e5c52ba0
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2016-01-11 15:20:04 +01:00
parent 43800a6aa8
commit 8d6549fa74
40 changed files with 747 additions and 37 deletions

View File

@@ -240,13 +240,14 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface *
}
bool ClangCompletionAssistProcessor::handleAvailableAsyncCompletions(
const CodeCompletions &completions)
const CodeCompletions &completions,
CompletionCorrection neededCorrection)
{
bool handled = true;
switch (m_sentRequestType) {
case CompletionRequestType::NormalCompletion:
handleAvailableCompletions(completions);
handleAvailableCompletions(completions, neededCorrection);
break;
case CompletionRequestType::FunctionHintCompletion:
handled = handleAvailableFunctionHintCompletions(completions);
@@ -775,14 +776,17 @@ bool ClangCompletionAssistProcessor::sendCompletionRequest(int position,
return false;
}
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal() const
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal(
CompletionCorrection neededCorrection) const
{
ClangAssistProposalModel *model = new ClangAssistProposalModel;
ClangAssistProposalModel *model = new ClangAssistProposalModel(neededCorrection);
model->loadContent(m_completions);
return new ClangAssistProposal(m_positionForProposal, model);
}
void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeCompletions &completions)
void ClangCompletionAssistProcessor::handleAvailableCompletions(
const CodeCompletions &completions,
CompletionCorrection neededCorrection)
{
QTC_CHECK(m_completions.isEmpty());
@@ -790,7 +794,7 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeComple
if (m_addSnippets)
addSnippets();
setAsyncProposalAvailable(createProposal());
setAsyncProposalAvailable(createProposal(neededCorrection));
}
bool ClangCompletionAssistProcessor::handleAvailableFunctionHintCompletions(