ui: Show list in tooltip when clicking source location with multiple tokens or local symbols
* Also shows list of all implicit symbols at a source location e.g. default constructors or template specializations
This commit is contained in:
@@ -32,6 +32,11 @@ void TooltipController::handleMessage(MessageActivateTokens* message)
|
||||
clear();
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageActivateLocalSymbols* message)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageFocusIn* message)
|
||||
{
|
||||
if (!message->tokenIds.size())
|
||||
@@ -52,6 +57,16 @@ void TooltipController::handleMessage(MessageGraphNodeExpand* message)
|
||||
clear();
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageScrollCode* message)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageScrollGraph* message)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageTooltipHide* message)
|
||||
{
|
||||
clear();
|
||||
@@ -59,7 +74,23 @@ void TooltipController::handleMessage(MessageTooltipHide* message)
|
||||
|
||||
void TooltipController::handleMessage(MessageTooltipShow* message)
|
||||
{
|
||||
requestTooltipShow(std::vector<Id>(), message->tooltipInfo, message->origin);
|
||||
if (message->tooltipInfo.title.size())
|
||||
{
|
||||
requestTooltipShow(std::vector<Id>(), message->tooltipInfo, message->origin);
|
||||
}
|
||||
else
|
||||
{
|
||||
TooltipInfo info = m_storageAccess->getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
message->sourceLocationIds, message->localSymbolIds);
|
||||
|
||||
if (info.snippets.size())
|
||||
{
|
||||
getView()->showTooltip(info, getViewForOrigin(message->origin));
|
||||
|
||||
m_showRequest.reset();
|
||||
m_hideRequest = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TooltipController::handleMessage(MessageWindowFocus* message)
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
#include "component/controller/Controller.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
#include "utility/messaging/type/MessageFocusIn.h"
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeExpand.h"
|
||||
#include "utility/messaging/type/MessageScrollCode.h"
|
||||
#include "utility/messaging/type/MessageScrollGraph.h"
|
||||
#include "utility/messaging/type/MessageTooltipHide.h"
|
||||
#include "utility/messaging/type/MessageTooltipShow.h"
|
||||
#include "utility/messaging/type/MessageWindowFocus.h"
|
||||
@@ -17,9 +20,12 @@ class TooltipView;
|
||||
class TooltipController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateTokens>
|
||||
, public MessageListener<MessageActivateLocalSymbols>
|
||||
, public MessageListener<MessageFocusIn>
|
||||
, public MessageListener<MessageFocusOut>
|
||||
, public MessageListener<MessageGraphNodeExpand>
|
||||
, public MessageListener<MessageScrollCode>
|
||||
, public MessageListener<MessageScrollGraph>
|
||||
, public MessageListener<MessageTooltipHide>
|
||||
, public MessageListener<MessageTooltipShow>
|
||||
, public MessageListener<MessageWindowFocus>
|
||||
@@ -33,9 +39,12 @@ public:
|
||||
|
||||
// MessageListener
|
||||
virtual void handleMessage(MessageActivateTokens* message);
|
||||
virtual void handleMessage(MessageActivateLocalSymbols* message);
|
||||
virtual void handleMessage(MessageFocusIn* message);
|
||||
virtual void handleMessage(MessageFocusOut* message);
|
||||
virtual void handleMessage(MessageGraphNodeExpand* message);
|
||||
virtual void handleMessage(MessageScrollCode* message);
|
||||
virtual void handleMessage(MessageScrollGraph* message);
|
||||
virtual void handleMessage(MessageTooltipHide* message);
|
||||
virtual void handleMessage(MessageTooltipShow* message);
|
||||
virtual void handleMessage(MessageWindowFocus* message);
|
||||
|
||||
@@ -97,6 +97,8 @@ public:
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const = 0;
|
||||
|
||||
virtual TooltipInfo getTooltipInfoForTokenIds(const std::vector<Id>& tokenIds, TooltipOrigin origin) const = 0;
|
||||
virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const = 0;
|
||||
|
||||
protected:
|
||||
ErrorFilter m_errorFilter;
|
||||
|
||||
@@ -425,6 +425,17 @@ TooltipInfo StorageAccessProxy::getTooltipInfoForTokenIds(const std::vector<Id>&
|
||||
return TooltipInfo();
|
||||
}
|
||||
|
||||
TooltipInfo StorageAccessProxy::getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(locationIds, localSymbolIds);
|
||||
}
|
||||
|
||||
return TooltipInfo();
|
||||
}
|
||||
|
||||
void StorageAccessProxy::setErrorFilter(const ErrorFilter& filter)
|
||||
{
|
||||
StorageAccess::setErrorFilter(filter);
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
|
||||
virtual TooltipInfo getTooltipInfoForTokenIds(const std::vector<Id>& tokenIds, TooltipOrigin origin) const;
|
||||
virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const;
|
||||
|
||||
protected:
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
@@ -71,7 +71,10 @@ SourceLocation* SourceLocationFile::addSourceLocation(
|
||||
m_locations.insert(start);
|
||||
m_locations.insert(end);
|
||||
|
||||
m_locationIndex.emplace(start->getLocationId(), start.get());
|
||||
if (start->getLocationId())
|
||||
{
|
||||
m_locationIndex.emplace(start->getLocationId(), start.get());
|
||||
}
|
||||
|
||||
return start.get();
|
||||
}
|
||||
@@ -96,7 +99,11 @@ SourceLocation* SourceLocationFile::addSourceLocationCopy(const SourceLocation*
|
||||
|
||||
std::shared_ptr<SourceLocation> copy = std::make_shared<SourceLocation>(location, this);
|
||||
m_locations.insert(copy);
|
||||
m_locationIndex.emplace(copy->getLocationId(), copy.get());
|
||||
|
||||
if (copy->getLocationId())
|
||||
{
|
||||
m_locationIndex.emplace(copy->getLocationId(), copy.get());
|
||||
}
|
||||
|
||||
// If the old location was added before, then link them with each other.
|
||||
if (oldLocation)
|
||||
|
||||
@@ -1073,43 +1073,22 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
|
||||
std::set<Id> edgeIds;
|
||||
std::set<Id> nodeIds;
|
||||
std::set<Id> implicitNodeIds;
|
||||
|
||||
for (const StorageOccurrence& occurrence: m_sqliteIndexStorage.getOccurrencesForLocationIds(locationIds))
|
||||
{
|
||||
const Id elementId = occurrence.elementId;
|
||||
|
||||
StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(elementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
if (edge.id != 0)
|
||||
{
|
||||
edgeIds.insert(edge.targetNodeId);
|
||||
}
|
||||
else if(m_sqliteIndexStorage.isNode(elementId))
|
||||
else if (m_sqliteIndexStorage.isNode(elementId))
|
||||
{
|
||||
StorageSymbol symbol = m_sqliteIndexStorage.getFirstById<StorageSymbol>(elementId);
|
||||
if (symbol.id != 0) // here we test if location is a symbol
|
||||
{
|
||||
if (intToDefinitionKind(symbol.definitionKind) == DEFINITION_IMPLICIT)
|
||||
{
|
||||
implicitNodeIds.insert(elementId);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds.insert(elementId);
|
||||
}
|
||||
}
|
||||
else // is file
|
||||
{
|
||||
nodeIds.insert(elementId);
|
||||
}
|
||||
nodeIds.insert(elementId);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeIds.size() == 0)
|
||||
{
|
||||
nodeIds = implicitNodeIds;
|
||||
}
|
||||
|
||||
if (nodeIds.size())
|
||||
{
|
||||
return utility::toVector(nodeIds);
|
||||
@@ -1707,7 +1686,6 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
));
|
||||
}
|
||||
|
||||
Id locationId = 1;
|
||||
std::vector<std::pair<size_t, size_t>> locationRanges;
|
||||
for (auto p : typeNames)
|
||||
{
|
||||
@@ -1734,11 +1712,10 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
if (!inRange)
|
||||
{
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_TOKEN, locationId, std::vector<Id>(1, p.second), 1, pos + 1, 1, pos + p.first.size());
|
||||
LOCATION_TOKEN, 0, std::vector<Id>(1, p.second), 1, pos + 1, 1, pos + p.first.size());
|
||||
|
||||
locationRanges.push_back(std::make_pair(pos + 1, pos + p.first.size()));
|
||||
pos += p.first.size();
|
||||
locationId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1752,6 +1729,60 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
return snippet;
|
||||
}
|
||||
|
||||
TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
TooltipInfo info;
|
||||
|
||||
if (!locationIds.size() && !localSymbolIds.size())
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
if (locationIds.size())
|
||||
{
|
||||
std::vector<Id> tokenIds = getNodeIdsForLocationIds(locationIds);
|
||||
|
||||
for (StorageNode node : m_sqliteIndexStorage.getAllByIds<StorageNode>(tokenIds))
|
||||
{
|
||||
TooltipSnippet snippet;
|
||||
|
||||
NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
snippet.code = nameHierarchy.getQualifiedName();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? "main.java" : "main.cpp"), true, true);
|
||||
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_TOKEN, 0, std::vector<Id>(1, node.id), 1, 1, 1, snippet.code.size());
|
||||
|
||||
if (Node::intToType(node.type) & (Node::NODE_METHOD | Node::NODE_FUNCTION))
|
||||
{
|
||||
snippet.code += "()";
|
||||
}
|
||||
|
||||
info.snippets.push_back(snippet);
|
||||
}
|
||||
}
|
||||
|
||||
for (Id id : localSymbolIds)
|
||||
{
|
||||
TooltipSnippet snippet;
|
||||
|
||||
snippet.code = "local symbol";
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(FilePath("main.cpp"), true, true);
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_LOCAL_SYMBOL, 0, std::vector<Id>(1, id), 1, 1, 1, snippet.code.size());
|
||||
|
||||
info.snippets.push_back(snippet);
|
||||
}
|
||||
|
||||
info.offset = Vec2i(0, 15);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
Id PersistentStorage::getFileNodeId(const FilePath& filePath) const
|
||||
{
|
||||
if (filePath.empty())
|
||||
|
||||
@@ -138,6 +138,8 @@ public:
|
||||
|
||||
virtual TooltipInfo getTooltipInfoForTokenIds(const std::vector<Id>& tokenIds, TooltipOrigin origin) const;
|
||||
TooltipSnippet getTooltipSnippetForNode(const StorageNode& node) const;
|
||||
virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const;
|
||||
|
||||
private:
|
||||
Id getFileNodeId(const FilePath& filePath) const;
|
||||
|
||||
@@ -17,12 +17,24 @@ public:
|
||||
setSendAsTask(false);
|
||||
}
|
||||
|
||||
MessageTooltipShow(const std::vector<Id>& sourceLocationIds, const std::vector<Id>& localSymbolIds, TooltipOrigin origin)
|
||||
: sourceLocationIds(sourceLocationIds)
|
||||
, localSymbolIds(localSymbolIds)
|
||||
, origin(origin)
|
||||
{
|
||||
setSendAsTask(false);
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageTooltipShow";
|
||||
}
|
||||
|
||||
const TooltipInfo tooltipInfo;
|
||||
|
||||
const std::vector<Id> sourceLocationIds;
|
||||
const std::vector<Id> localSymbolIds;
|
||||
|
||||
const TooltipOrigin origin;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user