Compare commits
2 Commits
main
...
async-comp
Author | SHA1 | Date | |
---|---|---|---|
|
0d50cf1517 | ||
|
39876f3866 |
Binary file not shown.
@@ -1,3 +1,3 @@
|
|||||||
# Java-TX Language Server
|
# lspclient README
|
||||||
|
|
||||||
This is the official Plugin for Java-TX.
|
This is the README for the Java-TX LSP Client.
|
@@ -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.5",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.94.0"
|
"vscode": "^1.94.0"
|
||||||
},
|
},
|
||||||
|
@@ -13,12 +13,12 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
|
|||||||
const serverOptions: ServerOptions = {
|
const serverOptions: ServerOptions = {
|
||||||
run: {
|
run: {
|
||||||
command: 'java',
|
command: 'java',
|
||||||
args: ['-Xss10m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
|
args: ['-Xss2m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
|
||||||
},
|
},
|
||||||
debug: {
|
debug: {
|
||||||
command: 'java',
|
command: 'java',
|
||||||
args: [
|
args: [
|
||||||
'-Xss10m',
|
'-Xss2m',
|
||||||
'-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', pattern: '**/*.jav' }],
|
documentSelector: [{ scheme: 'file', language: 'java' }],
|
||||||
synchronize: {
|
synchronize: {
|
||||||
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.jav')
|
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.jav')
|
||||||
},
|
},
|
||||||
|
@@ -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, conversionHelper);
|
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService);
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||||
logService.log("[didSave] Client triggered didSave-Event.");
|
logService.log("[didSave] Client triggered didSave-Event.");
|
||||||
clientService.startLoading("compile-task", "Inferring types...", client);
|
clientService.startLoading("compile-task", "Inferring types...", client);
|
||||||
saveHandler.handleSave(didSaveTextDocumentParams);
|
saveHandler.asyncHandle(didSaveTextDocumentParams);
|
||||||
clientService.stopLoading("compile-task", "Types successfully inferred", client);
|
clientService.stopLoading("compile-task", "Types successfully inferred", client);
|
||||||
clientService.updateClient(client);
|
clientService.updateClient(client);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -23,15 +22,13 @@ 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, ConversionHelper conversionHelper) {
|
public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService) {
|
||||||
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) {
|
||||||
@@ -106,7 +103,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());
|
||||||
@@ -116,8 +113,6 @@ 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<>();
|
||||||
@@ -132,7 +127,7 @@ public class CodeActionHandler {
|
|||||||
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 " + 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));
|
||||||
|
@@ -1,16 +1,27 @@
|
|||||||
package de.dhbw.handler;
|
package de.dhbw.handler;
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
|
import de.dhbw.helper.ResultListener;
|
||||||
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;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
import de.dhbw.model.LSPVariable;
|
import de.dhbw.model.LSPVariable;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenerateGenerics;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -93,4 +104,28 @@ public class SaveHandler {
|
|||||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void asyncHandle(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResultListener resultListener = new ResultListener(typeResolver, didSaveTextDocumentParams, cacheService, conversionHelper, clientService);
|
||||||
|
resultListener.init(didSaveTextDocumentParams);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
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());
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,16 +20,12 @@ 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 += " | " + cleanType(type.getType().replaceAll("GTV ", ""));
|
typeDisplay += " | " + type.getType().replaceAll("GTV ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +45,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
|
||||||
cleanType(type.getType().replaceAll("GTV ", "")),
|
type.getType().replaceAll("GTV ", ""),
|
||||||
DiagnosticSeverity.Hint,
|
DiagnosticSeverity.Hint,
|
||||||
"JavaTX Language Server"
|
"JavaTX Language Server"
|
||||||
);
|
);
|
||||||
@@ -66,7 +62,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
|
||||||
cleanType(type.getType().replaceAll("GTV ", "")),
|
type.getType().replaceAll("GTV ", ""),
|
||||||
DiagnosticSeverity.Hint,
|
DiagnosticSeverity.Hint,
|
||||||
"JavaTX Language Server"
|
"JavaTX Language Server"
|
||||||
);
|
);
|
||||||
@@ -75,7 +71,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
|
||||||
@@ -90,7 +86,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<>();
|
||||||
|
|
||||||
@@ -107,8 +103,7 @@ 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<>();
|
||||||
|
|
||||||
|
@@ -19,7 +19,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbw.helper;
|
||||||
|
|
||||||
|
public class Recalculator {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
123
LanguageServer/src/main/java/de/dhbw/helper/ResultListener.java
Normal file
123
LanguageServer/src/main/java/de/dhbw/helper/ResultListener.java
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
package de.dhbw.helper;
|
||||||
|
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
|
import de.dhbw.handler.SaveHandler;
|
||||||
|
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||||
|
import de.dhbw.model.LSPVariable;
|
||||||
|
import de.dhbw.service.CacheService;
|
||||||
|
import de.dhbw.service.ClientService;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
import org.eclipse.lsp4j.Diagnostic;
|
||||||
|
import org.eclipse.lsp4j.DidSaveTextDocumentParams;
|
||||||
|
import org.eclipse.lsp4j.InlayHint;
|
||||||
|
import org.eclipse.lsp4j.MessageType;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ResultListener implements UnifyResultListener {
|
||||||
|
|
||||||
|
TypeResolver typeResolver;
|
||||||
|
SourceFile ast;
|
||||||
|
DidSaveTextDocumentParams didSaveTextDocumentParams;
|
||||||
|
CacheService cacheService;
|
||||||
|
ConversionHelper conversionHelper;
|
||||||
|
ClientService clientService;
|
||||||
|
JavaTXCompiler compiler;
|
||||||
|
SourceFile sourceFile;
|
||||||
|
|
||||||
|
|
||||||
|
public ResultListener(TypeResolver saveHandler, DidSaveTextDocumentParams didSaveTextDocumentParams, CacheService cacheService, ConversionHelper conversionHelper, ClientService clientService){
|
||||||
|
this.typeResolver = saveHandler;
|
||||||
|
this.didSaveTextDocumentParams = didSaveTextDocumentParams;
|
||||||
|
this.cacheService = cacheService;
|
||||||
|
this.conversionHelper = conversionHelper;
|
||||||
|
this.clientService = clientService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(DidSaveTextDocumentParams didSaveTextDocumentParams){
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
|
var uri = new URI(didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
var path = Path.of(uri);
|
||||||
|
|
||||||
|
var file = path.toFile();
|
||||||
|
Files.createDirectories(path.getParent().resolve("out"));
|
||||||
|
|
||||||
|
this.compiler = new JavaTXCompiler(file, false);
|
||||||
|
sourceFile = compiler.sourceFiles.get(file);
|
||||||
|
|
||||||
|
compiler.typeInferenceAsync(this, new OutputStreamWriter(new NullOutputStream()));
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
clientService.sendClientLog("KRITISCHE");
|
||||||
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
|
for (StackTraceElement stack : e.getStackTrace()){
|
||||||
|
clientService.sendClientLog(stack.toString());
|
||||||
|
}
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNewTypeResultFound(UnifyResultEvent unifyResultEvent) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
clientService.sendClientLog("YEEEEEEEEEEEP: " + (unifyResultEvent.getNewTypeResult() == null ? "Null" : "Nicht null"));
|
||||||
|
List<LSPVariable> lspVariables = typeResolver.infereIncremental(unifyResultEvent.getNewTypeResult(), this.compiler.getGeneratedGenerics().get(sourceFile), ast);
|
||||||
|
|
||||||
|
if(cacheService.getVariables() == null){
|
||||||
|
clientService.sendClientLog("Variablen null");
|
||||||
|
cacheService.setVariables(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheService.getVariables().addAll(lspVariables);
|
||||||
|
|
||||||
|
|
||||||
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(new ArrayList<>(lspVariables), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
clientService.sendClientLog("Diagnostiken erstellt");
|
||||||
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|
||||||
|
cacheService.getGlobalInlayHintMap().computeIfAbsent(didSaveTextDocumentParams.getTextDocument().getUri(), k -> new ArrayList<>());
|
||||||
|
cacheService.getGlobalDiagnosticsMap().computeIfAbsent(didSaveTextDocumentParams.getTextDocument().getUri(), k -> new ArrayList<>());
|
||||||
|
|
||||||
|
|
||||||
|
cacheService.getGlobalInlayHintMap().get(didSaveTextDocumentParams.getTextDocument().getUri()).addAll(typeHint);
|
||||||
|
cacheService.getGlobalDiagnosticsMap().get(didSaveTextDocumentParams.getTextDocument().getUri()).addAll(diagnostics);
|
||||||
|
clientService.sendClientLog("paaaaaaaaaaaaast");
|
||||||
|
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(didSaveTextDocumentParams.getTextDocument().getUri()));
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
clientService.sendClientLog("KOMISCHER FEHLER!");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
clientService.sendClientLog("KOMISCHER FEHLER!");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
clientService.sendClientLog("KOMISCHER FEHLER!");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -143,20 +143,102 @@ 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()));
|
||||||
|
|
||||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
var uri = new URI(pathString);
|
||||||
LanguageServerTransferObject lsTransfer = languageServerInterface.getResultSetAndAbstractSyntax(pathString);
|
var path = Path.of(uri);
|
||||||
|
|
||||||
var parsedSource = lsTransfer.getAst();
|
logger.info("Path is for calculation: " + path.toString());
|
||||||
var tiResults = lsTransfer.getResultSets();
|
var file = path.toFile();
|
||||||
|
Files.createDirectories(path.getParent().resolve("out"));
|
||||||
|
JavaTXCompiler 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<>();
|
||||||
|
|
||||||
generatedGenerics = lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst());
|
// for (var sf : compiler.sourceFiles.values()) {
|
||||||
|
// 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, lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst()).get(i)));
|
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
||||||
}
|
}
|
||||||
System.setOut(System.out);
|
System.setOut(System.out);
|
||||||
this.current = lsTransfer;
|
this.current = new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
||||||
|
|
||||||
|
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
||||||
|
|
||||||
|
for (PlaceholderVariable insert : tips) {
|
||||||
|
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
||||||
|
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
||||||
|
} else {
|
||||||
|
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inserts = insertsOnLines;
|
||||||
|
|
||||||
|
logger.info("TYPES ARE:");
|
||||||
|
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.point.getInsertString())));
|
||||||
|
ArrayList<LSPVariable> variables = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
HashMap<String, Type> uniqueType = new HashMap<>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
for (Type t : variable.getPossibleTypes()) {
|
||||||
|
logger.info(t.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayList<LSPVariable> infereIncremental(List<ResultSet> newResultSet, List<GenericsResult> generatedGenerics, SourceFile ast) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
logger.info("HMMMMMMMMMMMMM");
|
||||||
|
var parsedSource = ast;
|
||||||
|
var tiResults = newResultSet;
|
||||||
|
Set<PlaceholderVariable> tips = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < tiResults.size(); i++) {
|
||||||
|
ResultSet tiResult = tiResults.get(i);
|
||||||
|
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("OKI DOKI ALLES ERSTELLT");
|
||||||
|
System.setOut(System.out);
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
||||||
|
|
||||||
@@ -239,4 +321,8 @@ public class TypeResolver {
|
|||||||
logger.info(ASTPrinter.print(current.getAst()));
|
logger.info(ASTPrinter.print(current.getAst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCurrent(List<ResultSet> resultSets){
|
||||||
|
current.getResultSets().addAll(resultSets);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -12,10 +12,6 @@ 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;
|
||||||
@@ -42,6 +38,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
|
||||||
|
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return this == obj;
|
return this == obj;
|
||||||
/*
|
/*
|
||||||
|
@@ -12,8 +12,6 @@ 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;
|
||||||
@@ -40,9 +38,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
@@ -55,10 +55,6 @@ 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:
|
||||||
|
Reference in New Issue
Block a user