Compare commits
3 Commits
refactor
...
c2cbd0aa92
Author | SHA1 | Date | |
---|---|---|---|
|
c2cbd0aa92 | ||
|
e1b000b976 | ||
|
7de2b2764a |
@@ -12,6 +12,7 @@ import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChangeHandler {
|
||||
|
||||
@@ -36,20 +37,34 @@ public class ChangeHandler {
|
||||
public void didChange(DidChangeTextDocumentParams params) {
|
||||
String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
||||
|
||||
DocumentChanges documentChanges = textDocumentService.calculateDifference(currentText, params.getContentChanges().getFirst().getText());
|
||||
HashMap<LineCharPosition, String> preciseChanges = documentChanges.getPreciseChanges();
|
||||
ArrayList<Integer> offsetPerLine = documentChanges.getOffsetPerLine();
|
||||
HashMap<Integer, List<String>> textChanges = documentChanges.getTextChanges();
|
||||
|
||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), summedUp.get());
|
||||
|
||||
DocumentChanges documentChanges = textDocumentService.calculateDifference(currentText, summedUp.get());
|
||||
HashMap<LineCharPosition, String> preciseChanges = documentChanges.getPreciseChanges();
|
||||
HashMap<Integer, List<String>> textChanges;
|
||||
ArrayList<Integer> offsetPerLine = documentChanges.getOffsetPerLine();
|
||||
|
||||
|
||||
//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());
|
||||
offsetPerLine = changesFromOldSave.getOffsetPerLine();
|
||||
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();
|
||||
|
||||
checkParser(input, params.getTextDocument().getUri());
|
||||
|
||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables(), clientService.getClient());
|
||||
typeResolver.reduceCurrent(preciseChanges, cacheService.getVariables());
|
||||
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
@@ -40,6 +40,7 @@ public class SaveHandler {
|
||||
try {
|
||||
|
||||
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
|
||||
if (fileInput == null) {
|
||||
|
@@ -101,17 +101,17 @@ public class TypeResolver {
|
||||
}
|
||||
|
||||
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables, LanguageClient client) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Lenght is: " + combinedList.size()));
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
|
||||
|
||||
for (var lines : combinedList.entrySet()) {
|
||||
var contentChange = lines.getValue();
|
||||
for (LSPVariable variable : variables) {
|
||||
for (Type typeOfVariable : variable.getPossibleTypes()) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "\"" + typeOfVariable.getType() + " : " + variable.getLine() + "\"< > \"" + contentChange + " : " + lines.getKey() + "\""));
|
||||
|
||||
if (typeOfVariable.getType().equalsIgnoreCase(contentChange.replaceAll(" ", ""))) {
|
||||
if (variable.getLine() - 1 == lines.getKey().line && variable.getCharPosition() == lines.getKey().charPosition) {
|
||||
current.getResultSets().removeIf(el -> !el.resolveType(variable.getOriginalTphName()).resolvedType.toString().equalsIgnoreCase(contentChange.replaceAll(" ", "")));
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Removing Resultset"));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
|
||||
public class CacheService {
|
||||
private HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
|
||||
private HashMap<String, String> lastSavedFiles = new HashMap<>();
|
||||
private Boolean currentlyCalculating = false;
|
||||
private HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
|
||||
private HashMap<String, String> textDocuments = new HashMap<>();
|
||||
@@ -42,6 +43,14 @@ public class CacheService {
|
||||
return singleFileOpened;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getLastSavedFiles() {
|
||||
return lastSavedFiles;
|
||||
}
|
||||
|
||||
public void setLastSavedFiles(HashMap<String, String> lastSavedFiles) {
|
||||
this.lastSavedFiles = lastSavedFiles;
|
||||
}
|
||||
|
||||
public CodeSnippetOptions getCodeSnippetOptions() {
|
||||
return codeSnippetOptions;
|
||||
}
|
||||
|
Reference in New Issue
Block a user