forked from qt-creator/qt-creator
CppEditor: Fix looking up containing function for search result
- Move look-up to CplusPlus::FindUsages, where we are guaranteed that
we actually have the document source.
- Use the same straightforward algorithm as with clangd.
- Undo the changes to CppDocument::functionAt(), which broke
the autotest.
Amends 6f7e7980d2.
Change-Id: I008d05ba41a3b63b71e3131d7021e0d4e7d0641f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -142,11 +142,30 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand
|
||||
const int len = tk.utf16chars();
|
||||
|
||||
const Usage u(Utils::FilePath::fromString(_doc->fileName()), lineText,
|
||||
getType(line, col, tokenIndex), line, col - 1, len);
|
||||
getContainingFunction(line, col), getType(line, col, tokenIndex),
|
||||
line, col - 1, len);
|
||||
_usages.append(u);
|
||||
_references.append(tokenIndex);
|
||||
}
|
||||
|
||||
QString FindUsages::getContainingFunction(int line, int column)
|
||||
{
|
||||
const QList<AST *> astPath = ASTPath(_doc)(line, column);
|
||||
bool hasBlock = false;
|
||||
for (auto it = astPath.crbegin(); it != astPath.crend(); ++it) {
|
||||
if (!hasBlock && (*it)->asCompoundStatement())
|
||||
hasBlock = true;
|
||||
if (const auto func = (*it)->asFunctionDefinition()) {
|
||||
if (!hasBlock)
|
||||
return {};
|
||||
if (!func->symbol)
|
||||
return {};
|
||||
return Overview().prettyName(func->symbol->name());
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
class FindUsages::GetUsageType
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user