Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions language-server/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# CD4Analysis language
This project contains the language server for CD4Analysis.
# CD4Analysis and CD4Code language servers
This project contains language servers for CD4Analysis and CD4Code.

It can be build with Gradle:
- `gradle build`, the resulting jar can be found in build/lib
Build the executable servers with `gradle :language-server:packCD4AnalysisLanguageServer`
and `gradle :language-server:packCD4CodeLanguageServer`. The JARs are written to `target/libs`.

References for the CD4Analysis:
- https://github.com/MontiCore/cd4analysis
- https://mbse.se-rwth.de/book1/index.php?c=chapter2

You can customize the resulting LSP via the TOP mechanism.

# Running the server
`gradle runCD4AnalysisVscodePluginAttached`
# Running the servers
Use `gradle :language-server:runCD4AnalysisVscodePluginAttached -PbuildVscodePlugin=true`
or `gradle :language-server:runCD4CodeVscodePluginAttached -PbuildVscodePlugin=true` to run a
server with its VS Code plugin attached.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cd4code._lsp.features.completion;

import de.mclsg.lsp.CommonLanguageServer;
import de.mclsg.lsp.ISymbolUsageResolutionProvider;
import de.mclsg.lsp.document_management.DocumentManager;
import de.monticore.cd4analysis._lsp.features.completion.strategy.CD4AnalysisAssociationCardinalityCompletionStrategy;
import de.monticore.cd4analysis._lsp.features.completion.strategy.CD4AnalysisAssociationCompletionStrategy;
import de.monticore.cd4analysis._lsp.features.completion.strategy.CD4AnalysisAssociationNavigationCompletionStrategy;
import de.monticore.cd4code._lsp.language_access.CD4CodeLanguageAccess;

public class CD4CodeCompletionProvider extends CD4CodeCompletionProviderTOP {

public CD4CodeCompletionProvider(CommonLanguageServer languageServer,
DocumentManager documentManager, CD4CodeLanguageAccess languageAccess,
ISymbolUsageResolutionProvider symbolUsageResolutionProvider) {
super(languageServer, documentManager, languageAccess, symbolUsageResolutionProvider);

completionStrategyManager.registerCompletionStrategy(
new CD4AnalysisAssociationCompletionStrategy(symbolUsageResolutionProvider,
documentManager));
completionStrategyManager.registerCompletionStrategy(
new CD4AnalysisAssociationCardinalityCompletionStrategy(symbolUsageResolutionProvider,
documentManager));
completionStrategyManager.registerCompletionStrategy(
new CD4AnalysisAssociationNavigationCompletionStrategy(symbolUsageResolutionProvider,
documentManager));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cd4code._lsp.features.syntax_highlighting;

import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightAttributeTypeRule;
import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightClassNameRule;
import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightEnumMemberNameRule;
import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightEnumNameRule;
import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightInterfaceNameRule;
import de.monticore.cd4analysis._lsp.features.syntax_highlighting.rule.HighlightPackageNameRule;
import de.monticore.cd4code._lsp.language_access.CD4CodeLanguageAccess;

public class CD4CodeLexerProvider extends CD4CodeLexerProviderTOP {

public CD4CodeLexerProvider(CD4CodeLanguageAccess languageAccess) {
super(languageAccess);
addClassificationRule(new HighlightClassNameRule());
addClassificationRule(new HighlightInterfaceNameRule());
addClassificationRule(new HighlightAttributeTypeRule());
addClassificationRule(new HighlightPackageNameRule());
addClassificationRule(new HighlightEnumNameRule());
addClassificationRule(new HighlightEnumMemberNameRule());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.cd4code._lsp;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import de.mclsg.lsp.document_management.DocumentManager;
import de.mclsg.lsp.features.sematic_tokens.impl.SemanticTokenTypesWrapper;
import de.mclsg.lsp.modelpath.multiproject.ProjectLayoutBuilder;
import de.mclsg.lsp.util.AsyncUtilWithSyncExec;
import de.monticore.cd4analysis._lsp.MockLanguageClient;
import de.monticore.cd4code._lsp.features.syntax_highlighting.CD4CodeLexerProvider;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.lsp4j.CodeLensParams;
import org.eclipse.lsp4j.InitializedParams;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.junit.jupiter.api.Test;

class CD4CodeLanguageServerTest {

@Test
void indexesCodeModelAndReusesAnalysisFeatures() throws IOException {
AsyncUtilWithSyncExec.init();
Path modelDirectory = Paths.get("src", "test", "resources", "cd4code");
Path model = modelDirectory.resolve("SharedFeatures.cd");
DocumentManager documentManager = new DocumentManager();
CD4CodeLanguageServer server = new CD4CodeLanguageServerBuilder().layout(
new ProjectLayoutBuilder().projectpath(modelDirectory).build()).documentManager(
documentManager).build();
server.connect(new MockLanguageClient());
server.initialized(new InitializedParams());

String uri = model.toUri().toString();
assertTrue(documentManager.getDocumentInformation(uri).isPresent());
assertNotNull(documentManager.getDocumentInformation(uri).orElseThrow().ast);

var lenses = server.getTextDocumentService().codeLens(new CodeLensParams(
new TextDocumentIdentifier(uri))).join();
assertEquals(2, lenses.size());
assertTrue(lenses.stream().allMatch(lens -> lens.getCommand().getTitle().equals(
"Part of 1 Association")));

var tokens = new CD4CodeLexerProvider(server.getLanguageAccess()).getTokensForInput(Files
.readString(model));
assertFalse(tokens.isEmpty());
assertTrue(tokens.stream().anyMatch(token -> token.getName().equals(
SemanticTokenTypesWrapper.Class.value)));
}

}
7 changes: 7 additions & 0 deletions language-server/src/test/resources/cd4code/SharedFeatures.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
classdiagram SharedFeatures {
class Source {
public void run();
}
class Target;
association Source -> Target;
}
Loading