Compare commits
8 Commits
0.0.2
...
637478b1c3
Author | SHA1 | Date | |
---|---|---|---|
|
637478b1c3 | ||
|
24c5cd823f | ||
|
26eedc5b32 | ||
|
c21f09496e | ||
|
39ae1d66bc | ||
|
6ee0a74b22 | ||
|
ca6fa89e3f | ||
|
8cde997c15 |
@@ -9,3 +9,7 @@ vsc-extension-quickstart.md
|
|||||||
**/*.map
|
**/*.map
|
||||||
**/*.ts
|
**/*.ts
|
||||||
**/.vscode-test.*
|
**/.vscode-test.*
|
||||||
|
|
||||||
|
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||||
|
|
||||||
|
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||||
|
Binary file not shown.
@@ -1,71 +1,3 @@
|
|||||||
# lspclient README
|
# lspclient README
|
||||||
|
|
||||||
This is the README for your extension "lspclient". After writing up a brief description, we recommend including the following sections.
|
This is the README for the Java-TX LSP Client.
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
|
|
||||||
|
|
||||||
For example if there is an image subfolder under your extension project workspace:
|
|
||||||
|
|
||||||
\!\[feature X\]\(images/feature-x.png\)
|
|
||||||
|
|
||||||
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
|
|
||||||
|
|
||||||
## Extension Settings
|
|
||||||
|
|
||||||
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
This extension contributes the following settings:
|
|
||||||
|
|
||||||
* `myExtension.enable`: Enable/disable this extension.
|
|
||||||
* `myExtension.thing`: Set to `blah` to do something.
|
|
||||||
|
|
||||||
## Known Issues
|
|
||||||
|
|
||||||
Calling out known issues can help limit users opening duplicate issues against your extension.
|
|
||||||
|
|
||||||
## Release Notes
|
|
||||||
|
|
||||||
Users appreciate release notes as you update your extension.
|
|
||||||
|
|
||||||
### 1.0.0
|
|
||||||
|
|
||||||
Initial release of ...
|
|
||||||
|
|
||||||
### 1.0.1
|
|
||||||
|
|
||||||
Fixed issue #.
|
|
||||||
|
|
||||||
### 1.1.0
|
|
||||||
|
|
||||||
Added features X, Y, and Z.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Following extension guidelines
|
|
||||||
|
|
||||||
Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.
|
|
||||||
|
|
||||||
* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
|
|
||||||
|
|
||||||
## Working with Markdown
|
|
||||||
|
|
||||||
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
|
|
||||||
|
|
||||||
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
|
|
||||||
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
|
|
||||||
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.
|
|
||||||
|
|
||||||
## For more information
|
|
||||||
|
|
||||||
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
|
|
||||||
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
|
|
||||||
|
|
||||||
**Enjoy!**
|
|
4
Clients/VisualStudioCode/package-lock.json
generated
4
Clients/VisualStudioCode/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "lspclient",
|
"name": "lspclient",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "lspclient",
|
"name": "lspclient",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vscode-languageclient": "^9.0.1"
|
"vscode-languageclient": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
@@ -42,10 +42,11 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
revealOutputChannelOn: 4
|
revealOutputChannelOn: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Language Client erstellen und starten
|
// Language Client erstellen und starten
|
||||||
const client = new LanguageClient(
|
const client = new LanguageClient(
|
||||||
'javaLanguageServer', // ID des Clients
|
'javaTxLanguageServer', // ID des Clients
|
||||||
'Java Language Server', // Name des Clients
|
'Java-TX Language Server', // Name des Clients
|
||||||
serverOptions,
|
serverOptions,
|
||||||
clientOptions
|
clientOptions
|
||||||
);
|
);
|
||||||
|
BIN
LanguageServer/lib/JavaTXcompiler-0.1-jar-with-dependencies.jar
Normal file
BIN
LanguageServer/lib/JavaTXcompiler-0.1-jar-with-dependencies.jar
Normal file
Binary file not shown.
@@ -14,6 +14,7 @@ import org.apache.log4j.LogManager;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.messages.Message;
|
||||||
import org.eclipse.lsp4j.services.LanguageClient;
|
import org.eclipse.lsp4j.services.LanguageClient;
|
||||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ import java.nio.file.Paths;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +44,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
HashMap<String, String> textDocuments = new HashMap<>();
|
HashMap<String, String> textDocuments = new HashMap<>();
|
||||||
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
||||||
TextHelper textHelper = new TextHelper();
|
TextHelper textHelper = new TextHelper();
|
||||||
|
Boolean dontShowHints = false;
|
||||||
TypeResolver typeResolver = new TypeResolver();
|
TypeResolver typeResolver = new TypeResolver();
|
||||||
Path fileRoot = null;
|
Path fileRoot = null;
|
||||||
|
Boolean singleFileOpened = false;
|
||||||
|
|
||||||
public void setClient(LanguageClient client) {
|
public void setClient(LanguageClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@@ -51,6 +55,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
public void setFileRoot(List<WorkspaceFolder> root) {
|
public void setFileRoot(List<WorkspaceFolder> root) {
|
||||||
|
|
||||||
|
if (root == null) {
|
||||||
|
singleFileOpened = true;
|
||||||
|
}
|
||||||
//TODO: Nicht nur das erste Element nehmen sondern alle beachten
|
//TODO: Nicht nur das erste Element nehmen sondern alle beachten
|
||||||
fileRoot = Path.of(URI.create(root.get(0).getUri()));
|
fileRoot = Path.of(URI.create(root.get(0).getUri()));
|
||||||
}
|
}
|
||||||
@@ -91,6 +98,36 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayList<String> difference(String first, String second) {
|
||||||
|
ArrayList<String> result = new ArrayList<>();
|
||||||
|
|
||||||
|
int i = 0, j = 0;
|
||||||
|
int startDiff = -1;
|
||||||
|
|
||||||
|
while (j < second.length()) {
|
||||||
|
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
||||||
|
if (startDiff != -1) {
|
||||||
|
result.add(second.substring(startDiff, j));
|
||||||
|
startDiff = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
if (startDiff == -1) {
|
||||||
|
startDiff = j;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDiff != -1) {
|
||||||
|
result.add(second.substring(startDiff));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles didChange-Event.
|
* Handles didChange-Event.
|
||||||
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
||||||
@@ -101,6 +138,30 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
public void didChange(DidChangeTextDocumentParams params) {
|
public void didChange(DidChangeTextDocumentParams params) {
|
||||||
log("[didChange] Client triggered didChange Event.", MessageType.Info);
|
log("[didChange] Client triggered didChange Event.", MessageType.Info);
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Regenerate if Line-Count does not match -> Return new AST and see where the Positions are instead of calculating them from changes in Text-Document. Even possible?
|
||||||
|
|
||||||
|
String currentText = textDocuments.get(params.getTextDocument().getUri());
|
||||||
|
ArrayList<String> currentTextLines = new ArrayList<>(Arrays.stream(currentText.split("\n")).toList());
|
||||||
|
|
||||||
|
String newText = params.getContentChanges().getFirst().getText();
|
||||||
|
ArrayList<String> newTextLines = new ArrayList<>(Arrays.stream(newText.split("\n")).toList());
|
||||||
|
|
||||||
|
ArrayList<Integer> offsetPerLine = new ArrayList<>();
|
||||||
|
HashMap<Integer, List<String>> textChanges = new HashMap<>();
|
||||||
|
int index = 0;
|
||||||
|
for (String newTextLine : newTextLines) {
|
||||||
|
if (!(currentTextLines.size() > index)) {
|
||||||
|
offsetPerLine.add(0);
|
||||||
|
} else {
|
||||||
|
textChanges.put(index, difference(currentTextLines.get(index), newTextLine).stream().map(el -> el.replaceAll(" ", "")).toList());
|
||||||
|
offsetPerLine.add(newTextLine.length() - currentTextLines.get(index).length());
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||||
textDocuments.put(params.getTextDocument().getUri(), summedUp.get());
|
textDocuments.put(params.getTextDocument().getUri(), summedUp.get());
|
||||||
@@ -125,9 +186,37 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
|
||||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
// PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||||
client.publishDiagnostics(diagnosticsParams);
|
// client.publishDiagnostics(diagnosticsParams);
|
||||||
|
|
||||||
|
for (var inlayHint : globalInlayHintMap.get(params.getTextDocument().getUri())) {
|
||||||
|
inlayHint.getPosition().setCharacter(inlayHint.getPosition().getCharacter() + offsetPerLine.get(inlayHint.getPosition().getLine()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var inlayHint : globalDiagnosticsMap.get(params.getTextDocument().getUri())) {
|
||||||
|
inlayHint.getRange().getStart().setCharacter(inlayHint.getRange().getStart().getCharacter() + offsetPerLine.get(inlayHint.getRange().getStart().getLine()));
|
||||||
|
inlayHint.getRange().getEnd().setCharacter(inlayHint.getRange().getEnd().getCharacter() + offsetPerLine.get(inlayHint.getRange().getEnd().getLine()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var textChangeLine : textChanges.entrySet()) {
|
||||||
|
log(textChangeLine.getKey() + " - " + String.join(",", textChangeLine.getValue()), MessageType.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
globalInlayHintMap.put(params.getTextDocument().getUri(), globalInlayHintMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||||
|
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
||||||
|
log(el.getLabel().getLeft().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getPosition().getLine())) + ": " + (!textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""))? "true" : "false"), MessageType.Info);
|
||||||
|
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
globalDiagnosticsMap.put(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||||
|
log(el.getMessage().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getRange().getStart().getLine())) + ": " + (!textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""))? "true" : "false"), MessageType.Info);
|
||||||
|
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||||
|
}).toList());
|
||||||
|
|
||||||
|
|
||||||
|
updateClient(client);
|
||||||
|
client.publishDiagnostics(new PublishDiagnosticsParams(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,6 +372,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
client.showMessage(new MessageParams(MessageType.Error, e.getMessage()));
|
||||||
|
updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
currentlyCalculating = false;
|
currentlyCalculating = false;
|
||||||
@@ -295,21 +386,24 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
stopLoading("compile-task", "Types successfully inferred", client);
|
stopLoading("compile-task", "Types successfully inferred", client);
|
||||||
|
|
||||||
|
dontShowHints = false;
|
||||||
updateClient(client);
|
updateClient(client);
|
||||||
|
|
||||||
ArrayList<File> files = new ArrayList<>();
|
ArrayList<File> files = new ArrayList<>();
|
||||||
|
|
||||||
|
if (fileRoot != null) {
|
||||||
try (Stream<Path> stream = Files.walk(Paths.get(fileRoot.toUri()))) {
|
try (Stream<Path> stream = Files.walk(Paths.get(fileRoot.toUri()))) {
|
||||||
stream.filter(Files::isRegularFile)
|
stream.filter(Files::isRegularFile)
|
||||||
.forEach(el -> files.add(el.toFile()));
|
.forEach(el -> files.add(el.toFile()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
||||||
log("[inlayHint] The Client requested Inlay-Hints.", MessageType.Info);
|
log("[inlayHint] The Client requested Inlay-Hints.", MessageType.Info);
|
||||||
return CompletableFuture.supplyAsync(() -> globalInlayHintMap.get(params.getTextDocument().getUri()) == null ? Collections.emptyList() : globalInlayHintMap.get(params.getTextDocument().getUri()));
|
return CompletableFuture.supplyAsync(() -> dontShowHints ? Collections.emptyList() : globalInlayHintMap.get(params.getTextDocument().getUri()) == null ? Collections.emptyList() : globalInlayHintMap.get(params.getTextDocument().getUri()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -441,7 +535,11 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
||||||
|
|
||||||
log("[codeAction] Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].", MessageType.Info);
|
log("[codeAction] Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].", MessageType.Info);
|
||||||
|
|
||||||
|
log("Code-Action Context was: " + params.getContext().getTriggerKind().name(), MessageType.Info);
|
||||||
|
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
@@ -453,6 +551,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
||||||
|
|
||||||
Range rangeOfInsert = params.getRange();
|
Range rangeOfInsert = params.getRange();
|
||||||
|
|
||||||
|
|
||||||
String documentUri = params.getTextDocument().getUri();
|
String documentUri = params.getTextDocument().getUri();
|
||||||
|
|
||||||
|
|
||||||
@@ -515,7 +615,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(actions);
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
return actions;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user