Skip to content

Commit

Permalink
Chamrousse -> EclipseCon
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Bullen <[email protected]>
  • Loading branch information
Lucas Bullen committed Oct 16, 2017
1 parent bf1c614 commit 97b296a
Show file tree
Hide file tree
Showing 43 changed files with 245 additions and 196 deletions.
11 changes: 5 additions & 6 deletions Eclipse_LS_Plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Bundle-Name: Language Server Plugin
Bundle-SymbolicName: org.eclipsecon.languageserverplugin;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.contenttype;bundle-version="3.7.0",
org.eclipse.lsp4j,
Require-Bundle: org.eclipse.core.contenttype;bundle-version="3.6.0",
org.eclipse.lsp4j;bundle-version="0.3.0",
org.eclipse.lsp4j.jsonrpc;bundle-version="0.3.0",
org.eclipse.lsp4e;bundle-version="0.4.0",
org.eclipse.ui;bundle-version="3.109.100",
org.eclipse.core.runtime;bundle-version="3.14.0",
org.eclipse.ui.genericeditor;bundle-version="1.1.0",
org.eclipse.ui;bundle-version="3.109.0",
org.eclipse.core.runtime;bundle-version="3.13.0",
org.eclipse.ui.genericeditor;bundle-version="1.0.1",
org.eclipsecon.solution;bundle-version="1.0.0",
code.satyagraha.gfm.viewer.plugin;bundle-version="2.0.1",
org.eclipsecon.exercise1;bundle-version="1.0.0",
org.eclipsecon.exercise2;bundle-version="1.0.0",
org.eclipsecon.exercise3;bundle-version="1.0.0",
Expand Down
14 changes: 14 additions & 0 deletions Eclipse_LS_Plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Eclipse LSP4J Tutorial Plugin

> This Eclipse Plugin is used to view the language servers created in exercises 1-4.
To run:

- Open this project in Eclipse
- File > Open Projects from File System
- Set directory to Path/To/Eclipse_LS_Plugin
- Import `Eclipse_LS_Plugin` Project
- Open `target-platform.target` with the `Target Editor`
- In the Definition tab, **Set as Active Target Platform**
- Right click on `org.eclipsecon.languageserverplugin project`
- Run As > Eclipse Application
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.io.IOException;

import org.eclipsecon.exercise1.ChamrousseLanguageServer;
import org.eclipsecon.exercise1.EclipseConLanguageServer;

public class ConnectionProvider1 extends AbstractConnectionProvider {
private static final ChamrousseLanguageServer TRAVEL_LANGUAGE_SERVER = new ChamrousseLanguageServer();
private static final EclipseConLanguageServer TRAVEL_LANGUAGE_SERVER = new EclipseConLanguageServer();
public ConnectionProvider1() {
super(TRAVEL_LANGUAGE_SERVER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.io.IOException;

import org.eclipsecon.exercise2.ChamrousseLanguageServer;
import org.eclipsecon.exercise2.EclipseConLanguageServer;

public class ConnectionProvider2 extends AbstractConnectionProvider {
private static final ChamrousseLanguageServer TRAVEL_LANGUAGE_SERVER = new ChamrousseLanguageServer();
private static final EclipseConLanguageServer TRAVEL_LANGUAGE_SERVER = new EclipseConLanguageServer();
public ConnectionProvider2() {
super(TRAVEL_LANGUAGE_SERVER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.io.IOException;

import org.eclipsecon.exercise3.ChamrousseLanguageServer;
import org.eclipsecon.exercise3.EclipseConLanguageServer;

public class ConnectionProvider3 extends AbstractConnectionProvider {
private static final ChamrousseLanguageServer TRAVEL_LANGUAGE_SERVER = new ChamrousseLanguageServer();
private static final EclipseConLanguageServer TRAVEL_LANGUAGE_SERVER = new EclipseConLanguageServer();
public ConnectionProvider3() {
super(TRAVEL_LANGUAGE_SERVER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.io.IOException;

import org.eclipsecon.exercise4.ChamrousseLanguageServer;
import org.eclipsecon.exercise4.EclipseConLanguageServer;

public class ConnectionProvider4 extends AbstractConnectionProvider {
private static final ChamrousseLanguageServer TRAVEL_LANGUAGE_SERVER = new ChamrousseLanguageServer();
private static final EclipseConLanguageServer TRAVEL_LANGUAGE_SERVER = new EclipseConLanguageServer();
public ConnectionProvider4() {
super(TRAVEL_LANGUAGE_SERVER);
}
Expand Down
25 changes: 25 additions & 0 deletions Eclipse_LS_Plugin/target-platform.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="aCute" sequenceNumber="6">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.lsp4e" version="0.0.0"/>
<repository location="http://download.eclipse.org/lsp4e/snapshots/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
<repository location="http://download.eclipse.org/modeling/tmf/xtext/updates/composite/milestones/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.lsp4j" version="0.0.0"/>
<unit id="org.eclipse.lsp4j.jsonrpc" version="0.0.0"/>
<repository location="http://services.typefox.io/open-source/jenkins/job/lsp4j/job/master/lastSuccessfulBuild/artifact/build/p2-repository/"/>
</location>
<location includeAllPlatforms="true" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.ui.genericeditor" version="0.0.0"/>
<unit id="org.eclipse.ui" version="0.0.0"/>
<unit id="org.eclipse.core.runtime" version="0.0.0"/>
<unit id="org.eclipse.core.contenttype" version="0.0.0"/>
<repository location="http://download.eclipse.org/eclipse/updates/4.7"/>
</location>
</locations>
</target>
8 changes: 4 additions & 4 deletions Exercises/1/1-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In this exercise, we will complete the Exercise1 Project with the required conne
## MANIFEST.MF

Start by opening the [MANIFEST.MF](TODO) file. Here we will add the dependencies of the project and the exported package; which will be the LS for our plug-ins to consume.
Start by opening the [MANIFEST.MF](/Exercises/1/META-INF/MANIFEST.MF) file. Here we will add the dependencies of the project and the exported package; which will be the LS for our plug-ins to consume.

### Dependencies

Expand All @@ -32,13 +32,13 @@ To allow other packages to use our Language Server, we must export the package.

## Main.java

Within [Main.java](TODO), we will be creating an instance of the server, launching it with the program's standard input and output to receive and send messages, set the server's client, and begin waiting for messages.
Within [Main.java](/Exercises/1/src/org/eclipsecon/exercise1/Main.java), we will be creating an instance of the server, launching it with the program's standard input and output to receive and send messages, set the server's client, and begin waiting for messages.

In the `startServer` function, do the following:

Create an instance of the Language Server, which implements `lsp4j.services.LanguageServer`:
```
ChamrousseLanguageServer server = new ChamrousseLanguageServer();
EclipseConLanguageServer server = new EclipseConLanguageServer();
```

Use the `Launcher` to start the server with the program's standard input and output:
Expand Down Expand Up @@ -71,4 +71,4 @@ Now that the EclipseCon 2017 Language Server has been setup (We will go over how

### Congratulations! You have set up a Language Server in Java!

[To next lesson](TODO)
[To next lesson](/Exercises/2/2-README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Map.Entry;
import java.util.Optional;

public class ChamrousseDocumentModel {
public class EclipseConDocumentModel {

public static abstract class DocumentLine {
final int line;
Expand Down Expand Up @@ -51,7 +51,7 @@ public VariableDefinition(int lineNumber, int charOffset, String text, String va
private final List<Route> routes = new ArrayList<>();
private final Map<String, VariableDefinition> variables = new HashMap<>();

public ChamrousseDocumentModel(String text) {
public EclipseConDocumentModel(String text) {
try (
Reader r = new StringReader(text);
BufferedReader reader = new BufferedReader(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import org.eclipse.lsp4j.services.TextDocumentService;
import org.eclipse.lsp4j.services.WorkspaceService;

public class ChamrousseLanguageServer implements LanguageServer {
public class EclipseConLanguageServer implements LanguageServer {

private TextDocumentService textService;
private WorkspaceService workspaceService;
LanguageClient client;

public ChamrousseLanguageServer() {
textService = new ChamrousseTextDocumentService(this);
workspaceService = new ChamrousseWorkspaceService();
public EclipseConLanguageServer() {
textService = new EclipseConTextDocumentService(this);
workspaceService = new EclipseConWorkspaceService();
}

public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
import java.util.Set;
import java.util.stream.Collectors;

public class ChamrousseMap {
public class EclipseConMap {

public static final ChamrousseMap INSTANCE = new ChamrousseMap();
public static final EclipseConMap INSTANCE = new EclipseConMap();

final Properties props = new Properties();
final Set<String> all;
final Map<String, Collection<String>> startsFrom;
final Map<String, Collection<String>> arrivesTo;
final Map<String, String> type;

private ChamrousseMap() {
InputStream propertiesStream = ChamrousseMap.class.getResourceAsStream("/" + ChamrousseMap.class.getPackage().getName().replace(".", "/") + "/EclipseConSessions.properties");
private EclipseConMap() {
InputStream propertiesStream = EclipseConMap.class.getResourceAsStream("/" + EclipseConMap.class.getPackage().getName().replace(".", "/") + "/chamrousseMap.properties");
try {
props.load(propertiesStream);
propertiesStream.close();
Expand All @@ -36,7 +36,7 @@ private ChamrousseMap() {
.map(key -> ((String)key).split("\\.")[0])
.collect(Collectors.toSet());
this.startsFrom = props.entrySet().stream()
.filter(entry -> ((String)entry.getKey()).endsWith(".isAfter"))
.filter(entry -> ((String)entry.getKey()).endsWith(".startsFrom"))
.collect(Collectors.toMap(
entry -> ((String)entry.getKey()).split("\\.")[0],
entry -> Arrays.asList(((String)entry.getValue()).split(","))));
Expand All @@ -52,7 +52,7 @@ private ChamrousseMap() {
});
});
this.type = props.entrySet().stream()
.filter(entry -> ((String)entry.getKey()).endsWith(".difficulty"))
.filter(entry -> ((String)entry.getKey()).endsWith(".type"))
.collect(Collectors.toMap(
entry -> ((String)entry.getKey()).split("\\.")[0],
entry -> (String)entry.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.TextDocumentService;
import org.eclipsecon.exercise1.ChamrousseMap;
import org.eclipsecon.exercise1.ChamrousseDocumentModel.Route;
import org.eclipsecon.exercise1.ChamrousseDocumentModel.VariableDefinition;
import org.eclipsecon.exercise1.EclipseConMap;
import org.eclipsecon.exercise1.EclipseConDocumentModel.Route;
import org.eclipsecon.exercise1.EclipseConDocumentModel.VariableDefinition;

public class ChamrousseTextDocumentService implements TextDocumentService {
public class EclipseConTextDocumentService implements TextDocumentService {

private final Map<String, ChamrousseDocumentModel> docs = Collections.synchronizedMap(new HashMap<>());
private final ChamrousseLanguageServer chamrousseLanguageServer;
private final Map<String, EclipseConDocumentModel> docs = Collections.synchronizedMap(new HashMap<>());
private final EclipseConLanguageServer eclipseConLanguageServer;

public ChamrousseTextDocumentService(ChamrousseLanguageServer chamrousseLanguageServer) {
this.chamrousseLanguageServer = chamrousseLanguageServer;
public EclipseConTextDocumentService(EclipseConLanguageServer eclipseConLanguageServer) {
this.eclipseConLanguageServer = eclipseConLanguageServer;
}

@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
TextDocumentPositionParams position) {
return CompletableFuture.supplyAsync(() -> Either.forLeft(ChamrousseMap.INSTANCE.all.stream()
return CompletableFuture.supplyAsync(() -> Either.forLeft(EclipseConMap.INSTANCE.all.stream()
.map(word -> {
CompletionItem item = new CompletionItem();
item.setLabel(word);
Expand All @@ -74,12 +74,12 @@ public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem un
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
return CompletableFuture.supplyAsync(() -> {
ChamrousseDocumentModel doc = docs.get(position.getTextDocument().getUri());
EclipseConDocumentModel doc = docs.get(position.getTextDocument().getUri());
Hover res = new Hover();
res.setContents(doc.getResolvedRoutes().stream()
.filter(route -> route.line == position.getPosition().getLine())
.map(route -> route.name)
.map(ChamrousseMap.INSTANCE.type::get)
.map(EclipseConMap.INSTANCE.type::get)
.map(this::getHoverContent)
.collect(Collectors.toList()));
return res;
Expand All @@ -98,7 +98,7 @@ public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams
@Override
public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams position) {
return CompletableFuture.supplyAsync(() -> {
ChamrousseDocumentModel doc = docs.get(position.getTextDocument().getUri());
EclipseConDocumentModel doc = docs.get(position.getTextDocument().getUri());
String variable = doc.getVariable(position.getPosition().getLine(), position.getPosition().getCharacter());
if (variable != null) {
int variableLine = doc.getDefintionLine(variable);
Expand All @@ -118,7 +118,7 @@ public CompletableFuture<List<? extends Location>> definition(TextDocumentPositi
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
return CompletableFuture.supplyAsync(() -> {
ChamrousseDocumentModel doc = docs.get(params.getTextDocument().getUri());
EclipseConDocumentModel doc = docs.get(params.getTextDocument().getUri());
String variable = doc.getVariable(params.getPosition().getLine(), params.getPosition().getCharacter());
if (variable != null) {
return doc.getResolvedRoutes().stream()
Expand Down Expand Up @@ -205,42 +205,42 @@ public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {

@Override
public void didOpen(DidOpenTextDocumentParams params) {
ChamrousseDocumentModel model = new ChamrousseDocumentModel(params.getTextDocument().getText());
EclipseConDocumentModel model = new EclipseConDocumentModel(params.getTextDocument().getText());
this.docs.put(params.getTextDocument().getUri(),
model);
CompletableFuture.runAsync(() ->
chamrousseLanguageServer.client.publishDiagnostics(
eclipseConLanguageServer.client.publishDiagnostics(
new PublishDiagnosticsParams(params.getTextDocument().getUri(), validate(model))
)
);
}

@Override
public void didChange(DidChangeTextDocumentParams params) {
ChamrousseDocumentModel model = new ChamrousseDocumentModel(params.getContentChanges().get(0).getText());
EclipseConDocumentModel model = new EclipseConDocumentModel(params.getContentChanges().get(0).getText());
this.docs.put(params.getTextDocument().getUri(),
model);
// send notification
CompletableFuture.runAsync(() ->
chamrousseLanguageServer.client.publishDiagnostics(
eclipseConLanguageServer.client.publishDiagnostics(
new PublishDiagnosticsParams(params.getTextDocument().getUri(), validate(model))
)
);
}

private List<Diagnostic> validate(ChamrousseDocumentModel model) {
private List<Diagnostic> validate(EclipseConDocumentModel model) {
List<Diagnostic> res = new ArrayList<>();
Route previousRoute = null;
for (Route route : model.getResolvedRoutes()) {
if (!ChamrousseMap.INSTANCE.all.contains(route.name)) {
if (!EclipseConMap.INSTANCE.all.contains(route.name)) {
Diagnostic diagnostic = new Diagnostic();
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("This is not a Session");
diagnostic.setRange(new Range(
new Position(route.line, route.charOffset),
new Position(route.line, route.charOffset + route.text.length())));
res.add(diagnostic);
} else if (previousRoute != null && !ChamrousseMap.INSTANCE.startsFrom(route.name, previousRoute.name)) {
} else if (previousRoute != null && !EclipseConMap.INSTANCE.startsFrom(route.name, previousRoute.name)) {
Diagnostic diagnostic = new Diagnostic();
diagnostic.setSeverity(DiagnosticSeverity.Warning);
diagnostic.setMessage("'" + route.name + "' does not follow '" + previousRoute.name + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;

public class ChamrousseWorkspaceService implements WorkspaceService {
public class EclipseConWorkspaceService implements WorkspaceService {

@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
Expand Down
8 changes: 4 additions & 4 deletions Exercises/2/2-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Add the completion provider capability to the initialize result so that the clie
res.getCapabilities().setCompletionProvider(new CompletionOptions());
```

## ChamrousseTextDocumentService.java
## EclipseConTextDocumentService.java

In the [ChamrousseLanguageServer.java](TODO)'s constructor, you will see an instance of [ChamrousseTextDocumentService.java](TODO) being created. This class contains all the functions that accept requests from the client and form the responses.
In [EclipseConLanguageServer](/Exercises/2/src/org/eclipsecon/exercise2/EclipseConLanguageServer.java)'s constructor, you will see an instance of [EclipseConTextDocumentService](/Exercises/2/src/org/eclipsecon/exercise2/EclipseConTextDocumentService.java) being created. This class contains all the functions that accept requests from the client and form the responses.

We will be working in the `completion` function. This function takes the position that the request for completion was made within the target document, and returns a list of `CompletionItem`s or a `CompletionList`.

The code below takes a stream of all the sessions at EclipseCon, creates `CompletionItem`s for each, then collects them into a list to be returned. This code is added in replacement of the current `return null;` line in the `completion` function in the solution LS:
```
return CompletableFuture.supplyAsync(() -> Either.forLeft(ChamrousseMap.INSTANCE.all.stream()
return CompletableFuture.supplyAsync(() -> Either.forLeft(EclipseConMap.INSTANCE.all.stream()
.map(word -> {
CompletionItem item = new CompletionItem();
item.setLabel(word);
Expand Down Expand Up @@ -54,4 +54,4 @@ With our new made completion assist endpoint, let's see it in action:

### Congratulations! You have created an endpoint for a Language Server in Java!

[To next lesson](TODO)
[To next lesson](/Exercises/3/3-README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Map.Entry;
import java.util.Optional;

public class ChamrousseDocumentModel {
public class EclipseConDocumentModel {

public static abstract class DocumentLine {
final int line;
Expand Down Expand Up @@ -51,7 +51,7 @@ public VariableDefinition(int lineNumber, int charOffset, String text, String va
private final List<Route> routes = new ArrayList<>();
private final Map<String, VariableDefinition> variables = new HashMap<>();

public ChamrousseDocumentModel(String text) {
public EclipseConDocumentModel(String text) {
try (
Reader r = new StringReader(text);
BufferedReader reader = new BufferedReader(r);
Expand Down
Loading

0 comments on commit 97b296a

Please sign in to comment.