Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a9bbe834cc | ||
|
4fbf9133a5 | ||
|
972d9014ba | ||
|
4f4404d366 | ||
|
2dfbef6d7f | ||
|
7e6e968b0f | ||
|
dded453ba3 | ||
|
254edf25af | ||
|
fc628f7547 |
Binary file not shown.
@@ -3,7 +3,7 @@
|
|||||||
"name": "java-tx-language-extension",
|
"name": "java-tx-language-extension",
|
||||||
"displayName": "Java-TX Language Extension",
|
"displayName": "Java-TX Language Extension",
|
||||||
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
||||||
"version": "0.0.9",
|
"version": "0.0.14",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.94.0"
|
"vscode": "^1.94.0"
|
||||||
},
|
},
|
||||||
|
@@ -13,6 +13,8 @@ import org.eclipse.lsp4j.*;
|
|||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@@ -78,6 +80,8 @@ public class ChangeHandler {
|
|||||||
|
|
||||||
if (!syntaxErrors.isEmpty()) {
|
if (!syntaxErrors.isEmpty()) {
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
||||||
|
}else {
|
||||||
|
clientService.updateClient();
|
||||||
}
|
}
|
||||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||||
|
|
||||||
@@ -93,7 +97,7 @@ public class ChangeHandler {
|
|||||||
logService.log("Type is here: " + type);
|
logService.log("Type is here: " + type);
|
||||||
for (LSPVariable variable : cacheService.getVariables()) {
|
for (LSPVariable variable : cacheService.getVariables()) {
|
||||||
for (Type variableType : variable.getPossibleTypes()) {
|
for (Type variableType : variable.getPossibleTypes()) {
|
||||||
logService.log(variableType.getType() + " <> "+ type.replaceAll(" ", "") + ": " + type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", "")));
|
logService.log(variableType.getType() + " <> " + type.replaceAll(" ", "") + ": " + type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", "")));
|
||||||
shouldCalculate = shouldCalculate || type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", ""));
|
shouldCalculate = shouldCalculate || type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", ""));
|
||||||
if (shouldCalculate) {
|
if (shouldCalculate) {
|
||||||
break;
|
break;
|
||||||
@@ -154,35 +158,39 @@ public class ChangeHandler {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
File tempDir2 = new File(System.getProperty("java.io.tmpdir"));
|
File tempDir2 = Path.of(new URI(params.getTextDocument().getUri())).getParent().toFile();
|
||||||
File tempFile2 = File.createTempFile("newText", ".tmp", tempDir2);
|
File tempFile2 = File.createTempFile("jtx_temp", ".tmp", tempDir2);
|
||||||
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||||
bw.write(input);
|
bw.write(input);
|
||||||
bw.close();
|
bw.close();
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input, false);
|
try {
|
||||||
cacheService.setVariables(variables);
|
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input);
|
||||||
|
cacheService.setVariables(variables);
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|
||||||
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
||||||
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
|
|
||||||
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
||||||
|
} catch (Exception | VerifyError f) {
|
||||||
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
|
for (StackTraceElement elem : f.getStackTrace()) {
|
||||||
|
logService.log(elem.toString());
|
||||||
|
}
|
||||||
|
clientService.showMessage(MessageType.Error, f.getMessage() == null ? "null" : f.getMessage());
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
}
|
||||||
tempFile2.delete();
|
tempFile2.delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
for (StackTraceElement elem : e.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
@@ -105,43 +105,50 @@ public class CodeActionHandler {
|
|||||||
String documentUri = params.getTextDocument().getUri();
|
String documentUri = params.getTextDocument().getUri();
|
||||||
Range rangeOfInsert = params.getRange();
|
Range rangeOfInsert = params.getRange();
|
||||||
|
|
||||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
if (typeResolver.getInserts() != null) {
|
||||||
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||||
logService.log("Inserts are:");
|
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
||||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
logService.log("Inserts are:");
|
||||||
logService.log("Size is: " + typeInsertsOverlapping.size());
|
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
||||||
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
logService.log("Size is: " + typeInsertsOverlapping.size());
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
||||||
|
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||||
|
|
||||||
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
||||||
for (var typeInsert : typeInsertList) {
|
for (var typeInsert : typeInsertList) {
|
||||||
try {
|
try {
|
||||||
logService.log("NEW TEXT OF FILE BEFORE INSERT IS:");
|
logService.log("NEW TEXT OF FILE BEFORE INSERT IS:");
|
||||||
logService.log(textDocumentService.getFileOfUri(documentUri));
|
logService.log(textDocumentService.getFileOfUri(documentUri));
|
||||||
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
||||||
|
|
||||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||||
|
|
||||||
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
||||||
|
|
||||||
var isTypeImported = false;
|
var isTypeImported = false;
|
||||||
|
|
||||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||||
changes.put(documentUri, listOfChanges);
|
changes.put(documentUri, listOfChanges);
|
||||||
|
|
||||||
WorkspaceEdit edit = new WorkspaceEdit();
|
WorkspaceEdit edit = new WorkspaceEdit();
|
||||||
edit.setChanges(changes);
|
edit.setChanges(changes);
|
||||||
|
|
||||||
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
|
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
|
||||||
action.setKind(CodeActionKind.QuickFix);
|
action.setKind(CodeActionKind.QuickFix);
|
||||||
action.setEdit(edit);
|
action.setEdit(edit);
|
||||||
actions.add(Either.forRight(action));
|
|
||||||
} catch (Exception e) {
|
if(!actions.stream().map(el -> el.getRight().getTitle()).toList().contains(action.getTitle())){
|
||||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
actions.add(Either.forRight(action));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return actions;
|
||||||
}
|
}
|
||||||
return actions;
|
|
||||||
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {
|
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package de.dhbw.handler;
|
package de.dhbw.handler;
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
|
import com.google.common.base.Verify;
|
||||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||||
import de.dhbw.service.*;
|
import de.dhbw.service.*;
|
||||||
import de.dhbw.helper.ConversionHelper;
|
import de.dhbw.helper.ConversionHelper;
|
||||||
@@ -51,19 +52,20 @@ public class SaveHandler {
|
|||||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
if (!syntaxErrors.isEmpty()) {
|
if (!syntaxErrors.isEmpty()) {
|
||||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), syntaxErrors);
|
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), syntaxErrors);
|
||||||
|
}else {
|
||||||
|
clientService.updateClient();
|
||||||
}
|
}
|
||||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||||
|
|
||||||
if (syntaxErrors.isEmpty()) {
|
if (syntaxErrors.isEmpty()) {
|
||||||
|
|
||||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||||
//typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
|
||||||
|
|
||||||
if (fileInput == null) {
|
if (fileInput == null) {
|
||||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput, false);
|
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||||
cacheService.setVariables(variables);
|
cacheService.setVariables(variables);
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
@@ -79,16 +81,13 @@ public class SaveHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception | VerifyError e) {
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
for (StackTraceElement elem : e.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
}
|
||||||
} finally {
|
finally {
|
||||||
sWatch.stop();
|
sWatch.stop();
|
||||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
}
|
}
|
||||||
|
@@ -140,7 +140,7 @@ public class TypeResolver {
|
|||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) throws IOException, ClassNotFoundException, URISyntaxException {
|
public ArrayList<LSPVariable> infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
||||||
|
@@ -42,6 +42,11 @@ public class PlaceholderPoint {
|
|||||||
return point.getStartIndex() + extraOffset;
|
return point.getStartIndex() + extraOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public PlaceholderType getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return this == obj;
|
return this == obj;
|
||||||
/*
|
/*
|
||||||
|
@@ -13,7 +13,6 @@ public class PlaceholderVariable {
|
|||||||
ResultPair<?, ?> resultPair;
|
ResultPair<?, ?> resultPair;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
|
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
|
||||||
this.point = point;
|
this.point = point;
|
||||||
inserts = additionalPoints;
|
inserts = additionalPoints;
|
||||||
@@ -26,7 +25,10 @@ public class PlaceholderVariable {
|
|||||||
|
|
||||||
List<PlaceholderPoint> insertsSorted = new ArrayList<>();
|
List<PlaceholderPoint> insertsSorted = new ArrayList<>();
|
||||||
insertsSorted.add(point);
|
insertsSorted.add(point);
|
||||||
insertsSorted.addAll(inserts);
|
|
||||||
|
if (!point.getInsertString().contains("void")) {
|
||||||
|
insertsSorted.addAll(inserts);
|
||||||
|
}
|
||||||
Collections.sort(insertsSorted, new PlaceholderPoint.TypeInsertPointPositionComparator().reversed());
|
Collections.sort(insertsSorted, new PlaceholderPoint.TypeInsertPointPositionComparator().reversed());
|
||||||
|
|
||||||
for (PlaceholderPoint insertPoint : insertsSorted) {
|
for (PlaceholderPoint insertPoint : insertsSorted) {
|
||||||
@@ -40,7 +42,8 @@ public class PlaceholderVariable {
|
|||||||
return point.getInsertString();
|
return point.getInsertString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reducePackage(){point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
|
public void reducePackage() {
|
||||||
|
point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultPair<?, ?> getResultPair() {
|
public ResultPair<?, ?> getResultPair() {
|
||||||
|
@@ -55,11 +55,16 @@ The Language Server in itself can be used for any Client. The Clients task is to
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Additional Information
|
||||||
|
|
||||||
|
- Uses the [LSP-Interface](https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore/src/branch/LSP-Interface) Branch of the Java-TX Compiler Repository
|
||||||
|
|
||||||
## Update JavaTX Compiler Dependency as Maven Package
|
## Update JavaTX Compiler Dependency as Maven Package
|
||||||
If you make changes in the Compiler Interface, you have to change the jar and therefore the Dependency in the Java TX Language Server
|
If you make changes in the Compiler Interface, you have to change the jar and therefore the Dependency in the Java TX Language Server
|
||||||
You can follow this steps:
|
You can follow this steps:
|
||||||
1. package the JavaTX Compiler
|
1. package the JavaTX Compiler
|
||||||
2. take the Jar-File and copy it into the /lib Folder
|
2. create a lib Folder at ./LangaugeServer -> ./LanguageServer/lib
|
||||||
|
2. take the Jar-File and copy it into the /lib Folder at
|
||||||
3. execute this Maven command to add the Jar in your local Repository: ```mvn install:install-file -Dfile=lib/JavaTXcompiler-0.1-jar-with-dependencies.jar -DgroupId=de.dhbwstuttgart -DartifactId=JavaTXcompiler -Dversion=0.1 -Dpackaging=jar```
|
3. execute this Maven command to add the Jar in your local Repository: ```mvn install:install-file -Dfile=lib/JavaTXcompiler-0.1-jar-with-dependencies.jar -DgroupId=de.dhbwstuttgart -DartifactId=JavaTXcompiler -Dversion=0.1 -Dpackaging=jar```
|
||||||
4. run ```maven clean```, ```validate``` and ```install``` to load the new Dependency
|
4. run ```maven clean```, ```validate``` and ```install``` to load the new Dependency
|
||||||
5. you can now package the Language Server or change the code accordingly.
|
5. you can now package the Language Server or change the code accordingly.
|
Reference in New Issue
Block a user