logic: Show symbols defined within file within file node when activating a file (issue #268)
This commit is contained in:
@@ -553,32 +553,7 @@ void GraphController::createDummyGraph(const std::shared_ptr<Graph> graph)
|
||||
}
|
||||
);
|
||||
|
||||
for (const std::shared_ptr<DummyNode>& node : dummyNodes)
|
||||
{
|
||||
node->hasParent = false;
|
||||
|
||||
if (node->data->getType().isPackage())
|
||||
{
|
||||
node->name = node->data->getFullName();
|
||||
}
|
||||
else
|
||||
{
|
||||
node->name = node->data->getName();
|
||||
|
||||
NameHierarchy qualifier = node->data->getNameHierarchy();
|
||||
qualifier.pop();
|
||||
|
||||
if (qualifier.size())
|
||||
{
|
||||
std::shared_ptr<DummyNode> qualifierNode = std::make_shared<DummyNode>(DummyNode::DUMMY_QUALIFIER);
|
||||
qualifierNode->qualifierName = qualifier;
|
||||
qualifierNode->visible = true;
|
||||
|
||||
node->subNodes.push_back(qualifierNode);
|
||||
node->hasQualifier = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateDummyNodeNamesAndAddQualifiers(dummyNodes);
|
||||
|
||||
m_dummyNodes = dummyNodes;
|
||||
|
||||
@@ -674,6 +649,39 @@ std::vector<std::shared_ptr<DummyNode>> GraphController::createDummyNodeTopDown(
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void GraphController::updateDummyNodeNamesAndAddQualifiers(
|
||||
const std::vector<std::shared_ptr<DummyNode>>& dummyNodes)
|
||||
{
|
||||
for (const std::shared_ptr<DummyNode>& node : dummyNodes)
|
||||
{
|
||||
if (node->isGroupNode() || !node->data || node->data->getType().isFile())
|
||||
{
|
||||
updateDummyNodeNamesAndAddQualifiers(node->subNodes);
|
||||
}
|
||||
else if (node->data->getType().isPackage())
|
||||
{
|
||||
node->name = node->data->getFullName();
|
||||
}
|
||||
else
|
||||
{
|
||||
node->name = node->data->getName();
|
||||
|
||||
NameHierarchy qualifier = node->data->getNameHierarchy();
|
||||
qualifier.pop();
|
||||
|
||||
if (qualifier.size())
|
||||
{
|
||||
std::shared_ptr<DummyNode> qualifierNode = std::make_shared<DummyNode>(DummyNode::DUMMY_QUALIFIER);
|
||||
qualifierNode->qualifierName = qualifier;
|
||||
qualifierNode->visible = true;
|
||||
|
||||
node->subNodes.push_back(qualifierNode);
|
||||
node->hasQualifier = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Id> GraphController::getExpandedNodeIds() const
|
||||
{
|
||||
std::vector<Id> nodeIds;
|
||||
|
||||
@@ -78,6 +78,8 @@ private:
|
||||
const std::vector<Id>& tokenIds, const std::shared_ptr<Graph> graph, bool keepExpandedNodesExpanded);
|
||||
std::vector<std::shared_ptr<DummyNode>> createDummyNodeTopDown(Node* node, Id ancestorId);
|
||||
|
||||
void updateDummyNodeNamesAndAddQualifiers(const std::vector<std::shared_ptr<DummyNode>>& dummyNodes);
|
||||
|
||||
std::vector<Id> getExpandedNodeIds() const;
|
||||
void setExpandedNodeIds(const std::vector<Id>& nodeIds);
|
||||
void autoExpandActiveNode(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
@@ -655,7 +655,6 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(
|
||||
}
|
||||
break;
|
||||
case Edge::EDGE_INCLUDE:
|
||||
case Edge::EDGE_MACRO_USAGE:
|
||||
style.zValue = isActive ? 2 : -3;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -141,11 +141,12 @@ bool NodeType::isCollapsible() const
|
||||
NodeType::NODE_SYMBOL |
|
||||
NodeType::NODE_TYPE |
|
||||
NodeType::NODE_BUILTIN_TYPE |
|
||||
NodeType::NODE_CLASS |
|
||||
NodeType::NODE_STRUCT |
|
||||
NodeType::NODE_CLASS |
|
||||
NodeType::NODE_INTERFACE |
|
||||
NodeType::NODE_ENUM |
|
||||
NodeType::NODE_UNION |
|
||||
NodeType::NODE_INTERFACE;
|
||||
NodeType::NODE_FILE;
|
||||
return ((m_type & mask) > 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -886,6 +886,8 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
bool addAggregations = false;
|
||||
std::vector<StorageEdge> edgesToAggregate;
|
||||
|
||||
bool addFileContents = false;
|
||||
|
||||
if (tokenIds.size() == 1)
|
||||
{
|
||||
const Id elementId = tokenIds[0];
|
||||
@@ -936,7 +938,14 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
}
|
||||
}
|
||||
|
||||
addAggregations = true;
|
||||
if (nodeType.isFile())
|
||||
{
|
||||
addFileContents = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addAggregations = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_sqliteIndexStorage.isEdge(elementId))
|
||||
@@ -995,6 +1004,10 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(
|
||||
{
|
||||
addAggregationEdgesToGraph(tokenIds[0], edgesToAggregate, graph);
|
||||
}
|
||||
else if (addFileContents)
|
||||
{
|
||||
addFileContentsToGraph(tokenIds[0], graph);
|
||||
}
|
||||
|
||||
if (!isPackage)
|
||||
{
|
||||
@@ -2368,7 +2381,7 @@ void PersistentStorage::addNodesWithParentsAndEdgesToGraph(
|
||||
}
|
||||
|
||||
void PersistentStorage::addAggregationEdgesToGraph(
|
||||
const Id nodeId, const std::vector<StorageEdge>& edgesToAggregate, Graph* graph) const
|
||||
Id nodeId, const std::vector<StorageEdge>& edgesToAggregate, Graph* graph) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
@@ -2469,6 +2482,58 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addFileContentsToGraph(Id fileId, Graph* graph) const
|
||||
{
|
||||
FilePath path = getFileNodePath(fileId);
|
||||
if (path.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
std::set<Id> tokenIdsSet;
|
||||
|
||||
std::shared_ptr<SourceLocationFile> locationFile = m_sqliteIndexStorage.getSourceLocationsForFile(path);
|
||||
locationFile->forEachStartSourceLocation(
|
||||
[this, &tokenIds, &tokenIdsSet](SourceLocation* location)
|
||||
{
|
||||
if (location->getType() != LOCATION_TOKEN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Id tokenId : location->getTokenIds())
|
||||
{
|
||||
if (tokenIdsSet.insert(tokenId).second)
|
||||
{
|
||||
auto it = m_symbolDefinitionKinds.find(tokenId);
|
||||
if (it == m_symbolDefinitionKinds.end() || it->second != DEFINITION_IMPLICIT)
|
||||
{
|
||||
tokenIds.push_back(tokenId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
addNodesWithParentsAndEdgesToGraph(tokenIds, { }, graph, true);
|
||||
|
||||
Node* fileNode = graph->getNodeById(fileId);
|
||||
Id memberEdgeId = 0;
|
||||
for (Id tokenId : tokenIds)
|
||||
{
|
||||
Id nodeId = m_hierarchyCache.getLastVisibleParentNodeId(tokenId);
|
||||
Node* node = graph->getNodeById(nodeId);
|
||||
if (node && !node->getMemberEdge())
|
||||
{
|
||||
// Set first bit to 1 to avoid collisions
|
||||
graph->createEdge(~(~Id(0) >> 1) + memberEdgeId++, Edge::EDGE_MEMBER, fileNode, node);
|
||||
}
|
||||
}
|
||||
|
||||
fileNode->setChildCount(memberEdgeId);
|
||||
}
|
||||
|
||||
void PersistentStorage::addComponentAccessToGraph(Graph* graph) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
@@ -172,7 +172,8 @@ private:
|
||||
void addNodesWithParentsAndEdgesToGraph(
|
||||
const std::vector<Id>& nodeIds, const std::vector<Id>& edgeIds, Graph* graphh, bool addChildCount) const;
|
||||
|
||||
void addAggregationEdgesToGraph(const Id nodeId, const std::vector<StorageEdge>& edgesToAggregate, Graph* graph) const;
|
||||
void addAggregationEdgesToGraph(Id nodeId, const std::vector<StorageEdge>& edgesToAggregate, Graph* graph) const;
|
||||
void addFileContentsToGraph(Id fileId, Graph* graph) const;
|
||||
void addComponentAccessToGraph(Graph* graph) const;
|
||||
|
||||
void addCompleteFlagsToSourceLocationCollection(SourceLocationCollection* collection) const;
|
||||
|
||||
@@ -869,7 +869,7 @@ QtGraphNode* QtGraphView::createNodeRecursive(
|
||||
QtGraphNode* newNode = nullptr;
|
||||
if (node->isGraphNode())
|
||||
{
|
||||
newNode = new QtGraphNodeData(node->data, node->name, node->hasParent, node->childVisible, node->hasQualifier);
|
||||
newNode = new QtGraphNodeData(node->data, node->name, node->childVisible, node->hasQualifier);
|
||||
}
|
||||
else if (node->isAccessNode())
|
||||
{
|
||||
|
||||
@@ -9,13 +9,12 @@
|
||||
|
||||
#include "data/graph/token_component/TokenComponentFilePath.h"
|
||||
|
||||
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::wstring& name, bool hasParent, bool childVisible, bool hasQualifier)
|
||||
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier)
|
||||
: m_data(data)
|
||||
, m_childVisible(childVisible)
|
||||
, m_hasQualifier(hasQualifier)
|
||||
{
|
||||
this->setAcceptHoverEvents(true);
|
||||
|
||||
this->setName(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class QtGraphNodeData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtGraphNodeData(const Node* data, const std::wstring& name, bool hasParent, bool childVisible, bool hasQualifier);
|
||||
QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier);
|
||||
virtual ~QtGraphNodeData();
|
||||
|
||||
const Node* getData() const;
|
||||
|
||||
Reference in New Issue
Block a user