Merge remote-tracking branch 'origin/4.8'

Conflicts:
	src/plugins/winrt/winrtdevicefactory.cpp

Change-Id: I33b8697e2ebf2bea051d7f1144449e0743ee16a5
This commit is contained in:
Eike Ziller
2018-11-19 09:48:28 +01:00
110 changed files with 2004 additions and 809 deletions

View File

@@ -140,6 +140,17 @@ static QString methodDefinitionParameters(const CodeCompletionChunks &chunks)
return result;
}
static bool skipParenForFunctionLikeSnippet(const std::vector<int> &placeholderPositions,
const QString &text,
int position)
{
return placeholderPositions.size() == 1
&& position > 0
&& text[position - 1] == '('
&& text[position] == ')'
&& position + 1 == text.size();
}
void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulator,
int basePosition) const
{
@@ -167,12 +178,20 @@ void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulato
} else if (ccr.completionKind == CodeCompletion::KeywordCompletionKind) {
CompletionChunksToTextConverter converter;
converter.setupForKeywords();
converter.parseChunks(ccr.chunks);
textToBeInserted = converter.text();
if (converter.hasPlaceholderPositions())
cursorOffset = converter.placeholderPositions().at(0) - converter.text().size();
if (converter.hasPlaceholderPositions()) {
const std::vector<int> &placeholderPositions = converter.placeholderPositions();
const int position = placeholderPositions[0];
cursorOffset = position - converter.text().size();
// If the snippet looks like a function call, e.g. "sizeof(<PLACEHOLDER>)",
// ensure that we can "overtype" ')' after inserting it.
setAutoCompleteSkipPos = skipParenForFunctionLikeSnippet(placeholderPositions,
textToBeInserted,
position);
}
} else if (ccr.completionKind == CodeCompletion::NamespaceCompletionKind) {
CompletionChunksToTextConverter converter;
converter.parseChunks(ccr.chunks); // Appends "::" after name space name

View File

@@ -29,6 +29,7 @@
#include "clangassistproposalmodel.h"
#include "clangcompletionassistprocessor.h"
#include "clangcompletioncontextanalyzer.h"
#include "clangfixitoperation.h"
#include "clangfunctionhintmodel.h"
#include "clangcompletionchunkstotextconverter.h"
#include "clangpreprocessorassistproposalitem.h"
@@ -178,6 +179,35 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface *
return startCompletionHelper(); // == 0 if results are calculated asynchronously
}
// All completions require fix-it, apply this fix-it now.
CodeCompletions ClangCompletionAssistProcessor::applyCompletionFixIt(const CodeCompletions &completions)
{
// CLANG-UPGRADE-CHECK: Currently we rely on fact that there are only 2 possible fix-it types:
// 'dot to arrow' and 'arrow to dot' and they can't appear for the same item.
// However if we get multiple options which trigger for the same code we need to improve this
// algorithm. Check comments to FixIts field of CodeCompletionResult and which fix-its are used
// to construct results in SemaCodeComplete.cpp.
const CodeCompletion &completion = completions.front();
const ClangBackEnd::FixItContainer &fixIt = completion.requiredFixIts.front();
ClangFixItOperation fixItOperation(Utf8String(), completion.requiredFixIts);
fixItOperation.perform();
const int fixItLength = static_cast<int>(fixIt.range.end.column - fixIt.range.start.column);
const QString fixItText = fixIt.text.toString();
m_positionForProposal += fixItText.length() - fixItLength;
CodeCompletions completionsWithoutFixIts;
completionsWithoutFixIts.reserve(completions.size());
for (const CodeCompletion &completion : completions) {
CodeCompletion completionCopy = completion;
completionCopy.requiredFixIts.clear();
completionsWithoutFixIts.push_back(completionCopy);
}
return completionsWithoutFixIts;
}
void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeCompletions &completions)
{
QTC_CHECK(m_completions.isEmpty());
@@ -194,7 +224,13 @@ void ClangCompletionAssistProcessor::handleAvailableCompletions(const CodeComple
}
//m_sentRequestType == NormalCompletion or function signatures were empty
m_completions = toAssistProposalItems(completions, m_interface.data());
// Completions are sorted the way that all items with fix-its come after all items without them
// therefore it's enough to check only the first one.
if (!completions.isEmpty() && !completions.front().requiredFixIts.isEmpty())
m_completions = toAssistProposalItems(applyCompletionFixIt(completions), m_interface.data());
else
m_completions = toAssistProposalItems(completions, m_interface.data());
if (m_addSnippets && !m_completions.isEmpty())
addSnippets();

View File

@@ -85,6 +85,8 @@ private:
const QByteArray &customFileContent,
int functionNameStartPosition = -1);
CodeCompletions applyCompletionFixIt(const CodeCompletions &completions);
private:
struct Position { int line; int column; };
Position extractLineColumn(int position);

View File

@@ -57,7 +57,7 @@ public:
private:
void applyFixitsToFile(TextEditor::RefactoringFile &refactoringFile,
const QVector<ClangBackEnd::FixItContainer> fixItContainers);
Utils::ChangeSet toChangeSet(
::Utils::ChangeSet toChangeSet(
TextEditor::RefactoringFile &refactoringFile,
const QVector<ClangBackEnd::FixItContainer> fixItContainers) const;