3 Commits

Author SHA1 Message Date
Ruben
c2cbd0aa92 fix: reduction of ResultSet now also bases on last saved File 2025-07-08 19:54:35 +02:00
Ruben
e1b000b976 fix: fix position adjustment 2025-07-08 19:28:06 +02:00
RubenKraft
7de2b2764a Merge pull request 'refactor' (#37) from refactor into main
Reviewed-on: #37
2025-07-07 18:38:09 +00:00
4 changed files with 34 additions and 9 deletions

View File

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

View File

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

View File

@@ -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;
}
}

View File

@@ -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;
}