12 Commits

Author SHA1 Message Date
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
ed26f869c3 feat #40: only insert Type as normal name without package reference as it is implicitly imported 2025-09-17 14:29:46 +02:00
Ruben
ee0b51868c feat: move compilation into compiler 2025-09-17 11:32:46 +02:00
Ruben
98b32fd418 feat #40: remove Diagnostic if it has been selected 2025-09-17 11:08:07 +02:00
Ruben
7bc07d9ac1 feat: update vscode client 2025-09-15 18:51:24 +02:00
Ruben
558fcb5ebb feat: initially check syntax when opening document 2025-09-15 13:50:20 +02:00
Ruben
1e4541b705 feat: update 2025-09-11 12:53:41 +02:00
15 changed files with 150 additions and 161 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.5", "version": "0.0.9",
"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

@@ -55,7 +55,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
this.logService = new LogService(clientService); this.logService = new LogService(clientService);
this.formattingHandler = new FormattingHandler(textDocumentService); this.formattingHandler = new FormattingHandler(textDocumentService);
this.parserService = new ParserService(conversionHelper, clientService, cacheService); this.parserService = new ParserService(conversionHelper, clientService, cacheService);
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService); this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService, conversionHelper);
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService); this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService);
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService); this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService);
} }
@@ -109,6 +109,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
public void didOpen(DidOpenTextDocumentParams params) { public void didOpen(DidOpenTextDocumentParams params) {
cacheService.reset(); cacheService.reset();
typeResolver.reset(); typeResolver.reset();
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(params.getTextDocument().getText(), params.getTextDocument().getUri());
if (!syntaxErrors.isEmpty()) {
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
}
client.refreshDiagnostics(); client.refreshDiagnostics();
client.refreshInlayHints(); client.refreshInlayHints();
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText()); textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());

View File

@@ -3,16 +3,18 @@ package de.dhbw.handler;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import de.dhbw.helper.ConversionHelper; import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TypeResolver; import de.dhbw.helper.TypeResolver;
import de.dhbw.model.DiagnosticsAndTypehints; import de.dhbw.model.*;
import de.dhbw.model.DocumentChanges;
import de.dhbw.model.LSPVariable;
import de.dhbw.model.LineCharPosition;
import de.dhbw.service.*; import de.dhbw.service.*;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import org.eclipse.lsp4j.*; 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;
@@ -40,27 +42,32 @@ public class ChangeHandler {
public static String findAddedWord(String str1, String str2) { public static String findAddedWord(String str1, String str2) {
String[] words1 = str1.split("\\s+");
String[] words2 = str2.split("\\s+");
int i = 0, j = 0; int i = 0, j = 0;
while (i < words1.length && j < words2.length) {
if (words1[i].equals(words2[j])) { // Suche den ersten Unterschied
i++; while (i < str1.length() && j < str2.length() && str1.charAt(i) == str2.charAt(j)) {
j++; i++;
} else { j++;
return words2[j]; // Unterschied gefunden
}
} }
// Falls das neue Wort am Ende steht // Falls alles gleich ist, gibt es nichts Neues
if (j < words2.length) { if (i == str1.length() && j == str2.length()) {
return words2[j]; return null;
} }
return null; // Kein Unterschied gefunden // Suche ab Ende rückwärts, um den gemeinsamen Suffix zu finden
int iEnd = str1.length() - 1;
int jEnd = str2.length() - 1;
while (iEnd >= i && jEnd >= j && str1.charAt(iEnd) == str2.charAt(jEnd)) {
iEnd--;
jEnd--;
}
// Der Unterschied liegt nun zwischen j und jEnd in str2
return str2.substring(j, jEnd + 1);
} }
public void didChange(DidChangeTextDocumentParams params) { public void didChange(DidChangeTextDocumentParams params) {
String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri()); String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
@@ -70,6 +77,7 @@ public class ChangeHandler {
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(summedUp.get(), params.getTextDocument().getUri()); List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(summedUp.get(), params.getTextDocument().getUri());
if (!syntaxErrors.isEmpty()) { if (!syntaxErrors.isEmpty()) {
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors); clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
} }
@@ -77,41 +85,27 @@ public class ChangeHandler {
if (syntaxErrors.isEmpty()) { if (syntaxErrors.isEmpty()) {
DocumentChanges documentChanges = textDocumentService.calculateDifference(currentText, summedUp.get());
HashMap<LineCharPosition, String> preciseChanges = documentChanges.getPreciseChanges();
HashMap<Integer, List<String>> textChanges;
String type = findAddedWord(currentText, summedUp.get()); String type = findAddedWord(currentText, summedUp.get());
logService.log("ADDED TYPE IS: " + type);
//Have to check of old saved Input because the result set and Inlay Hints will be updated according to the old AST which contains the old Positions
if (cacheService.getLastSavedFiles().containsKey(params.getTextDocument().getUri())) {
DocumentChanges changesFromOldSave = textDocumentService.calculateDifference(cacheService.getLastSavedFiles().get(params.getTextDocument().getUri()), summedUp.get());
;
textChanges = changesFromOldSave.getTextChanges();
preciseChanges = changesFromOldSave.getPreciseChanges();
logService.log(textChanges.values().stream().map(el -> String.join(", ", el)).collect(Collectors.joining("\n")));
} else {
textChanges = documentChanges.getTextChanges();
}
String input = summedUp.get(); String input = summedUp.get();
logService.log("Variables are: " + cacheService.getVariables().size()); logService.log("Variables are: " + cacheService.getVariables().size());
boolean shouldCalculate = false;
AtomicBoolean needToCalculate = new AtomicBoolean(false); logService.log("Type is here: " + type);
for (LSPVariable variable : cacheService.getVariables()) {
cacheService.getVariables().forEach( for (Type variableType : variable.getPossibleTypes()) {
el -> el.getPossibleTypes().forEach(pos -> needToCalculate.set(needToCalculate.get() || pos.getType().equalsIgnoreCase(type))) logService.log(variableType.getType() + " <> " + type.replaceAll(" ", "") + ": " + type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", "")));
); shouldCalculate = shouldCalculate || type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", ""));
if (shouldCalculate) {
break;
}
}
}
logService.log("Should Calculate is: " + shouldCalculate);
if (false) { if (false) {
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
try { try {
File tempDir = new File(System.getProperty("java.io.tmpdir")); File tempDir = new File(System.getProperty("java.io.tmpdir"));
File tempFile = File.createTempFile("newText", ".tmp", tempDir); File tempFile = File.createTempFile("newText", ".tmp", tempDir);
@@ -126,33 +120,20 @@ public class ChangeHandler {
logService.log(e.getMessage()); logService.log(e.getMessage());
} }
var sWatch = Stopwatch.createUnstarted(); var sWatch = Stopwatch.createUnstarted();
sWatch.start(); sWatch.start();
try { try {
String currentInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
if (currentInput == null) {
logService.log("[didChange] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
}
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput(); ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput();
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri()); DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
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());
} catch (Exception e) { } catch (Exception e) {
logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error); logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
for (var stackTrace : e.getStackTrace()) { for (var stackTrace : e.getStackTrace()) {
logService.log(stackTrace.toString()); logService.log(stackTrace.toString());
} }
@@ -165,68 +146,47 @@ public class ChangeHandler {
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info); logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
} }
//updatePositions(params, offsetPerLine);
cacheService.getGlobalInlayHintMap().put(params.getTextDocument().getUri(), cacheService.getGlobalInlayHintMap().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.
logService.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());
cacheService.getGlobalDiagnosticsMap().put(params.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()).stream().filter(el -> {
logService.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());
List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri()); List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
List<Diagnostic> parserErrors = parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri());
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics); ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
allDiagnostics.addAll(parserErrors);
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics); clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
} else { } else {
logService.log("Calculating again.");
var sWatch = Stopwatch.createUnstarted(); var sWatch = Stopwatch.createUnstarted();
sWatch.start(); sWatch.start();
try { try {
String fileInput = input;
logService.log("Input ist:");
logService.log(fileInput);
// cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
// typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
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(fileInput); bw.write(input);
bw.close(); bw.close();
try {
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input, true);
cacheService.setVariables(variables);
if (fileInput == null) { DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
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());
} }
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), fileInput, false);
cacheService.setVariables(variables);
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(fileInput, params.getTextDocument().getUri()));
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
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);
@@ -240,7 +200,6 @@ public class ChangeHandler {
} 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);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@@ -1,5 +1,6 @@
package de.dhbw.handler; package de.dhbw.handler;
import de.dhbw.helper.ConversionHelper;
import de.dhbw.helper.TextHelper; import de.dhbw.helper.TextHelper;
import de.dhbw.helper.TypeResolver; import de.dhbw.helper.TypeResolver;
import de.dhbw.service.CacheService; import de.dhbw.service.CacheService;
@@ -22,13 +23,15 @@ public class CodeActionHandler {
private final CacheService cacheService; private final CacheService cacheService;
private final TypeResolver typeResolver; private final TypeResolver typeResolver;
private final LogService logService; private final LogService logService;
private final ConversionHelper conversionHelper;
public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService) { public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService, ConversionHelper conversionHelper) {
this.textHelper = textHelper; this.textHelper = textHelper;
this.textDocumentService = textDocumentService; this.textDocumentService = textDocumentService;
this.cacheService = cacheService; this.cacheService = cacheService;
this.typeResolver = typeResolver; this.typeResolver = typeResolver;
this.logService = logService; this.logService = logService;
this.conversionHelper = conversionHelper;
} }
public static Range wholeDocumentRange(String text) { public static Range wholeDocumentRange(String text) {
@@ -103,7 +106,7 @@ public class CodeActionHandler {
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 //All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine()+1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter()); Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
logService.log("Inserts are:"); logService.log("Inserts are:");
typeResolver.getInserts().forEach((key, value) -> logService.log(key)); typeResolver.getInserts().forEach((key, value) -> logService.log(key));
logService.log("Size is: " + typeInsertsOverlapping.size()); logService.log("Size is: " + typeInsertsOverlapping.size());
@@ -113,6 +116,8 @@ public class CodeActionHandler {
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(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<>();
@@ -127,7 +132,7 @@ public class CodeActionHandler {
WorkspaceEdit edit = new WorkspaceEdit(); WorkspaceEdit edit = new WorkspaceEdit();
edit.setChanges(changes); edit.setChanges(changes);
CodeAction action = new CodeAction("Insert " + 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)); actions.add(Either.forRight(action));

View File

@@ -74,7 +74,6 @@ public class SaveHandler {
cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri()); cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri());
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics); List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri()));
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics); clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);

View File

@@ -20,12 +20,16 @@ public class ConversionHelper {
this.textDocumentService = textDocumentService; this.textDocumentService = textDocumentService;
} }
public String cleanType(String type){
return type.replaceAll("java.lang.", "").replaceAll("java.util.", "");
}
public InlayHint getInlayHint(LSPVariable variable) { public InlayHint getInlayHint(LSPVariable variable) {
InlayHint inlayHint = new InlayHint(); InlayHint inlayHint = new InlayHint();
String typeDisplay = ""; String typeDisplay = "";
for (Type type : variable.getPossibleTypes()) { for (Type type : variable.getPossibleTypes()) {
typeDisplay += " | " + type.getType().replaceAll("GTV ", ""); typeDisplay += " | " + cleanType(type.getType().replaceAll("GTV ", ""));
} }
@@ -45,7 +49,7 @@ public class ConversionHelper {
Diagnostic diagnostic = new Diagnostic( Diagnostic diagnostic = new Diagnostic(
errorRange, errorRange,
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver //TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
type.getType().replaceAll("GTV ", ""), cleanType(type.getType().replaceAll("GTV ", "")),
DiagnosticSeverity.Hint, DiagnosticSeverity.Hint,
"JavaTX Language Server" "JavaTX Language Server"
); );
@@ -62,7 +66,7 @@ public class ConversionHelper {
Diagnostic diagnostic = new Diagnostic( Diagnostic diagnostic = new Diagnostic(
errorRange, errorRange,
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver //TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
type.getType().replaceAll("GTV ", ""), cleanType(type.getType().replaceAll("GTV ", "")),
DiagnosticSeverity.Hint, DiagnosticSeverity.Hint,
"JavaTX Language Server" "JavaTX Language Server"
); );
@@ -71,7 +75,7 @@ public class ConversionHelper {
return diagnostic; return diagnostic;
} }
public List<Diagnostic> parseErrorToDiagnostic(List<ParserError> parserErrors){ public List<Diagnostic> parseErrorToDiagnostic(List<ParserError> parserErrors) {
return parserErrors.stream().map(el -> { return parserErrors.stream().map(el -> {
Range errorRange = new Range( Range errorRange = new Range(
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
@@ -86,7 +90,7 @@ public class ConversionHelper {
}).toList(); }).toList();
} }
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> typesOfMethodAndParameters, String uri){ public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> typesOfMethodAndParameters, String uri) {
List<InlayHint> typeHint = new ArrayList<>(); List<InlayHint> typeHint = new ArrayList<>();
ArrayList<Diagnostic> diagnostics = new ArrayList<>(); ArrayList<Diagnostic> diagnostics = new ArrayList<>();
@@ -103,7 +107,8 @@ public class ConversionHelper {
return new DiagnosticsAndTypehints(diagnostics, typeHint); return new DiagnosticsAndTypehints(diagnostics, typeHint);
} }
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input){
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input) {
List<InlayHint> typeHint = new ArrayList<>(); List<InlayHint> typeHint = new ArrayList<>();
ArrayList<Diagnostic> diagnostics = new ArrayList<>(); ArrayList<Diagnostic> diagnostics = new ArrayList<>();

View File

@@ -19,6 +19,7 @@ public class PlaceholderPlacer extends AbstractASTWalker {
this.genericsResult = genericsResult; this.genericsResult = genericsResult;
pkgName = forSourceFile.getPkgName(); pkgName = forSourceFile.getPkgName();
forSourceFile.accept(this); forSourceFile.accept(this);
inserts.forEach(el -> el.reducePackage());
return inserts; return inserts;
} }

View File

@@ -115,12 +115,21 @@ public class TypeResolver {
} }
} }
inserts = insertsOnLines;
ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList()); ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList());
for (var variable : variables) { for (var variable : variables) {
Set<Type> set = new HashSet<>(variable.getPossibleTypes().stream().map(el -> new Type(el.getType().replaceAll(" ", ""), el.isGeneric())).toList());
variable.getPossibleTypes().clear(); HashMap<String, Type> uniqueType = new HashMap<>();
variable.getPossibleTypes().addAll(set);
for (var type : variable.getPossibleTypes()) {
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
uniqueType.put(type.getType(), type);
}
}
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
logger.info(variable.getLine() + ":" + variable.getCharPosition()); logger.info(variable.getLine() + ":" + variable.getCharPosition());
for (Type t : variable.getPossibleTypes()) { for (Type t : variable.getPossibleTypes()) {
logger.info(t.getType()); logger.info(t.getType());
@@ -134,39 +143,20 @@ public class TypeResolver {
public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) throws IOException, ClassNotFoundException, URISyntaxException { public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) throws IOException, ClassNotFoundException, URISyntaxException {
System.setOut(new PrintStream(OutputStream.nullOutputStream())); System.setOut(new PrintStream(OutputStream.nullOutputStream()));
var uri = new URI(pathString); LanguageServerInterface languageServerInterface = new LanguageServerInterface();
var path = Path.of(uri); LanguageServerTransferObject lsTransfer = languageServerInterface.getResultSetAndAbstractSyntax(pathString);
logger.info("Path is for calculation: " + path.toString()); var parsedSource = lsTransfer.getAst();
var file = path.toFile(); var tiResults = lsTransfer.getResultSets();
NameGenerator.resetTo("A");
Files.createDirectories(path.getParent().resolve("out"));
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
var parsedSource = compiler.sourceFiles.get(file);
var tiResults = compiler.typeInference(file);
Set<PlaceholderVariable> tips = new HashSet<>(); Set<PlaceholderVariable> tips = new HashSet<>();
// for (var sf : compiler.sourceFiles.values()) { generatedGenerics = lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst());
// Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
// logger.info("Path for Class-File is: " + path.getParent().resolve("out").toFile());
// Files.createDirectories(path.getParent().resolve("out"));
// compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
//
// }
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(parsedSource, tiResults);
logger.info("Path for Class-File is: " + path.getParent().resolve("out").toFile());
Files.createDirectories(path.getParent().resolve("out"));
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
generatedGenerics = compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file));
for (int i = 0; i < tiResults.size(); i++) { for (int i = 0; i < tiResults.size(); i++) {
ResultSet tiResult = tiResults.get(i); ResultSet tiResult = tiResults.get(i);
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i))); tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst()).get(i)));
} }
System.setOut(System.out); System.setOut(System.out);
this.current = new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics()); this.current = lsTransfer;
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>(); HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
@@ -180,9 +170,20 @@ public class TypeResolver {
inserts = insertsOnLines; inserts = insertsOnLines;
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.insert(input)))); logger.info("TYPES ARE:");
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.point.getInsertString())));
ArrayList<LSPVariable> variables = new ArrayList<>();
ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList());
for(var entrySet : insertsOnLines.entrySet()){
ArrayList<Type> typesOfVariable = new ArrayList<>();
for(PlaceholderVariable typeinsert : entrySet.getValue()){
typesOfVariable.add(new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()));
}
variables.add(new LSPVariable("test",typesOfVariable , entrySet.getValue().getFirst().point.point.getLine(), entrySet.getValue().getFirst().point.point.getCharPositionInLine(), entrySet.getValue().get(0).point.point.getStopIndex(), entrySet.getValue().get(0).getResultPair().getLeft()));
}
for (var variable : variables) { for (var variable : variables) {

View File

@@ -12,6 +12,10 @@ public class PlaceholderPoint {
private int extraOffset = 0; private int extraOffset = 0;
private PlaceholderType kind; private PlaceholderType kind;
public void setInsertString(String insertString){
this.insertString = insertString;
}
public PlaceholderPoint(Token point, String toInsert, PlaceholderType kind){ public PlaceholderPoint(Token point, String toInsert, PlaceholderType kind){
this.point = point; this.point = point;
this.kind = kind; this.kind = kind;
@@ -38,11 +42,11 @@ public class PlaceholderPoint {
return point.getStartIndex() + extraOffset; return point.getStartIndex() + extraOffset;
} }
/* PL 2018-06-19
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind public PlaceholderType getKind() {
* eingefuegt damit man TypeReplaceMarker vergleichen kann return kind;
* @see java.lang.Object#equals(java.lang.Object) }
*/
public boolean equals(Object obj) { public boolean equals(Object obj) {
return this == obj; return this == obj;
/* /*

View File

@@ -12,6 +12,7 @@ public class PlaceholderVariable {
Set<PlaceholderPoint> inserts; Set<PlaceholderPoint> inserts;
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;
@@ -24,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) {
@@ -38,6 +42,10 @@ public class PlaceholderVariable {
return point.getInsertString(); return point.getInsertString();
} }
public void reducePackage() {
point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
}
public ResultPair<?, ?> getResultPair() { public ResultPair<?, ?> getResultPair() {
return this.resultPair; return this.resultPair;
} }

View File

@@ -48,7 +48,6 @@ public class CacheService {
typeResolver = new TypeResolver(); typeResolver = new TypeResolver();
fileRoot = null; fileRoot = null;
singleFileOpened = false; singleFileOpened = false;
variables = new ArrayList<>();
typeInserts = null; typeInserts = null;
} }

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: