Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint to include more data with AST node metrics #755

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions plugins/cpp_metrics/model/include/model/cppastnodemetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <model/cppastnode.h>
#include <model/cppentity.h>
#include <model/cpprecord.h>
#include <model/position.h>

namespace cc
{
Expand Down Expand Up @@ -78,6 +79,42 @@ struct CppAstNodeMetricsForPathView
double value;
};

#pragma db view \
object(CppAstNodeMetrics) \
object(CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
object(File = LocFile : CppAstNode::location.file)
struct CppAstNodeMetricsAndDataForPathView
{
typedef cc::model::Position::PosType PosType;

#pragma db column(CppAstNodeMetrics::astNodeId)
CppAstNodeId astNodeId;

#pragma db column(LocFile::path)
std::string path;

#pragma db column(CppAstNode::location.range.start.line)
PosType startLine;

#pragma db column(CppAstNode::location.range.end.line)
PosType endLine;

#pragma db column(CppAstNode::astValue)
std::string astValue;

#pragma db column(CppAstNode::symbolType)
CppAstNode::SymbolType symbolType;

#pragma db column(CppAstNode::astType)
CppAstNode::AstType astType;

#pragma db column(CppAstNodeMetrics::type)
CppAstNodeMetrics::Type type;

#pragma db column(CppAstNodeMetrics::value)
double value;
};

} //model
} //cc

Expand Down
21 changes: 18 additions & 3 deletions plugins/cpp_metrics/service/cxxmetrics.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ struct CppMetricsAstNodeSingle
3:double value
}

struct CppMetricsAstNodeAll
mcserep marked this conversation as resolved.
Show resolved Hide resolved
struct CppMetricsAstNodeDetailed
{
1:common.AstNodeId id,
2:list<CppMetricsAstNodeSingle> metrics
1:string path,
2:string file,
3:string symbolType,
4:string astType,
5:i32 startLine,
6:i32 endLine,
7:string astValue,
8:map<CppAstNodeMetricsType, double> metrics
}

struct CppMetricsModuleSingle
Expand Down Expand Up @@ -90,6 +96,15 @@ service CppMetricsService
map<common.AstNodeId, list<CppMetricsAstNodeSingle>> getCppAstNodeMetricsForPath(
1:string path)

/**
* This function returns all available C++ metrics
* (AST node-level) and miscellaneous data for a particular path.
*
* The given path is a handled as a prefix.
*/
map<common.AstNodeId, CppMetricsAstNodeDetailed> getCppAstNodeMetricsDetailedForPath(
1:string path)

/**
* This function returns all available C++ metrics
* (file-level) for a particular path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_) override;

void getCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_) override;

void getCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_) override;
Expand Down
42 changes: 42 additions & 0 deletions plugins/cpp_metrics/service/src/cppmetricsservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <odb/query.hxx>
#include <model/file.h>
#include <model/file-odb.hxx>
#include <model/cppastnode.h>
#include <model/cppastnode-odb.hxx>

namespace cc
{
Expand Down Expand Up @@ -161,6 +163,46 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
});
}

void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_)
{
_transaction([&, this](){
typedef odb::query<model::CppAstNodeFilePath> CppAstNodeFilePathQuery;
typedef odb::result<model::CppAstNodeFilePath> CppAstNodeFilePathResult;
typedef odb::query<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewQuery;
typedef odb::result<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewResult;

auto nodes = _db->query<model::CppAstNodeMetricsAndDataForPathView>(
CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%'));

for (const auto& node : nodes)
{
auto pair = std::make_pair(static_cast<CppAstNodeMetricsType::type>(node.type), node.value);
if (_return.count(std::to_string(node.astNodeId)))
{
_return[std::to_string(node.astNodeId)].metrics.insert(pair);
}
else
{
CppMetricsAstNodeDetailed metric;
std::size_t pos = node.path.find_last_of('/');
metric.path = node.path.substr(0, pos + 1);
metric.file = node.path.substr(pos + 1);
metric.startLine = node.startLine;
metric.endLine = node.endLine;
metric.astValue = node.astValue;
metric.symbolType = cc::model::symbolTypeToString(node.symbolType);
metric.astType = cc::model::astTypeToString(node.astType);

std::map<CppAstNodeMetricsType::type, double> metricsList;
metricsList.insert(pair);
_return.insert(std::make_pair(std::to_string(node.astNodeId), metric));
}
}
});
}

void CppMetricsServiceHandler::getCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_)
Expand Down
Loading