2 Commits

Author SHA1 Message Date
Ruben
7e6e968b0f feat: do not show 100 times the insert 2025-09-22 18:22:05 +02:00
Ruben
dded453ba3 feat: update jar and Version 2025-09-22 15:42:25 +02:00
3 changed files with 35 additions and 28 deletions

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.9", "version": "0.0.11",
"engines": { "engines": {
"vscode": "^1.94.0" "vscode": "^1.94.0"
}, },

View File

@@ -105,43 +105,50 @@ public class CodeActionHandler {
String documentUri = params.getTextDocument().getUri(); String documentUri = params.getTextDocument().getUri();
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 if (typeResolver.getInserts() != null) {
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter()); //All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
logService.log("Inserts are:"); Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
typeResolver.getInserts().forEach((key, value) -> logService.log(key)); logService.log("Inserts are:");
logService.log("Size is: " + typeInsertsOverlapping.size()); typeResolver.getInserts().forEach((key, value) -> logService.log(key));
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter()); logService.log("Size is: " + typeInsertsOverlapping.size());
List<Either<Command, CodeAction>> actions = new ArrayList<>(); logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
List<Either<Command, CodeAction>> actions = new ArrayList<>();
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("NEW TEXT OF FILE BEFORE INSERT IS:");
logService.log(textDocumentService.getFileOfUri(documentUri)); 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<>();
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable)); listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
var isTypeImported = false; var isTypeImported = false;
Map<String, List<TextEdit>> changes = new HashMap<>(); Map<String, List<TextEdit>> changes = new HashMap<>();
changes.put(documentUri, listOfChanges); changes.put(documentUri, listOfChanges);
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 " + conversionHelper.cleanType(typeInsert.getInsertString()));
action.setKind(CodeActionKind.QuickFix); action.setKind(CodeActionKind.QuickFix);
action.setEdit(edit); action.setEdit(edit);
actions.add(Either.forRight(action));
} catch (Exception e) { if(!actions.stream().map(el -> el.getRight().getTitle()).toList().contains(action.getTitle())){
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error); actions.add(Either.forRight(action));
}
} catch (Exception e) {
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
}
} }
} }
return actions;
} }
return actions;
return new ArrayList<>();
} }
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) { public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {