Compare commits
2 Commits
ed26f869c3
...
async-comp
Author | SHA1 | Date | |
---|---|---|---|
|
0d50cf1517 | ||
|
39876f3866 |
@@ -155,7 +155,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||
logService.log("[didSave] Client triggered didSave-Event.");
|
||||
clientService.startLoading("compile-task", "Inferring types...", client);
|
||||
saveHandler.handleSave(didSaveTextDocumentParams);
|
||||
saveHandler.asyncHandle(didSaveTextDocumentParams);
|
||||
clientService.stopLoading("compile-task", "Types successfully inferred", client);
|
||||
clientService.updateClient(client);
|
||||
}
|
||||
|
@@ -1,16 +1,27 @@
|
||||
package de.dhbw.handler;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.dhbw.helper.ResultListener;
|
||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||
import de.dhbw.service.*;
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
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 java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
@@ -93,4 +104,28 @@ public class SaveHandler {
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -149,8 +149,7 @@ public class TypeResolver {
|
||||
logger.info("Path is for calculation: " + path.toString());
|
||||
var file = path.toFile();
|
||||
Files.createDirectories(path.getParent().resolve("out"));
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
|
||||
|
||||
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<>();
|
||||
@@ -224,6 +223,71 @@ public class TypeResolver {
|
||||
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<>();
|
||||
|
||||
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 void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
|
||||
|
||||
for (var lines : combinedList.entrySet()) {
|
||||
@@ -257,4 +321,8 @@ public class TypeResolver {
|
||||
logger.info(ASTPrinter.print(current.getAst()));
|
||||
}
|
||||
|
||||
public void updateCurrent(List<ResultSet> resultSets){
|
||||
current.getResultSets().addAll(resultSets);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user