ui: improved code snippet location clicks
* activate token of most nested location * show parts of locations with start or end outside of snippet * (fix for multiple parsing of function and method bodies)
This commit is contained in:
@@ -26,31 +26,34 @@ void CodeController::setActiveTokenId(Id id)
|
||||
getView()->clearCodeSnippets();
|
||||
|
||||
TokenLocationCollection collection = m_locationAccess->getTokenLocationsForTokenId(id);
|
||||
collection.forEachTokenLocation([&] (TokenLocation* tokenLocation) -> void {
|
||||
if (tokenLocation->isStartTokenLocation())
|
||||
collection.forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
const std::string filePath = tokenLocation->getFilePath();
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
|
||||
|
||||
unsigned int firstLineNumber = std::max<int>(1, tokenLocation->getLineNumber() - lineRadius);
|
||||
unsigned int lastLineNumber = std::min<int>(
|
||||
textAccess->getLineCount(), tokenLocation->getEndTokenLocation()->getLineNumber() + lineRadius
|
||||
);
|
||||
|
||||
for (std::string line: textAccess->getLines(firstLineNumber, lastLineNumber))
|
||||
if (tokenLocation->isStartTokenLocation())
|
||||
{
|
||||
params.code += line;
|
||||
const std::string filePath = tokenLocation->getFilePath();
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
|
||||
|
||||
unsigned int firstLineNumber = std::max<int>(1, tokenLocation->getLineNumber() - lineRadius);
|
||||
unsigned int lastLineNumber = std::min<int>(
|
||||
textAccess->getLineCount(), tokenLocation->getEndTokenLocation()->getLineNumber() + lineRadius
|
||||
);
|
||||
|
||||
CodeView::CodeSnippetParams params;
|
||||
for (const std::string& line: textAccess->getLines(firstLineNumber, lastLineNumber))
|
||||
{
|
||||
params.code += line;
|
||||
}
|
||||
|
||||
params.startLineNumber = firstLineNumber;
|
||||
params.locationFile =
|
||||
m_locationAccess->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
params.activeTokenId = id;
|
||||
|
||||
getView()->addCodeSnippet(params);
|
||||
}
|
||||
|
||||
params.startLineNumber = firstLineNumber;
|
||||
params.locationFile =
|
||||
m_locationAccess->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
params.activeTokenId = id;
|
||||
|
||||
getView()->addCodeSnippet(params);
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
void CodeController::handleMessage(MessageActivateToken* message)
|
||||
|
||||
+16
-17
@@ -263,26 +263,25 @@ TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
TokenLocationFile ret(fileName);
|
||||
|
||||
TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(fileName);
|
||||
if (locationFile)
|
||||
if (!locationFile)
|
||||
{
|
||||
for (unsigned int i = firstLineNumber; i <= lastLineNumber; i++)
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (unsigned int i = firstLineNumber; i <= lastLineNumber; i++)
|
||||
{
|
||||
TokenLocationLine* locationLine = locationFile->findTokenLocationLineByNumber(i);
|
||||
if (!locationLine)
|
||||
{
|
||||
TokenLocationLine* locationLine = locationFile->findTokenLocationLineByNumber(i);
|
||||
if (locationLine)
|
||||
{
|
||||
locationLine->forEachTokenLocation([&] (TokenLocation* tokenLocation) -> void {
|
||||
if (tokenLocation->getOtherTokenLocation() &&
|
||||
tokenLocation->isStartTokenLocation() &&
|
||||
tokenLocation->getLineNumber() >= firstLineNumber &&
|
||||
tokenLocation->getOtherTokenLocation()->isEndTokenLocation() &&
|
||||
tokenLocation->getOtherTokenLocation()->getLineNumber() <= lastLineNumber)
|
||||
{
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation);
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation->getOtherTokenLocation());
|
||||
}
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
locationLine->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
ret.addTokenLocationAsPlainCopy(tokenLocation);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -141,7 +141,7 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration)
|
||||
getParameters(declaration)
|
||||
);
|
||||
|
||||
if (declaration->hasBody())
|
||||
if (declaration->hasBody() && declaration->isThisDeclarationADefinition())
|
||||
{
|
||||
ASTBodyVisitor bodyVisitor(this, declaration);
|
||||
bodyVisitor.Visit(declaration->getBody());
|
||||
@@ -176,7 +176,7 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
|
||||
declaration->isStatic()
|
||||
);
|
||||
|
||||
if (declaration->hasBody())
|
||||
if (declaration->hasBody() && declaration->isThisDeclarationADefinition())
|
||||
{
|
||||
ASTBodyVisitor bodyVisitor(this, declaration);
|
||||
bodyVisitor.Visit(declaration->getBody());
|
||||
|
||||
Reference in New Issue
Block a user