diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-10-17 14:16:32 +0200 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-10-25 07:10:12 +0000 |
commit | 039a34a369d96384cf72ae6979bff6f6fb36a0e7 (patch) | |
tree | 464c9eb49795c62beb4c8e2794a8ae4ca66eb6b3 /src/tools | |
parent | b00017e0ad1e27e79d79e476ee82d6bc3204bc6b (diff) | |
download | qt-creator-039a34a369d96384cf72ae6979bff6f6fb36a0e7.tar.gz |
Clang: Adapt priorities for the same method/constructor overloads
CXXMethod and CXXConstructor may have different priorities
depending ony their origin and attributes. To keep them together
in the sorted list we adapt their priorities to have the same
value if their names match.
To continue keeping ClassCompletion before ConstructorCompletion
change the order of the completion kinds for the sort purposes.
Change-Id: I36efe5d5dbaa77d604a54b1dafe07d67f44db4c9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/clangbackend/source/codecompletionsextractor.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/tools/clangbackend/source/codecompletionsextractor.cpp b/src/tools/clangbackend/source/codecompletionsextractor.cpp index 2e2817c72b..f9c019b66d 100644 --- a/src/tools/clangbackend/source/codecompletionsextractor.cpp +++ b/src/tools/clangbackend/source/codecompletionsextractor.cpp @@ -110,24 +110,30 @@ static CodeCompletions filterFunctionOverloads(const CodeCompletions &completion }); } -static ::Utils::optional<bool> classBeforeCXXConstructor(const CodeCompletion &first, - const CodeCompletion &second) +static void adaptOverloadsPriorities(CodeCompletions &codeCompletions) { - // Put ClassCompletionKind elements before ConstructorCompletionKind elements - // when they have the same name. - if (first.completionKind == CodeCompletion::ClassCompletionKind - && second.completionKind == CodeCompletion::ConstructorCompletionKind - && first.text == second.text) { - return true; - } + std::map<Utf8String, std::vector<CodeCompletion *>> cachedOverloads; + for (CodeCompletion ¤tCompletion : codeCompletions) { + if (currentCompletion.completionKind != CodeCompletion::ConstructorCompletionKind + && currentCompletion.completionKind != CodeCompletion::FunctionCompletionKind) { + continue; + } - if (first.completionKind == CodeCompletion::ConstructorCompletionKind - && second.completionKind == CodeCompletion::ClassCompletionKind - && first.text == second.text) { - return false; + auto found = cachedOverloads.find(currentCompletion.text); + if (found == cachedOverloads.end()) { + cachedOverloads[currentCompletion.text].push_back(¤tCompletion); + } else { + const quint32 oldPriority = found->second.front()->priority; + if (currentCompletion.priority >= oldPriority) { + currentCompletion.priority = oldPriority; + } else { + const quint32 newPriority = currentCompletion.priority; + for (CodeCompletion *completion : found->second) + completion->priority = newPriority; + } + found->second.push_back(¤tCompletion); + } } - - return ::Utils::optional<bool>(); } static void sortCodeCompletions(CodeCompletions &codeCompletions) @@ -138,14 +144,8 @@ static void sortCodeCompletions(CodeCompletions &codeCompletions) if (first.requiredFixIts.empty() != second.requiredFixIts.empty()) return first.requiredFixIts.empty() > second.requiredFixIts.empty(); - const ::Utils::optional<bool> classBeforeConstructorWithTheSameName - = classBeforeCXXConstructor(first, second); - if (classBeforeConstructorWithTheSameName) - return classBeforeConstructorWithTheSameName.value(); - - return (first.priority > 0 - && (first.priority < second.priority - || (first.priority == second.priority && first.text < second.text))); + return std::tie(first.priority, first.text, first.completionKind) + < std::tie(second.priority, second.text, second.completionKind); }; // Keep the order for the items with the same priority and name. @@ -164,6 +164,7 @@ void CodeCompletionsExtractor::handleCompletions(CodeCompletions &codeCompletion codeCompletions = overloadCompletions; } + adaptOverloadsPriorities(codeCompletions); sortCodeCompletions(codeCompletions); } |