-
Notifications
You must be signed in to change notification settings - Fork 102
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
Support for C# static analysis #584
base: master
Are you sure you want to change the base?
Conversation
…e.Definition handling.
…ons instead of a connection string parameter. Also did some minor (mostly syntactic) refactoring on the code.
…moving unnecessary ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin generally works fine, however, there is much space for improvement. We should run some tests on larger projects to find critical errors.
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\lib\csharp\thrift_netstd\Thrift\Thrift.csproj" /> | ||
<ProjectReference Include="..\..\..\..\..\..\..\codecompass\intjftw-build\plugins\csharp\service\src_csharp\gen-netstd\gen-netstd.csproj" /> | ||
</ItemGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are written into the file by CMake in order to include two csproj files. The Thrift.csproj file reference can be put in as a default reference since it is part of the source code with a fixed path. However, the other one (gen-netstd.csproj) is generated by CMake in a previous step inside the build directory, so this reference cannot be guaranteed to have the same relative path all the time, hence the ugly path to my build directory. This reference is added during build time and it requires the committer to manually delete this line everytime they want to make a git commit. My question is, @mcserep, what do you think how we can solve this problem? Adding some kind of git hook or git filter that automatically deletes this line from the csproj file is a valid solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tough question, I see the following options:
- Generated, language-specific Thrift interfaces should be generated into the source folder and version controlled. These files rarely change and it is also an issue for the web frontend that the required JS/TS interfaces are not available in the source folder of CodeCompass. As a first attempt we could do this for the C# Thrift interfaces to see how this work. However, if shall refactor this later to the complete project. (Preferably in another PR.)
- Copy the complete C# source code into the build folder, edit the .csproj file there, and do the compilation there. Basically that is what we do for the current and the new (New web frontend #590) webgui, in the installation folder. Kinda ugly to be honest.
- During building copy the
csharpservice.csproj
inside the source directory, e.g.csharpservice_generated.csproj
and edit the copied version. Use that for building the C# project. Placecsharpservice_generated.csproj
in the gitignore list.
In my opinion, option 2 is what we currently do, but it is not really nice. Option 1 should be the proper solution, but it requires refactoring for the complete project to be a proper solution. Option 3 requires minimal extra effort. Although it creates a new generated file in the source directory, that could easily be ignored from VC. It is not really the proper and general solution, but can be done easily.
So maybe do Option 3 now and later refactor as suggested in Option 1 in a separate PR?
bool CsharpParser::acceptProjectBuildPath(const std::vector<std::string>& path_) | ||
{ | ||
return path_.size() >= 2 && fs::is_directory(path_[0]) && fs::is_directory(path_[1]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser requires the source code root directory and the build directory to work properly. Right now the solution is to have a fix order of input parameters (the source root first and the build directory second). This is a very inflexible solution, especially if we want to use multiple language plugins at the same time.
add_custom_target(dotnetaddref2 | ||
COMMAND dotnet add reference ${CMAKE_SOURCE_DIR}/lib/csharp/thrift_netstd/Thrift/Thrift.csproj | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen-netstd/" | ||
) | ||
|
||
add_dependencies(dotnetaddref2 dotnetaddref dotnetaddclasslib dotnetbuildservice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this reference can be written in csproj file permanently.
std::string& return_, | ||
const core::AstNodeId& astNodeId_) | ||
{ | ||
LOG(info) << "getSourceText"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All unnecessary debug comments should be deleted.
namespace bp = boost::process; | ||
namespace pt = boost::property_tree; | ||
|
||
int CsharpServiceHandler::_thriftServerPort = 9091; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us make sure that the port is free and if it's not, search for a free one.
private ulong createIdentifier(CsharpAstNode astNode){ | ||
string[] properties = | ||
{ | ||
astNode.AstValue,":", | ||
astNode.AstType.ToString(),":", | ||
astNode.EntityHash.ToString(),":", | ||
astNode.RawKind.ToString(),":", | ||
astNode.Path,":", | ||
astNode.Location_range_start_line.ToString(),":", | ||
astNode.Location_range_start_column.ToString(),":", | ||
astNode.Location_range_end_line.ToString(),":", | ||
astNode.Location_range_end_column.ToString() | ||
}; | ||
|
||
string res = string.Concat(properties); | ||
|
||
//WriteLine(res); | ||
return fnvHash(res); | ||
} | ||
|
||
private ulong fnvHash(string data_) | ||
{ | ||
ulong hash = 14695981039346656037; | ||
|
||
int len = data_.Length; | ||
for (int i = 0; i < len; ++i) | ||
{ | ||
hash ^= data_[i]; | ||
hash *= 1099511628211; | ||
} | ||
|
||
return hash; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper functions like these might be placed in a separate file / class.
{ | ||
private static readonly ILogger Logger = LoggingHelper.CreateLogger<CSharpQueryServer>(); | ||
private static readonly TConfiguration Configuration = new TConfiguration(); | ||
private static int port = 9091; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I rewrote this part to not clash with the cpp service, and to work with multiple parsed C# projects, port numbering should really be given some thought. The plugin should look for the next free port if the current one is taken.
@@ -0,0 +1,79 @@ | |||
// Licensed to the Apache Software Foundation(ASF) under one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should investigate whether this large pack of Thrift files is really needed as source in the plugin. It seems unncessary.
…irectories and a separate build path. Also corrected the parsing command to be able to run CodeCompass_parser from anywhere.
The official support for C# static analysis. Uses the Roslyn Semantic API to parse source code.
This plugin has been made by @Borisz42 as his TDK thesis. Thanks Dávid for your work!