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

LSP for CodeCompass #599

Merged
merged 28 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
134b3ad
Add LSP support
Kalfou Jan 14, 2023
16cc347
Add position data to function call diagram as tooltip
Kalfou Feb 19, 2023
6c169eb
Add position data to all diagrams as tooltip
Kalfou Feb 25, 2023
7306e76
Add go to implementation to lsp
Kalfou Mar 12, 2023
b5bb0c5
Move the lsp from services to plugins
Kalfou Mar 19, 2023
5dadead
Fix thrift to lsp conversion for graphs
Kalfou Mar 19, 2023
538e627
Renaming lsp service to cpp lsp service
Kalfou Mar 22, 2023
b1269b1
Remove thrift from lsp plugin
Kalfou Apr 2, 2023
d05a6ec
Remove even more thrift from lsp
Kalfou Apr 2, 2023
5525933
Create base class for lsp service
Kalfou Apr 8, 2023
9e7b103
Add declaration support
Kalfou Apr 24, 2023
f2d2c9a
Refactoring and code convention fixes
Kalfou Apr 29, 2023
f68feca
Add location request features
Kalfou May 1, 2023
45045e1
Rename and separate diagram methods
Kalfou May 1, 2023
cd67f02
Fix file diagrams for directories
Kalfou May 2, 2023
67269b6
Separate diagram graph creation from svg creation
Kalfou May 2, 2023
a4c9268
Replace id with location in svg diagram nodes
Kalfou May 3, 2023
d3973b2
Fix diagram types for position dependant diagrams
Kalfou May 3, 2023
afb1b53
Add signature, remove unused types
Kalfou May 11, 2023
11415b5
Remove unneeded registerLspPluginSimple helper function
Kalfou May 13, 2023
d8ed4fe
Merge remote-tracking branch 'upstream/master'
Kalfou May 16, 2023
5b14e75
Cleanup and convention checking
Kalfou May 15, 2023
618b3ab
Use strings instead of CompletionItems for DiagramTypes
Kalfou May 16, 2023
f1c9084
More cleanup and code convention fixes
Kalfou May 22, 2023
53b32a3
Adding const specifier and convention fixes
Kalfou May 28, 2023
77884d0
Merge remote-tracking branch 'origin/master' into lsp_reanimated
Kalfou Jun 10, 2023
3a391fa
Add LSP details to README
Kalfou Jun 25, 2023
2b29feb
Convention fixes
Kalfou Sep 29, 2023
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
11 changes: 10 additions & 1 deletion plugins/cpp/service/include/service/cppservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <model/cpprelation-odb.hxx>

#include <util/odbtransaction.h>
#include "util/graph.h"
intjftw marked this conversation as resolved.
Show resolved Hide resolved
#include <webserver/servercontext.h>

namespace cc
Expand Down Expand Up @@ -69,6 +70,10 @@ class CppServiceHandler : virtual public LanguageServiceIf
const core::AstNodeId& astNodeId_,
const std::int32_t diagramId_) override;

util::Graph returnDiagram(
const core::AstNodeId& astNodeId_,
const std::int32_t diagramId_);

void getDiagramLegend(
std::string& return_,
const std::int32_t diagramId_) override;
Expand All @@ -82,6 +87,10 @@ class CppServiceHandler : virtual public LanguageServiceIf
const core::FileId& fileId_,
const int32_t diagramId_) override;

util::Graph returnFileDiagram(
const core::FileId& fileId_,
const int32_t diagramId_);

void getFileDiagramLegend(
std::string& return_,
const std::int32_t diagramId_) override;
Expand Down Expand Up @@ -131,7 +140,6 @@ class CppServiceHandler : virtual public LanguageServiceIf
std::vector<SyntaxHighlight>& return_,
const core::FileRange& range_) override;

private:
enum ReferenceType
{
DEFINITION, /*!< By this option the definition(s) of the AST node can be
Expand Down Expand Up @@ -258,6 +266,7 @@ class CppServiceHandler : virtual public LanguageServiceIf
of a module. */
};
intjftw marked this conversation as resolved.
Show resolved Hide resolved

private:
static bool compareByPosition(
const model::CppAstNode& lhs,
const model::CppAstNode& rhs);
Expand Down
64 changes: 42 additions & 22 deletions plugins/cpp/service/src/cppservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void CppServiceHandler::getProperties(
{
VarResult variables = _db->query<model::CppVariable>(
VarQuery::entityHash == node.entityHash);

if (!variables.empty())
{
model::CppVariable variable = *variables.begin();
Expand All @@ -289,7 +289,7 @@ void CppServiceHandler::getProperties(
return_["Type"] = variable.qualifiedType;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying properties "
"of C++ variable: "
<< toShortDiagnosticString(node);
Expand All @@ -312,7 +312,7 @@ void CppServiceHandler::getProperties(
return_["Signature"] = function.name;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying properties "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand All @@ -338,7 +338,7 @@ void CppServiceHandler::getProperties(
return_["Qualified name"] = type.qualifiedName;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying properties "
"of C++ type: "
<< toShortDiagnosticString(node);
Expand All @@ -359,11 +359,11 @@ void CppServiceHandler::getProperties(
return_["Qualified name"] = type.qualifiedName;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying properties "
"of C++ typedef: "
<< toShortDiagnosticString(node);

break;
}

Expand All @@ -381,7 +381,7 @@ void CppServiceHandler::getProperties(
return_["Value"] = std::to_string(enumConst.value);
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying properties "
"of C++ enum constant: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -502,7 +502,7 @@ std::int32_t CppServiceHandler::getReferenceCount(
TypeQuery::entityHash == function.typeHash).count;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when counting return types "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -538,7 +538,7 @@ std::int32_t CppServiceHandler::getReferenceCount(
TypeQuery::entityHash == variable.typeHash).count;
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when counting types "
"of C++ variable: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -788,7 +788,7 @@ void CppServiceHandler::getReferences(
std::to_string(var.load()->astNodeId)));
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying parameters "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand All @@ -811,7 +811,7 @@ void CppServiceHandler::getReferences(
std::to_string(var.load()->astNodeId)));
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying local variables "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -840,7 +840,7 @@ void CppServiceHandler::getReferences(
}
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying return type "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -904,7 +904,7 @@ void CppServiceHandler::getReferences(
}
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying type "
"of C++ variable: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void CppServiceHandler::getReferences(
nodes = std::vector<model::CppAstNode>(result.begin(), result.end());
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying underlying type "
"of C++ typedef: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ void CppServiceHandler::getReferences(
});
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying enum constants "
"of C++ enum: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -1253,7 +1253,9 @@ void CppServiceHandler::getSyntaxHighlight(

// Regular expression to find element position
const std::regex specialChars { R"([-[\]{}()*+?.,\^$|#\s])" };
std::string sanitizedAstValue = std::regex_replace(node.astValue, specialChars, R"(\$&)");
std::string sanitizedAstValue = std::regex_replace(node.astValue,
specialChars,
R"(\$&)");
std::string reg = "\\b" + sanitizedAstValue + "\\b";

for (std::size_t i = node.location.range.start.line - 1;
Expand Down Expand Up @@ -1291,6 +1293,16 @@ void CppServiceHandler::getDiagram(
std::string& return_,
const core::AstNodeId& astNodeId_,
const std::int32_t diagramId_)
{
util::Graph graph = returnDiagram(astNodeId_, diagramId_);

if (graph.nodeCount() != 0)
return_ = graph.output(util::Graph::SVG);
}

util::Graph CppServiceHandler::returnDiagram(
const core::AstNodeId& astNodeId_,
const std::int32_t diagramId_)
{
Diagram diagram(_db, _datadir, _context);
util::Graph graph;
Expand All @@ -1310,8 +1322,7 @@ void CppServiceHandler::getDiagram(
break;
}

if (graph.nodeCount() != 0)
return_ = graph.output(util::Graph::SVG);
return graph;
}

void CppServiceHandler::getDiagramLegend(
Expand Down Expand Up @@ -1366,6 +1377,16 @@ void CppServiceHandler::getFileDiagram(
std::string& return_,
const core::FileId& fileId_,
const int32_t diagramId_)
{
util::Graph graph = returnFileDiagram(fileId_, diagramId_);

if (graph.nodeCount() != 0)
return_ = graph.output(util::Graph::SVG);
}

util::Graph CppServiceHandler::returnFileDiagram(
const core::FileId& fileId_,
const int32_t diagramId_)
{
FileDiagram diagram(_db, _datadir, _context);
util::Graph graph;
Expand Down Expand Up @@ -1398,8 +1419,7 @@ void CppServiceHandler::getFileDiagram(
break;
}

if (graph.nodeCount() != 0)
return_ = graph.output(util::Graph::SVG);
return graph;
}

void CppServiceHandler::getFileDiagramLegend(
Expand Down Expand Up @@ -1649,7 +1669,7 @@ CppServiceHandler::getTags(const std::vector<model::CppAstNode>& nodes_)
tags[node.id].push_back(model::tagToString(tag));
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying tags "
"of C++ function: "
<< toShortDiagnosticString(node);
Expand Down Expand Up @@ -1684,7 +1704,7 @@ CppServiceHandler::getTags(const std::vector<model::CppAstNode>& nodes_)
tags[node.id].push_back(model::tagToString(tag));
}
else
LOG(warning)
LOG(warning)
<< "Unexpected empty result when querying tags "
"of C++ variable: "
<< toShortDiagnosticString(node);
Expand Down
2 changes: 2 additions & 0 deletions plugins/cpp/service/src/diagram.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <sstream>
intjftw marked this conversation as resolved.
Show resolved Hide resolved

#include <model/cppvariable.h>
#include <model/cppvariable-odb.hxx>
#include <model/cpprecord.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/cpp/service/src/filediagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void FileDiagram::getIncludeDependencyDiagram(
util::bfsBuild(graph_, currentNode,std::bind(&FileDiagram::getRevUsages,
this, std::placeholders::_1, std::placeholders::_2),
{}, revUsagesEdgeDecoration, 3);

util::bfsBuild(graph_, currentNode, std::bind(&FileDiagram::getProvides,
this, std::placeholders::_1, std::placeholders::_2),
{}, usagesEdgeDecoration, 3);
Expand Down
11 changes: 11 additions & 0 deletions plugins/cpp_lsp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The C++ lsp plugin depends on the C++ plugin's components to be built.

if ("${cpp_PLUGIN_DIR}" STREQUAL "")
# Use SEND_ERROR here so a build file is not generated at the end.
# CodeCompass might use a lot of plugins and produce a lengthy build, so
# a warning at configure time would easily be missed by the users.
message(SEND_ERROR
"C++ LSP plugin found without C++ plugin in the plugins directory.")
endif()

add_subdirectory(service)
24 changes: 24 additions & 0 deletions plugins/cpp_lsp/service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include_directories(
include
${PROJECT_SOURCE_DIR}/model/include
${PROJECT_BINARY_DIR}/service/language/gen-cpp
${PROJECT_BINARY_DIR}/service/project/gen-cpp
${PROJECT_SOURCE_DIR}/service/project/include
${PROJECT_SOURCE_DIR}/plugins/cpp/service/include
${PROJECT_SOURCE_DIR}/plugins/cpp/model/include
${CMAKE_BINARY_DIR}/model/include
${CMAKE_BINARY_DIR}/plugins/cpp/model/include
${PROJECT_SOURCE_DIR}/util/include
${PROJECT_SOURCE_DIR}/webserver/include
${PROJECT_SOURCE_DIR}/service/lsp/include)

add_library(cpplspservice SHARED
src/cpplspservice.cpp
src/plugin.cpp)

target_link_libraries(cpplspservice
cppservice
lspservice
util)

install(TARGETS cpplspservice DESTINATION ${INSTALL_SERVICE_DIR})
Loading