Skip to content

Commit

Permalink
LSP for CodeCompass (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalfou authored Feb 4, 2024
1 parent 476c356 commit d761423
Show file tree
Hide file tree
Showing 21 changed files with 2,477 additions and 30 deletions.
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 @@ -292,4 +292,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

0 comments on commit d761423

Please sign in to comment.