ui: show signature in function & method tooltip
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeMove.h"
|
||||
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
|
||||
QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVisible)
|
||||
: m_data(data)
|
||||
, m_childVisible(childVisible)
|
||||
@@ -26,6 +28,15 @@ QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVis
|
||||
toolTip = "undefined " + toolTip;
|
||||
}
|
||||
|
||||
if (data->isType(Node::NODE_FUNCTION | Node::NODE_METHOD))
|
||||
{
|
||||
TokenComponentSignature* sig = data->getComponent<TokenComponentSignature>();
|
||||
if (sig)
|
||||
{
|
||||
toolTip += ": " + sig->getSignature();
|
||||
}
|
||||
}
|
||||
|
||||
this->setToolTip(QString::fromStdString(toolTip));
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,8 @@ add_files(
|
||||
data/graph/token_component/TokenComponentConst.h
|
||||
data/graph/token_component/TokenComponentFilePath.cpp
|
||||
data/graph/token_component/TokenComponentFilePath.h
|
||||
data/graph/token_component/TokenComponentSignature.cpp
|
||||
data/graph/token_component/TokenComponentSignature.h
|
||||
data/graph/token_component/TokenComponentStatic.cpp
|
||||
data/graph/token_component/TokenComponentStatic.h
|
||||
|
||||
|
||||
@@ -606,7 +606,7 @@ NameHierarchy SqliteStorage::getNameHierarchyById(const Id id) const
|
||||
StorageSourceLocation SqliteStorage::getSourceLocationByData(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, bool isScope) const
|
||||
{
|
||||
return getFirstSourceLocation((
|
||||
"SELECT * FROM source_location WHERE element_id == " + std::to_string(elementId)
|
||||
"SELECT * FROM source_location WHERE element_id == " + std::to_string(elementId)
|
||||
+ " AND file_node_id == " + std::to_string(fileNodeId)
|
||||
+ " AND start_line == " + std::to_string(startLine)
|
||||
+ " AND start_column == " + std::to_string(startCol)
|
||||
@@ -752,6 +752,20 @@ Id SqliteStorage::getNodeIdBySignature(const std::string& signature) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string SqliteStorage::getSignatureByNodeId(Id nodeId) const
|
||||
{
|
||||
CppSQLite3Query q = m_database.execQuery((
|
||||
"SELECT id, signature FROM function_signature WHERE id == " + std::to_string(nodeId) + ";"
|
||||
).c_str());
|
||||
|
||||
while (!q.eof())
|
||||
{
|
||||
return q.getStringField(1, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
{
|
||||
Id fileNodeId = getFileByPath(filePath.str()).id;
|
||||
|
||||
@@ -107,6 +107,7 @@ public:
|
||||
StorageComponentAccess getComponentAccessByMemberEdgeId(Id memberEdgeId) const;
|
||||
std::vector<StorageComponentAccess> getComponentAccessByMemberEdgeIds(const std::vector<Id>& memberEdgeIds) const;
|
||||
Id getNodeIdBySignature(const std::string& signature) const;
|
||||
std::string getSignatureByNodeId(Id nodeId) const;
|
||||
|
||||
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
std::vector<StorageError> getAllErrors() const;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/graph/token_component/TokenComponentAggregation.h"
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
@@ -1258,11 +1259,11 @@ std::shared_ptr<TokenLocationFile> Storage::getCommentLocationsInFile(const File
|
||||
for (size_t i = 0; i < storageLocations.size(); i++)
|
||||
{
|
||||
TokenLocation* loc = file->addTokenLocation(
|
||||
storageLocations[i].id,
|
||||
storageLocations[i].id,
|
||||
0, // comment token location has no element.
|
||||
storageLocations[i].startLine,
|
||||
storageLocations[i].startCol,
|
||||
storageLocations[i].endLine,
|
||||
storageLocations[i].startLine,
|
||||
storageLocations[i].startCol,
|
||||
storageLocations[i].endLine,
|
||||
storageLocations[i].endCol
|
||||
);
|
||||
}
|
||||
@@ -1612,12 +1613,20 @@ void Storage::addNodesToGraph(const std::vector<Id> nodeIds, Graph* graph) const
|
||||
|
||||
for (const StorageNode& storageNode : storageNodes)
|
||||
{
|
||||
graph->createNode(
|
||||
Node::NodeType type = Node::intToType(storageNode.type);
|
||||
Node* node = graph->createNode(
|
||||
storageNode.id,
|
||||
Node::intToType(storageNode.type),
|
||||
type,
|
||||
m_tokenIndex.getNameHierarchyForTokenId(storageNode.id),
|
||||
storageNode.defined
|
||||
);
|
||||
|
||||
if (type == Node::NODE_FUNCTION || type == Node::NODE_METHOD)
|
||||
{
|
||||
node->addComponentSignature(
|
||||
std::make_shared<TokenComponentSignature>(m_sqliteStorage.getSignatureByNodeId(storageNode.id))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "data/graph/token_component/TokenComponentConst.h"
|
||||
#include "data/graph/token_component/TokenComponentStatic.h"
|
||||
#include "data/graph/token_component/TokenComponentFilePath.h"
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
|
||||
const Node::NodeTypeMask Node::NODE_NOT_VISIBLE = Node::NODE_UNDEFINED | Node::NODE_NAMESPACE;
|
||||
|
||||
@@ -395,6 +396,23 @@ void Node::addComponentFilePath(std::shared_ptr<TokenComponentFilePath> componen
|
||||
}
|
||||
}
|
||||
|
||||
void Node::addComponentSignature(std::shared_ptr<TokenComponentSignature> component)
|
||||
{
|
||||
if (getComponent<TokenComponentSignature>())
|
||||
{
|
||||
LOG_ERROR("TokenComponentSignature has been set before!");
|
||||
return;
|
||||
}
|
||||
else if (!isType(NODE_FUNCTION | NODE_METHOD))
|
||||
{
|
||||
LOG_ERROR("TokenComponentFilePath can't be set on node of type: " + getTypeString());
|
||||
}
|
||||
else
|
||||
{
|
||||
addComponent(component);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Node::getTypeString() const
|
||||
{
|
||||
return getTypeString(m_type);
|
||||
|
||||
@@ -14,6 +14,7 @@ class TokenComponentAbstraction;
|
||||
class TokenComponentConst;
|
||||
class TokenComponentStatic;
|
||||
class TokenComponentFilePath;
|
||||
class TokenComponentSignature;
|
||||
|
||||
class Node
|
||||
: public Token
|
||||
@@ -91,6 +92,7 @@ public:
|
||||
void addComponentConst(std::shared_ptr<TokenComponentConst> component);
|
||||
void addComponentStatic(std::shared_ptr<TokenComponentStatic> component);
|
||||
void addComponentFilePath(std::shared_ptr<TokenComponentFilePath> component);
|
||||
void addComponentSignature(std::shared_ptr<TokenComponentSignature> component);
|
||||
|
||||
// Logging.
|
||||
virtual std::string getTypeString() const;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
|
||||
TokenComponentSignature::TokenComponentSignature(const std::string& signature)
|
||||
: m_signature(signature)
|
||||
{
|
||||
}
|
||||
|
||||
TokenComponentSignature::~TokenComponentSignature()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenComponent> TokenComponentSignature::copy() const
|
||||
{
|
||||
return std::make_shared<TokenComponentSignature>(*this);
|
||||
}
|
||||
|
||||
const std::string& TokenComponentSignature::getSignature() const
|
||||
{
|
||||
return m_signature;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef TOKEN_COMPONENT_SIGNATURE_H
|
||||
#define TOKEN_COMPONENT_SIGNATURE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "data/graph/token_component/TokenComponent.h"
|
||||
|
||||
class TokenComponentSignature
|
||||
: public TokenComponent
|
||||
{
|
||||
public:
|
||||
TokenComponentSignature(const std::string& signature);
|
||||
virtual ~TokenComponentSignature();
|
||||
|
||||
virtual std::shared_ptr<TokenComponent> copy() const;
|
||||
|
||||
const std::string& getSignature() const;
|
||||
|
||||
private:
|
||||
const std::string m_signature;
|
||||
};
|
||||
|
||||
#endif // TOKEN_COMPONENT_SIGNATURE_H
|
||||
Reference in New Issue
Block a user