data: showing local symbols
- added local symbols to storage - added tests for local symbol parsing - added MessageActivateLocalSymbols to activate local symbols in code view - TokenLocations now store their LocationType instead of a plain bool "isScope" - moved LocationType from TokenLocation to separate file, since it is also used in Annotations now. - added local_symbol in stylesheet to define a style for hovering and activating these elements - renamed location to token in stylesheet
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <QToolTip>
|
||||
#include <qscrollbar.h>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenIds.h"
|
||||
#include "utility/messaging/type/MessageFocusIn.h"
|
||||
@@ -355,7 +356,7 @@ void QtCodeArea::paintEvent(QPaintEvent* event)
|
||||
painter.setPen(QPen(color.border.c_str()));
|
||||
painter.setBrush(QBrush(color.fill.c_str()));
|
||||
|
||||
if (annotation.isScope)
|
||||
if (annotation.locationType == LOCATION_SCOPE)
|
||||
{
|
||||
painter.drawRoundedRect(
|
||||
0, top + (annotation.startLine - m_startLineNumber) * blockHeight,
|
||||
@@ -425,42 +426,10 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
||||
else if (!m_fileWidget->getErrorMessages().size())
|
||||
{
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<const Annotation*> annotations = getAnnotationsForPosition(cursor.position());
|
||||
std::vector<const Annotation*> annotations = getNonScopeAnnotationsForPosition(cursor.position());
|
||||
|
||||
std::vector<Id> locationIds;
|
||||
std::set<Id> tokenIds;
|
||||
|
||||
bool allActive = true;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
if (!annotation->isActive)
|
||||
{
|
||||
allActive = false;
|
||||
}
|
||||
|
||||
if (annotation->locationId > 0)
|
||||
{
|
||||
locationIds.push_back(annotation->locationId);
|
||||
}
|
||||
if (annotation->tokenId > 0)
|
||||
{
|
||||
tokenIds.insert(annotation->tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
if (allActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (locationIds.size())
|
||||
{
|
||||
MessageActivateTokenLocations(locationIds).dispatch();
|
||||
}
|
||||
else if (tokenIds.size()) // fallback for links in project description
|
||||
{
|
||||
MessageActivateTokenIds(utility::toVector(tokenIds)).dispatch();
|
||||
}
|
||||
activateTokenLocations(annotations);
|
||||
activateLocalSymbols(annotations);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,7 +450,7 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
||||
|
||||
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
std::vector<const Annotation*> annotations = getAnnotationsForPosition(cursor.position());
|
||||
std::vector<const Annotation*> annotations = getNonScopeAnnotationsForPosition(cursor.position());
|
||||
|
||||
bool same = annotations.size() == m_hoveredAnnotations.size();
|
||||
if (same)
|
||||
@@ -558,13 +527,13 @@ void QtCodeArea::setIDECursorPosition()
|
||||
MessageMoveIDECursor(m_locationFile->getFilePath().str(), lineColumn.first, lineColumn.second).dispatch();
|
||||
}
|
||||
|
||||
std::vector<const QtCodeArea::Annotation*> QtCodeArea::getAnnotationsForPosition(int pos) const
|
||||
std::vector<const QtCodeArea::Annotation*> QtCodeArea::getNonScopeAnnotationsForPosition(int pos) const
|
||||
{
|
||||
std::vector<const QtCodeArea::Annotation*> annotations;
|
||||
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (!annotation.isScope && pos >= annotation.start && pos <= annotation.end)
|
||||
if (annotation.locationType != LOCATION_SCOPE && pos >= annotation.start && pos <= annotation.end)
|
||||
{
|
||||
annotations.push_back(&annotation);
|
||||
}
|
||||
@@ -573,6 +542,75 @@ std::vector<const QtCodeArea::Annotation*> QtCodeArea::getAnnotationsForPosition
|
||||
return annotations;
|
||||
}
|
||||
|
||||
void QtCodeArea::activateTokenLocations(const std::vector<const Annotation*>& annotations)
|
||||
{
|
||||
std::vector<Id> tokenLocationIds;
|
||||
std::set<Id> tokenIds;
|
||||
|
||||
bool allActive = true;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
if (annotation->locationType == LOCATION_TOKEN)
|
||||
{
|
||||
if (!annotation->isActive)
|
||||
{
|
||||
allActive = false;
|
||||
}
|
||||
|
||||
if (annotation->locationId > 0)
|
||||
{
|
||||
tokenLocationIds.push_back(annotation->locationId);
|
||||
}
|
||||
if (annotation->tokenId > 0)
|
||||
{
|
||||
tokenIds.insert(annotation->tokenId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allActive)
|
||||
{
|
||||
if (tokenLocationIds.size())
|
||||
{
|
||||
MessageActivateTokenLocations(tokenLocationIds).dispatch();
|
||||
}
|
||||
else if (tokenIds.size()) // fallback for links in project description
|
||||
{
|
||||
MessageActivateTokenIds(utility::toVector(tokenIds)).dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeArea::activateLocalSymbols(const std::vector<const Annotation*>& annotations)
|
||||
{
|
||||
std::vector<Id> localSymbolIds;
|
||||
|
||||
bool allActive = true;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
if (annotation->locationType == LOCATION_LOCAL_SYMBOL)
|
||||
{
|
||||
if (!annotation->isActive)
|
||||
{
|
||||
allActive = false;
|
||||
}
|
||||
|
||||
if (annotation->tokenId > 0)
|
||||
{
|
||||
localSymbolIds.push_back(annotation->tokenId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allActive)
|
||||
{
|
||||
if (localSymbolIds.size())
|
||||
{
|
||||
MessageActivateLocalSymbols(localSymbolIds).dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
{
|
||||
locationFile->forEachStartTokenLocation(
|
||||
@@ -624,7 +662,7 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
|
||||
annotation.tokenId = startLocation->getTokenId();
|
||||
annotation.locationId = startLocation->getId();
|
||||
|
||||
annotation.isScope = (startLocation->getType() == TokenLocation::LOCATION_SCOPE);
|
||||
annotation.locationType = startLocation->getType();
|
||||
annotation.isError = false;
|
||||
|
||||
annotation.isActive = false;
|
||||
@@ -637,7 +675,8 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
|
||||
|
||||
void QtCodeArea::annotateText()
|
||||
{
|
||||
const std::vector<Id>& activeIds = m_fileWidget->getActiveTokenIds();
|
||||
const std::vector<Id>& activeTokenIds = m_fileWidget->getActiveTokenIds();
|
||||
const std::vector<Id>& activeLocalSymbolIds = m_fileWidget->getActiveLocalSymbolIds();
|
||||
const std::vector<Id>& focusIds = m_fileWidget->getFocusedTokenIds();
|
||||
|
||||
bool isError = m_fileWidget->hasErrors();
|
||||
@@ -648,7 +687,10 @@ void QtCodeArea::annotateText()
|
||||
bool wasActive = annotation.isActive;
|
||||
bool wasFocused = annotation.isFocused;
|
||||
|
||||
annotation.isActive = std::find(activeIds.begin(), activeIds.end(), annotation.tokenId) != activeIds.end();
|
||||
annotation.isActive = (
|
||||
std::find(activeTokenIds.begin(), activeTokenIds.end(), annotation.tokenId) != activeTokenIds.end() ||
|
||||
std::find(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end(), annotation.tokenId) != activeLocalSymbolIds.end()
|
||||
);
|
||||
annotation.isFocused = std::find(focusIds.begin(), focusIds.end(), annotation.tokenId) != focusIds.end();
|
||||
|
||||
annotation.isError = isError;
|
||||
@@ -827,7 +869,8 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
|
||||
{
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
std::vector<std::string> types;
|
||||
types.push_back("location");
|
||||
types.push_back("token");
|
||||
types.push_back("local_symbol");
|
||||
types.push_back("scope");
|
||||
types.push_back("error");
|
||||
|
||||
@@ -850,14 +893,18 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
if (annotation.isScope)
|
||||
if (annotation.locationType == LOCATION_LOCAL_SYMBOL)
|
||||
{
|
||||
i = 3;
|
||||
}
|
||||
else if (annotation.isError)
|
||||
else if (annotation.locationType == LOCATION_SCOPE)
|
||||
{
|
||||
i = 6;
|
||||
}
|
||||
else if (annotation.isError)
|
||||
{
|
||||
i = 9;
|
||||
}
|
||||
|
||||
if (annotation.isActive)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class QDragMoveEvent;
|
||||
@@ -124,7 +125,7 @@ private:
|
||||
Id tokenId;
|
||||
Id locationId;
|
||||
|
||||
bool isScope;
|
||||
LocationType locationType;
|
||||
bool isError;
|
||||
|
||||
bool isActive;
|
||||
@@ -137,7 +138,9 @@ private:
|
||||
std::string fill;
|
||||
};
|
||||
|
||||
std::vector<const Annotation*> getAnnotationsForPosition(int pos) const;
|
||||
std::vector<const Annotation*> getNonScopeAnnotationsForPosition(int pos) const;
|
||||
void activateTokenLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateLocalSymbols(const std::vector<const Annotation*>& annotations);
|
||||
|
||||
void createAnnotations(std::shared_ptr<TokenLocationFile> locationFile);
|
||||
void annotateText();
|
||||
|
||||
@@ -129,6 +129,11 @@ const std::vector<Id>& QtCodeFile::getActiveTokenIds() const
|
||||
return m_parent->getActiveTokenIds();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFile::getActiveLocalSymbolIds() const
|
||||
{
|
||||
return m_parent->getActiveLocalSymbolIds();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFile::getFocusedTokenIds() const
|
||||
{
|
||||
return m_parent->getFocusedTokenIds();
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
std::string getFileName() const;
|
||||
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
const std::vector<Id>& getActiveLocalSymbolIds() const;
|
||||
const std::vector<Id>& getFocusedTokenIds() const;
|
||||
|
||||
const std::vector<std::string>& getErrorMessages() const;
|
||||
|
||||
@@ -85,6 +85,17 @@ const std::vector<Id>& QtCodeFileList::getActiveTokenIds() const
|
||||
void QtCodeFileList::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
m_activeLocalSymbolIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFileList::getActiveLocalSymbolIds() const
|
||||
{
|
||||
return m_activeLocalSymbolIds;
|
||||
}
|
||||
|
||||
void QtCodeFileList::setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
||||
{
|
||||
m_activeLocalSymbolIds = activeLocalSymbolIds;
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFileList::getFocusedTokenIds() const
|
||||
|
||||
@@ -39,6 +39,9 @@ public:
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
const std::vector<Id>& getActiveLocalSymbolIds() const;
|
||||
void setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
const std::vector<Id>& getFocusedTokenIds() const;
|
||||
void setFocusedTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
|
||||
@@ -77,6 +80,7 @@ private:
|
||||
std::vector<std::shared_ptr<QtCodeFile>> m_files;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<Id> m_activeLocalSymbolIds;
|
||||
std::vector<Id> m_focusedTokenIds;
|
||||
std::vector<std::string> m_errorMessages;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
, m_setFileStateFunctor(std::bind(&QtCodeView::doSetFileState, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_doShowActiveTokenIdsFunctor(std::bind(&QtCodeView::doShowActiveTokenIds, this, std::placeholders::_1))
|
||||
, m_doShowActiveLocalSymbolIdsFunctor(std::bind(&QtCodeView::doShowActiveLocalSymbolIds, this, std::placeholders::_1))
|
||||
, m_focusTokenIdsFunctor(std::bind(&QtCodeView::doFocusTokenIds, this, std::placeholders::_1))
|
||||
, m_defocusTokenIdsFunctor(std::bind(&QtCodeView::doDefocusTokenIds, this))
|
||||
, m_showContentsFunctor(std::bind(&QtCodeView::doShowContents, this))
|
||||
@@ -91,6 +92,11 @@ void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
m_doShowActiveTokenIdsFunctor(activeTokenIds);
|
||||
}
|
||||
|
||||
void QtCodeView::showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
||||
{
|
||||
m_doShowActiveLocalSymbolIdsFunctor(activeLocalSymbolIds);
|
||||
}
|
||||
|
||||
void QtCodeView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
|
||||
{
|
||||
m_focusTokenIdsFunctor(focusedTokenIds);
|
||||
@@ -194,6 +200,12 @@ void QtCodeView::doShowActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
m_widget->showActiveTokenIds();
|
||||
}
|
||||
|
||||
void QtCodeView::doShowActiveLocalSymbolIds(const std::vector<Id>& localSymbolIds)
|
||||
{
|
||||
m_widget->setActiveLocalSymbolIds(localSymbolIds);
|
||||
m_widget->showActiveTokenIds();
|
||||
}
|
||||
|
||||
void QtCodeView::doFocusTokenIds(const std::vector<Id>& focusedTokenIds)
|
||||
{
|
||||
m_widget->focusTokenIds(focusedTokenIds);
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
|
||||
virtual void showFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo);
|
||||
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
virtual void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
virtual void focusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
virtual void defocusTokenIds();
|
||||
@@ -59,6 +60,7 @@ private:
|
||||
|
||||
void doShowFirstActiveSnippet(const std::vector<Id>& activeTokenIds, bool scrollTo);
|
||||
void doShowActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
void doShowActiveLocalSymbolIds(const std::vector<Id>& localSymbolIds);
|
||||
|
||||
void doFocusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
void doDefocusTokenIds();
|
||||
@@ -77,6 +79,7 @@ private:
|
||||
QtThreadedFunctor<const FilePath, FileState> m_setFileStateFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, bool> m_doShowFirstActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveTokenIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveLocalSymbolIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_focusTokenIdsFunctor;
|
||||
QtThreadedFunctor<> m_defocusTokenIdsFunctor;
|
||||
QtThreadedFunctor<> m_showContentsFunctor;
|
||||
|
||||
Reference in New Issue
Block a user