9 Commits

Author SHA1 Message Date
Ruben
7e6e968b0f feat: do not show 100 times the insert 2025-09-22 18:22:05 +02:00
Ruben
dded453ba3 feat: update jar and Version 2025-09-22 15:42:25 +02:00
Ruben
254edf25af feat: update jar and Version 2025-09-19 19:20:16 +02:00
RubenKraft
fc628f7547 Update README.md 2025-09-18 16:05:45 +00:00
Ruben
33d5fbb01d feat: update jar and Version 2025-09-18 17:55:45 +02:00
Ruben
6332daf2ad feat: update Compiler Jar 2025-09-18 17:54:17 +02:00
Ruben
01616ee985 feat: update vscode client 2025-09-17 19:11:55 +02:00
Ruben
29f0e6a05a Merge remote-tracking branch 'origin/main'
# Conflicts:
#	Clients/VisualStudioCode/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
#	Clients/VisualStudioCode/package.json
2025-09-17 19:08:53 +02:00
Ruben
7bc07d9ac1 feat: update vscode client 2025-09-15 18:51:24 +02:00
10 changed files with 78 additions and 48 deletions

View File

@@ -1,3 +1,3 @@
# lspclient README # Java-TX Language Server
This is the README for the Java-TX LSP Client. This is the official Plugin for Java-TX.

View File

@@ -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.7", "version": "0.0.11",
"engines": { "engines": {
"vscode": "^1.94.0" "vscode": "^1.94.0"
}, },

View File

@@ -13,12 +13,12 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
const serverOptions: ServerOptions = { const serverOptions: ServerOptions = {
run: { run: {
command: 'java', command: 'java',
args: ['-Xss2m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], args: ['-Xss10m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
}, },
debug: { debug: {
command: 'java', command: 'java',
args: [ args: [
'-Xss2m', '-Xss10m',
'-jar', '-jar',
workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar', workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar',
], ],
@@ -26,7 +26,7 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
}; };
const clientOptions: LanguageClientOptions = { const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'java' }], documentSelector: [{ scheme: 'file', pattern: '**/*.jav' }],
synchronize: { synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.jav') fileEvents: vscode.workspace.createFileSystemWatcher('**/*.jav')
}, },

View File

@@ -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;
@@ -93,7 +95,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,28 +156,37 @@ 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, true);
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())); allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics); clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} catch (Exception 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);

View File

@@ -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) {

View File

@@ -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;
/* /*

View File

@@ -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() {

View File

@@ -55,6 +55,10 @@ The Language Server in itself can be used for any Client. The Clients task is to
![Diagram](docs/diagram.png) ![Diagram](docs/diagram.png)
## 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: