Skip to content

LSP for CodeCompass #599

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

Merged
merged 28 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
227 changes: 227 additions & 0 deletions doc/lsp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# Supported LSP Requests

## Standard

- [textDocument/declaration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_declaration)
- [textDocument/definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition)
- [textDocument/implementation](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_implementation)
- [textDocument/references](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_references)

## CodeCompass Specific Methods

### textDocument/thisCalls

Returns the locations of function calls inside the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/callsOfThis

Returns the locations where the function at the selected position is called.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/callee

Returns the locations of the definitions of the functions called by the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/caller

Returns the locations of the definitions of the functions that call the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/virtualCall

Returns the locations where the function at the selected position may be virtually called.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/functionPointerCall

Returns the locations where the function at the selected position is called through a function pointer.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/parameters

Returns the locations of the parameters of the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/localVariables

Returns the locations of the local variables of the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/overridden

Returns the locations of the functions the function at the selected position overrides.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/overriders

Returns the locations of the functions that override the function at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/read

Returns the locations the variable at the selected position is read.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/write

Returns the locations where the variable at the selected position is written.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/signature

Returns the name of the AST node of the entity at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* string | null

### textDocument/alias

Returns the locations of the type aliases of the type at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/implements

Returns the locations of the types that inherit from the type at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/dataMember

Returns the locations of the data members of the class at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/methods

Returns the locations of the methods of the class at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/friends

Returns the locations of the friends of the class at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/underlyingType

Returns the location of the underlying type of the type alias at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/enumConstants

Returns the locations of the constants of the enumeration at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/expansion

Returns the locations of the expansions of the macro at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/undefinition

Returns the locations of the undefinitions of the macro at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location) | [Location](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location)[] | null

### textDocument/diagramTypes

Returns the names of diagram types available at the selected position.

*Params:* [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams)

*Response:* string[] | null

### textDocument/diagram

Returns a diagram of the selected type based on the selected position in SVG format.

*Params:* diagramParams

*Response:* string | null

### directory/diagram

Returns a diagram of the selected type based on the selected module in SVG format.

*Params:* diagramParams

*Response:* string | null

## CodeCompass Specific Types

### DiagramParams

Parameters needed for diagram requests.
Directory based diagrams do not need the position parameter.
The diagramType should contain a valid diagram type name for the given language plugin.
The `textDocument/diagramTypes` method can be used to access these for position dependant diagrams.

```javascript
interface DiagramParams {
textDocument: TextDocumentIdentifier;
position?: Position;
diagramType: string;
}
```
15 changes: 14 additions & 1 deletion doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,17 @@ The server will be available in a browser on
In both the parser and the webserver it is possible to write the logs to a given directory.
This feature can be enabled by passing the `--logtarget` command line option with the full
path to the directory to be used for storing the log files.
If this argument is not specified, the logs will be written to the terminal only.
If this argument is not specified, the logs will be written to the terminal only.

### Language Server Protocol support

The CodeCompass_webserver is not a fully fledged LSP server on its own,
but it does support some standard and non-standard LSP requests for C and C++ projects.
The full list can be found here: [Supported LSP Requests](lsp.md)

To access this feature, requests must be sent to the following address:
`http://<domain>:<port>/<project_name>/CppLspService`

e.g.: [`http://localhost:6251/MyProject/CppLspService`](http://localhost:6251/MyProject/CppLspService)

The project name should match the name of the project used by the CodeCompass_parser.
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>
#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. */
};

private:
static bool compareByPosition(
const model::CppAstNode& lhs,
const model::CppAstNode& rhs);
Expand Down
Loading