Skip to content

Commit 1778aa6

Browse files
committed
Fixed issues mentioned in PR comments
1 parent 4662f95 commit 1778aa6

6 files changed

Lines changed: 151 additions & 155 deletions

File tree

plugins/csharp/parser/src/csharpparser.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ bool CsharpParser::parse()
4646

4747
if (acceptProjectBuildPath(buildPath))
4848
{
49-
LOG(debug) << "C# parser parse path: " << paths[0];
50-
LOG(debug) << "Parsed csharp project build path: " << buildPath;
5149
success = success && parseProjectBuildPath(paths, buildPath);
5250
}
5351
else
@@ -108,7 +106,6 @@ bool CsharpParser::parseProjectBuildPath(
108106

109107
std::string line;
110108
std::stringstream log_str(log.get());
111-
//LOG(warning) << log_str.str();
112109
int countFull = 0, countPart = 0;
113110

114111
while(std::getline(log_str, line, '\n'))

plugins/csharp/parser/src_csharp/AstVisitor.cs

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,18 @@ partial class AstVisitor : CSharpSyntaxWalker
1414
private readonly CsharpDbContext DbContext;
1515
private readonly SemanticModel Model;
1616
private readonly SyntaxTree Tree;
17+
private readonly AstVisitorHelper Helper;
1718

1819
public bool FullyParsed = true;
1920

2021
public AstVisitor(CsharpDbContext context, SemanticModel model, SyntaxTree tree)
2122
{
2223
this.DbContext = context;
2324
this.Model = model;
24-
this.Tree = tree;
25-
}
26-
27-
private ulong createIdentifier(CsharpAstNode astNode){
28-
string[] properties =
29-
{
30-
astNode.AstValue,":",
31-
astNode.AstType.ToString(),":",
32-
astNode.EntityHash.ToString(),":",
33-
astNode.RawKind.ToString(),":",
34-
astNode.Path,":",
35-
astNode.Location_range_start_line.ToString(),":",
36-
astNode.Location_range_start_column.ToString(),":",
37-
astNode.Location_range_end_line.ToString(),":",
38-
astNode.Location_range_end_column.ToString()
39-
};
40-
41-
string res = string.Concat(properties);
42-
43-
//WriteLine(res);
44-
return fnvHash(res);
25+
this.Tree = tree;
26+
this.Helper = new AstVisitorHelper();
4527
}
4628

47-
private ulong fnvHash(string data_)
48-
{
49-
ulong hash = 14695981039346656037;
50-
51-
int len = data_.Length;
52-
for (int i = 0; i < len; ++i)
53-
{
54-
hash ^= data_[i];
55-
hash *= 1099511628211;
56-
}
57-
58-
return hash;
59-
}
60-
61-
private ulong getAstNodeId(SyntaxNode node){
62-
CsharpAstNode astNode = new CsharpAstNode
63-
{
64-
AstValue = node.ToString(),
65-
RawKind = node.Kind(),
66-
EntityHash = node.GetHashCode(),
67-
AstType = AstTypeEnum.Declaration
68-
};
69-
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
70-
var ret = createIdentifier(astNode);
71-
return ret;
72-
}
73-
7429
private CsharpAstNode AstNode(SyntaxNode node, AstSymbolTypeEnum type, AstTypeEnum astType)
7530
{
7631
Accessibility acc = Accessibility.NotApplicable;
@@ -92,7 +47,7 @@ private CsharpAstNode AstNode(SyntaxNode node, AstSymbolTypeEnum type, AstTypeEn
9247
Accessibility = acc
9348
};
9449
astNode.SetLocation(Tree.GetLineSpan(node.Span));
95-
astNode.Id = createIdentifier(astNode);
50+
astNode.Id = Helper.createIdentifier(astNode);
9651

9752
if (DbContext.CsharpAstNodes.Find(astNode.Id) == null)
9853
{
@@ -933,7 +888,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
933888
FullyParsed = false;
934889
}
935890
var info = Model.GetTypeInfo(node).ConvertedType;
936-
var declaratorNodeId = getAstNodeId(declaration.GetSyntax());
891+
var declaratorNodeId = Helper.getAstNodeId(declaration.GetSyntax());
937892
var astNode = AstNode(node, AstSymbolTypeEnum.EtcEntity, AstTypeEnum.Usage);
938893
CsharpEtcEntity invoc = new CsharpEtcEntity
939894
{
@@ -981,7 +936,7 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
981936
EtcEntityTypeEnum.ForeachExpr : EtcEntityTypeEnum.Invocation;
982937
if (node.Parent.Parent.Kind() != SyntaxKind.InvocationExpression)
983938
{
984-
var declaratorNodeId = getAstNodeId(declaration.GetSyntax());
939+
var declaratorNodeId = Helper.getAstNodeId(declaration.GetSyntax());
985940
var astNode = AstNode(node, AstSymbolTypeEnum.EtcEntity, AstTypeEnum.Usage);
986941
CsharpEtcEntity expr = new CsharpEtcEntity
987942
{
@@ -1004,4 +959,54 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
1004959

1005960
}
1006961
}
962+
963+
class AstVisitorHelper
964+
{
965+
public ulong createIdentifier(CsharpAstNode astNode){
966+
string[] properties =
967+
{
968+
astNode.AstValue,":",
969+
astNode.AstType.ToString(),":",
970+
astNode.EntityHash.ToString(),":",
971+
astNode.RawKind.ToString(),":",
972+
astNode.Path,":",
973+
astNode.Location_range_start_line.ToString(),":",
974+
astNode.Location_range_start_column.ToString(),":",
975+
astNode.Location_range_end_line.ToString(),":",
976+
astNode.Location_range_end_column.ToString()
977+
};
978+
979+
string res = string.Concat(properties);
980+
981+
//WriteLine(res);
982+
return fnvHash(res);
983+
}
984+
985+
private ulong fnvHash(string data_)
986+
{
987+
ulong hash = 14695981039346656037;
988+
989+
int len = data_.Length;
990+
for (int i = 0; i < len; ++i)
991+
{
992+
hash ^= data_[i];
993+
hash *= 1099511628211;
994+
}
995+
996+
return hash;
997+
}
998+
999+
public ulong getAstNodeId(SyntaxNode node){
1000+
CsharpAstNode astNode = new CsharpAstNode
1001+
{
1002+
AstValue = node.ToString(),
1003+
RawKind = node.Kind(),
1004+
EntityHash = node.GetHashCode(),
1005+
AstType = AstTypeEnum.Declaration
1006+
};
1007+
astNode.SetLocation(node.SyntaxTree.GetLineSpan(node.Span));
1008+
var ret = createIdentifier(astNode);
1009+
return ret;
1010+
}
1011+
}
10071012
}

plugins/csharp/parser/src_csharp/Program.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int Main(string[] args)
8282
}*/
8383

8484
//Converting the connectionstring into entiy framwork style connectionstring
85-
string csharpConnectionString = transformConnectionString();
85+
string csharpConnectionString = ProgramHelper.transformConnectionString(_connectionString);
8686

8787
var options = new DbContextOptionsBuilder<CsharpDbContext>()
8888
.UseNpgsql(csharpConnectionString)
@@ -95,17 +95,17 @@ static int Main(string[] args)
9595
foreach (var p in _rootDir)
9696
{
9797
Console.WriteLine(p);
98-
allFiles.AddRange(GetSourceFilesFromDir(p, ".cs"));
98+
allFiles.AddRange(ProgramHelper.GetSourceFilesFromDir(p, ".cs"));
9999
}
100100

101101
foreach (var f in allFiles)
102102
{
103103
WriteLine(f);
104104
}
105-
IEnumerable<string> assemblies = GetSourceFilesFromDir(_buildDir, ".dll");
105+
IEnumerable<string> assemblies = ProgramHelper.GetSourceFilesFromDir(_buildDir, ".dll");
106106
IEnumerable<string> assemblies_base = assemblies;
107107
if (args.Length == 5)
108-
assemblies_base = GetSourceFilesFromDir(_buildDirBase, ".dll");
108+
assemblies_base = ProgramHelper.GetSourceFilesFromDir(_buildDirBase, ".dll");
109109

110110
List<SyntaxTree> trees = new List<SyntaxTree>();
111111
foreach (string file in allFiles)
@@ -197,6 +197,11 @@ private static async Task<int> ParseTree(CsharpDbContext context,
197197
return await ParsingTask;
198198
}
199199

200+
201+
}
202+
203+
class ProgramHelper
204+
{
200205
public static IEnumerable<string> GetSourceFilesFromDir(string root, string extension)
201206
{
202207
IEnumerable<string> allFiles = new string[]{};
@@ -268,7 +273,7 @@ public static IEnumerable<string> GetSourceFilesFromDir(string root, string exte
268273
return allFiles;
269274
}
270275

271-
private static string transformConnectionString()
276+
public static string transformConnectionString(string _connectionString)
272277
{
273278
_connectionString = _connectionString.Substring(_connectionString.IndexOf(':')+1);
274279
_connectionString = _connectionString.Replace("user", "username");

plugins/csharp/service/include/service/csharpservice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CSharpQueryHandler : public CsharpServiceIf
8181

8282
if (elapsed_time > timeoutInMs_)
8383
{
84-
LOG(debug) << "Connection timeout, could not reach CSharp server on"
84+
LOG(error) << "Connection timeout, could not reach CSharp server on"
8585
<< host << ":" << _thriftServerPort;
8686
apache::thrift::GlobalOutput.setOutputFunction(
8787
apache::thrift::TOutput::errorTimeWrapper);

plugins/csharp/service/src/csharpservice.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ int CsharpServiceHandler::getThriftServerPort()
5959
acceptor.bind(endPoint, ec);
6060

6161
if (!ec) {
62-
//LOG(info) << "[C# Plugin] Thrift server bound to port: " << port << std::endl;
6362
acceptor.close(ec);
6463
return port;
6564
}
@@ -78,7 +77,6 @@ std::string CsharpServiceHandler::getDbString()
7877

7978
void CsharpServiceHandler::getFileTypes(std::vector<std::string>& return_)
8079
{
81-
//LOG(info) << "CsharpServiceHandler getFileTypes";
8280
return_.push_back("CS");
8381
return_.push_back("Dir");
8482
}
@@ -95,7 +93,6 @@ void CsharpServiceHandler::getAstNodeInfo(
9593
std::stringstream ss;
9694
ss << file;
9795
return_.range.file = ss.str();
98-
//LOG(info) << "csharpQuery.getAstNodeInfo: file = " << return_.range.file;
9996
}
10097

10198
void CsharpServiceHandler::getAstNodeInfoByPosition(
@@ -113,7 +110,6 @@ void CsharpServiceHandler::getSourceText(
113110
std::string& return_,
114111
const core::AstNodeId& astNodeId_)
115112
{
116-
LOG(info) << "getSourceText";
117113
core::FileRange fileRange;
118114

119115
_csharpQueryHandler.getFileRange(fileRange, astNodeId_);
@@ -139,23 +135,21 @@ void CsharpServiceHandler::getProperties(
139135
std::map<std::string, std::string>& return_,
140136
const core::AstNodeId& astNodeId_)
141137
{
142-
//LOG(info) << "getProperties";
143138
_csharpQueryHandler.getProperties(return_, astNodeId_);
144139
}
145140

146141
void CsharpServiceHandler::getDocumentation(
147142
std::string& return_,
148143
const core::AstNodeId& astNodeId_)
149144
{
150-
LOG(info) << "getDocumentation";
151145
_csharpQueryHandler.getDocumentation(return_, astNodeId_);
152146
}
153147

154148
void CsharpServiceHandler::getDiagramTypes(
155149
std::map<std::string, std::int32_t>& return_,
156150
const core::AstNodeId& astNodeId_)
157151
{
158-
LOG(info) << "getDiagramTypes";
152+
//TODO
159153
//csharpQueryHandler.getDiagramTypes(return_, astNodeId_);
160154
}
161155

@@ -164,52 +158,50 @@ void CsharpServiceHandler::getDiagram(
164158
const core::AstNodeId& astNodeId_,
165159
const std::int32_t diagramId_)
166160
{
167-
LOG(info) << "getDiagram";
161+
//TODO
168162
//csharpQueryHandler.getDiagram(return_, astNodeId_, diagramId_);
169163
}
170164

171165
void CsharpServiceHandler::getDiagramLegend(
172166
std::string& return_,
173167
const std::int32_t diagramId_)
174168
{
175-
LOG(info) << "getDiagramLegend";
169+
//TODO
176170
}
177171

178172
void CsharpServiceHandler::getFileDiagramTypes(
179173
std::map<std::string, std::int32_t>& return_,
180174
const core::FileId& fileId_)
181175
{
182-
LOG(info) << "getFileDiagramTypes";
176+
//TODO
183177
}
184178

185179
void CsharpServiceHandler::getFileDiagram(
186180
std::string& return_,
187181
const core::FileId& fileId_,
188182
const int32_t diagramId_)
189183
{
190-
LOG(info) << "getFileDiagram";
184+
//TODO
191185
}
192186

193187
void CsharpServiceHandler::getFileDiagramLegend(
194188
std::string& return_,
195189
const std::int32_t diagramId_)
196190
{
197-
LOG(info) << "getFileDiagramLegend";
191+
//TODO
198192
}
199193

200194
void CsharpServiceHandler::getReferenceTypes(
201195
std::map<std::string, std::int32_t>& return_,
202196
const core::AstNodeId& astNodeId_)
203197
{
204-
//LOG(info) << "getReferenceTypes";
205198
_csharpQueryHandler.getReferenceTypes(return_, astNodeId_);
206199
}
207200

208201
std::int32_t CsharpServiceHandler::getReferenceCount(
209202
const core::AstNodeId& astNodeId_,
210203
const std::int32_t referenceId_)
211204
{
212-
//LOG(info) << "getReferenceCount";
213205
return _csharpQueryHandler.getReferenceCount(astNodeId_, referenceId_);
214206
}
215207

@@ -219,7 +211,6 @@ void CsharpServiceHandler::getReferences(
219211
const std::int32_t referenceId_,
220212
const std::vector<std::string>& tags_)
221213
{
222-
//LOG(info) << "getReferences";
223214
_csharpQueryHandler.getReferences(return_, astNodeId_, referenceId_, tags_);
224215
std::vector<AstNodeInfo> ret;
225216
for (AstNodeInfo nodeinfo : return_)
@@ -244,7 +235,6 @@ void CsharpServiceHandler::getReferencesInFile(
244235
const core::FileId& /* fileId_ */,
245236
const std::vector<std::string>& /* tags_ */)
246237
{
247-
//LOG(info) << "getReferencesInFile";
248238
// TODO
249239
}
250240

@@ -255,23 +245,20 @@ void CsharpServiceHandler::getReferencesPage(
255245
const std::int32_t /* pageSize_ */,
256246
const std::int32_t /* pageNo_ */)
257247
{
258-
//LOG(info) << "getReferencesPage";
259248
// TODO
260249
}
261250

262251
void CsharpServiceHandler::getFileReferenceTypes(
263252
std::map<std::string, std::int32_t>& return_,
264253
const core::FileId& /* fileId_*/)
265254
{
266-
//LOG(info) << "getFileReferenceTypes";
267255
_csharpQueryHandler.getFileReferenceTypes(return_);
268256
}
269257

270258
std::int32_t CsharpServiceHandler::getFileReferenceCount(
271259
const core::FileId& fileId_,
272260
const std::int32_t referenceId_)
273261
{
274-
//LOG(info) << "getFileReferenceCount";
275262
model::FilePtr file = _transaction([&, this](){
276263
return _db->query_one<model::File>(
277264
FileQuery::id == std::stoull(fileId_));
@@ -284,7 +271,6 @@ void CsharpServiceHandler::getFileReferences(
284271
const core::FileId& fileId_,
285272
const std::int32_t referenceId_)
286273
{
287-
//LOG(info) << "getFileReferences";
288274
model::FilePtr file = _transaction([&, this](){
289275
return _db->query_one<model::File>(
290276
FileQuery::id == std::stoull(fileId_));
@@ -296,7 +282,7 @@ void CsharpServiceHandler::getSyntaxHighlight(
296282
std::vector<SyntaxHighlight>& return_,
297283
const core::FileRange& range_)
298284
{
299-
LOG(info) << "getSyntaxHighlight";
285+
//TODO
300286
/*
301287
std::vector<std::string> content;
302288
_transaction([&, this]() {

0 commit comments

Comments
 (0)