Compare commits
1 Commits
position-a
...
onlySyntac
Author | SHA1 | Date | |
---|---|---|---|
|
f5cdda7625 |
@@ -9,7 +9,3 @@ vsc-extension-quickstart.md
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/.vscode-test.*
|
||||
|
||||
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||
|
||||
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||
|
Binary file not shown.
@@ -1 +1,44 @@
|
||||
LSP-Client for Java-TX
|
||||
# Welcome to your VS Code Extension
|
||||
|
||||
## What's in the folder
|
||||
|
||||
* This folder contains all of the files necessary for your extension.
|
||||
* `package.json` - this is the manifest file in which you declare your extension and command.
|
||||
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
|
||||
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
|
||||
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
|
||||
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
|
||||
|
||||
## Get up and running straight away
|
||||
|
||||
* Press `F5` to open a new window with your extension loaded.
|
||||
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
|
||||
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
|
||||
* Find output from your extension in the debug console.
|
||||
|
||||
## Make changes
|
||||
|
||||
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
|
||||
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
|
||||
|
||||
## Explore the API
|
||||
|
||||
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
|
||||
|
||||
## Run tests
|
||||
|
||||
* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner)
|
||||
* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered.
|
||||
* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A`
|
||||
* See the output of the test result in the Test Results view.
|
||||
* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder.
|
||||
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
|
||||
* You can create folders inside the `test` folder to structure your tests any way you want.
|
||||
|
||||
## Go further
|
||||
|
||||
* [Follow UX guidelines](https://code.visualstudio.com/api/ux-guidelines/overview) to create extensions that seamlessly integrate with VS Code's native interface and patterns.
|
||||
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
|
||||
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace.
|
||||
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).
|
||||
* Integrate to the [report issue](https://code.visualstudio.com/api/get-started/wrapping-up#issue-reporting) flow to get issue and feature requests reported by users.
|
||||
|
Binary file not shown.
@@ -1,12 +1,10 @@
|
||||
package de.dhbw;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.dhbw.handler.UpdatePositionHandler;
|
||||
import de.dhbw.helper.CodeSnippetOptions;
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbw.model.LineCharPosition;
|
||||
import de.dhbw.model.SnippetWithName;
|
||||
import de.dhbw.model.Type;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
@@ -16,7 +14,6 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.lsp4j.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Message;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||
|
||||
@@ -29,7 +26,6 @@ import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@@ -37,30 +33,18 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService {
|
||||
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(JavaTXTextDocumentService.class);
|
||||
LanguageClient client;
|
||||
HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
|
||||
Boolean currentlyCalculating = false;
|
||||
HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
|
||||
HashMap<String, String> textDocuments = new HashMap<>();
|
||||
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
||||
TextHelper textHelper = new TextHelper();
|
||||
Boolean dontShowHints = false;
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
Path fileRoot = null;
|
||||
Boolean singleFileOpened = false;
|
||||
List<LSPVariable> variables = new ArrayList<>();
|
||||
|
||||
public void setClient(LanguageClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void setFileRoot(List<WorkspaceFolder> root) {
|
||||
|
||||
if (root == null) {
|
||||
singleFileOpened = true;
|
||||
}
|
||||
//TODO: Nicht nur das erste Element nehmen sondern alle beachten
|
||||
fileRoot = Path.of(URI.create(root.get(0).getUri()));
|
||||
}
|
||||
|
||||
@@ -84,6 +68,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
completions.add(item);
|
||||
}
|
||||
|
||||
|
||||
return CompletableFuture.completedFuture(Either.forLeft(completions));
|
||||
}
|
||||
|
||||
@@ -99,67 +84,6 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> difference(String first, String second) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
int i = 0, j = 0;
|
||||
int startDiff = -1;
|
||||
|
||||
while (j < second.length()) {
|
||||
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
||||
if (startDiff != -1) {
|
||||
result.add(second.substring(startDiff, j));
|
||||
startDiff = -1;
|
||||
}
|
||||
i++;
|
||||
j++;
|
||||
} else {
|
||||
if (startDiff == -1) {
|
||||
startDiff = j;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
if (startDiff != -1) {
|
||||
result.add(second.substring(startDiff));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<LineCharPosition, String> differenceLinePos(String first, String second, int line) {
|
||||
Map<LineCharPosition, String> result = new HashMap<>();
|
||||
int i = 0, j = 0;
|
||||
int startDiff = -1;
|
||||
|
||||
while (j < second.length()) {
|
||||
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
||||
if (startDiff != -1) {
|
||||
String diff = second.substring(startDiff, j);
|
||||
result.put(new LineCharPosition(line, startDiff), diff);
|
||||
startDiff = -1;
|
||||
}
|
||||
i++;
|
||||
j++;
|
||||
} else {
|
||||
if (startDiff == -1) {
|
||||
startDiff = j;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
if (startDiff != -1) {
|
||||
String diff = second.substring(startDiff);
|
||||
result.put(new LineCharPosition(line, startDiff), diff);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles didChange-Event.
|
||||
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
||||
@@ -168,39 +92,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
*/
|
||||
@Override
|
||||
public void didChange(DidChangeTextDocumentParams params) {
|
||||
log("[didChange] Client triggered didChange Event.", MessageType.Info);
|
||||
|
||||
|
||||
//TODO: Regenerate if Line-Count does not match -> Return new AST and see where the Positions are instead of calculating them from changes in Text-Document. Even possible?
|
||||
|
||||
String currentText = textDocuments.get(params.getTextDocument().getUri());
|
||||
ArrayList<String> currentTextLines = new ArrayList<>(Arrays.stream(currentText.split("\n")).toList());
|
||||
HashMap<LineCharPosition, String> preciseChanges = new HashMap<>();
|
||||
String newText = params.getContentChanges().getFirst().getText();
|
||||
ArrayList<String> newTextLines = new ArrayList<>(Arrays.stream(newText.split("\n")).toList());
|
||||
|
||||
|
||||
|
||||
ArrayList<Integer> offsetPerLine = new ArrayList<>();
|
||||
HashMap<Integer, List<String>> textChanges = new HashMap<>();
|
||||
int index = 0;
|
||||
for (String newTextLine : newTextLines) {
|
||||
if (!(currentTextLines.size() > index)) {
|
||||
offsetPerLine.add(0);
|
||||
} else {
|
||||
|
||||
|
||||
Map<LineCharPosition, String> lineDiffs = differenceLinePos(currentTextLines.get(index), newTextLine, index);
|
||||
preciseChanges.putAll(lineDiffs);
|
||||
|
||||
textChanges.put(index, difference(currentTextLines.get(index), newTextLine).stream().map(el -> el.replaceAll(" ", "")).toList());
|
||||
client.logMessage(new MessageParams(MessageType.Info, "For Line " + index + " difference of " + (newTextLine.length() - currentTextLines.get(index).length())));
|
||||
offsetPerLine.add(newTextLine.length() - currentTextLines.get(index).length());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
client.logMessage(new MessageParams(MessageType.Info,"[didChange] Client triggered didChange Event."));
|
||||
|
||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||
@@ -212,7 +104,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
List<ParserError> parserErrors = parserInterface.getParseErrors(input);
|
||||
|
||||
List<Diagnostic> diagnosticsList = parserErrors.stream().map(el -> {
|
||||
List<Diagnostic> diagnostics = parserErrors.stream().map(el -> {
|
||||
Range errorRange = new Range(
|
||||
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
|
||||
new Position(el.getLine() - 1, el.getEndCharPosition()) // Endposition
|
||||
@@ -225,73 +117,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
);
|
||||
}).toList();
|
||||
|
||||
client.publishDiagnostics(new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnosticsList));
|
||||
|
||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||
client.publishDiagnostics(diagnosticsParams);
|
||||
|
||||
typeResolver.reduceCurrent(preciseChanges, variables, client);
|
||||
//Reduce and display Typehints and Diagnostics
|
||||
|
||||
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
||||
try {
|
||||
if (textDocuments.get(params.getTextDocument().getUri()) == null) {
|
||||
log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||
}
|
||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(params.getTextDocument().getUri()), params.getTextDocument().getUri());
|
||||
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
|
||||
for (var variable : typesOfMethodAndParameters) {
|
||||
|
||||
InlayHint inlayHint = getInlayHint(variable);
|
||||
inlayHint.getPosition().setCharacter(inlayHint.getPosition().getCharacter() + offsetPerLine.get(inlayHint.getPosition().getLine()));
|
||||
typeHint.add(inlayHint);
|
||||
|
||||
|
||||
//Diagnostics of Types
|
||||
for (var type : variable.getPossibleTypes()) {
|
||||
Diagnostic diagnostic = getDiagnostic(variable, params.getTextDocument().getUri(), type);
|
||||
diagnostic.getRange().getStart().setCharacter(diagnostic.getRange().getStart().getCharacter() + offsetPerLine.get(diagnostic.getRange().getStart().getLine()));
|
||||
diagnostic.getRange().getEnd().setCharacter(diagnostic.getRange().getEnd().getCharacter() + offsetPerLine.get(diagnostic.getRange().getEnd().getLine()));
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
globalDiagnosticsMap.put(params.getTextDocument().getUri(), diagnostics);
|
||||
globalInlayHintMap.put(params.getTextDocument().getUri(), typeHint);
|
||||
// updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||
client.showMessage(new MessageParams(MessageType.Error, e.getMessage()));
|
||||
updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
currentlyCalculating = false;
|
||||
sWatch.stop();
|
||||
log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||
}
|
||||
|
||||
globalInlayHintMap.put(params.getTextDocument().getUri(), globalInlayHintMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||
//TODO: Hier das Label aufspalten an | weil die Typehints immer mit und getrennt sind und so jeder Typhint für sich durchlaufen werden kann.
|
||||
log(el.getLabel().getLeft().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getPosition().getLine())) + ": " + (!textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||
return !textChanges.get(el.getPosition().getLine()).contains(el.getLabel().getLeft().replaceAll(" ", ""));
|
||||
}).toList());
|
||||
|
||||
globalDiagnosticsMap.put(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri()).stream().filter(el -> {
|
||||
log(el.getMessage().replaceAll(" ", "") + "<>" + String.join(",", textChanges.get(el.getRange().getStart().getLine())) + ": " + (!textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", "")) ? "true" : "false"), MessageType.Info);
|
||||
return !textChanges.get(el.getRange().getStart().getLine()).contains(el.getMessage().replaceAll(" ", ""));
|
||||
}).toList());
|
||||
|
||||
|
||||
|
||||
updateClient(client);
|
||||
client.publishDiagnostics(new PublishDiagnosticsParams(params.getTextDocument().getUri(), globalDiagnosticsMap.get(params.getTextDocument().getUri())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,184 +130,20 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
*/
|
||||
@Override
|
||||
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
|
||||
log("[formatting] Client requested formatting.", MessageType.Info);
|
||||
|
||||
List<TextEdit> edits = new ArrayList<>();
|
||||
|
||||
|
||||
String[] lines = textDocuments.get(params.getTextDocument().getUri()).split("\n");
|
||||
StringBuilder formattedText = new StringBuilder();
|
||||
|
||||
for (String line : lines) {
|
||||
formattedText.append(line.stripTrailing()).append("\n");
|
||||
}
|
||||
|
||||
TextEdit edit = new TextEdit();
|
||||
edit.setRange(new Range(new Position(0, 0), new Position(lines.length, 0)));
|
||||
edit.setNewText(formattedText.toString().trim());
|
||||
|
||||
edits.add(edit);
|
||||
return CompletableFuture.completedFuture(edits);
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didClose(DidCloseTextDocumentParams params) {
|
||||
}
|
||||
|
||||
private void log(String message, MessageType type) {
|
||||
client.logMessage(new MessageParams(type, message));
|
||||
switch (type) {
|
||||
case Error -> logger.error(message);
|
||||
case Warning -> logger.warn(message);
|
||||
case Info -> logger.info(message);
|
||||
default -> logger.debug(message);
|
||||
}
|
||||
}
|
||||
|
||||
private InlayHint getInlayHint(LSPVariable variable) {
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
|
||||
String typeDisplay = "";
|
||||
for (Type type : variable.getPossibleTypes()) {
|
||||
typeDisplay += " | " + type.getType().replaceAll("GTV ", "");
|
||||
}
|
||||
|
||||
|
||||
inlayHint.setLabel(typeDisplay.length() > 2 ? typeDisplay.substring(2) : typeDisplay);
|
||||
inlayHint.setPosition(new Position(variable.getLine() - 1, variable.getCharPosition()));
|
||||
inlayHint.setKind(InlayHintKind.Parameter);
|
||||
inlayHint.setPaddingRight(true);
|
||||
inlayHint.setPaddingRight(true);
|
||||
return inlayHint;
|
||||
}
|
||||
|
||||
private Diagnostic getDiagnostic(LSPVariable variable, String fileUri, Type type) {
|
||||
Range errorRange = new Range(
|
||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), textDocuments.get(fileUri))) // Endposition
|
||||
);
|
||||
Diagnostic diagnostic = new Diagnostic(
|
||||
errorRange,
|
||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
||||
type.getType().replaceAll("GTV ", ""),
|
||||
DiagnosticSeverity.Hint,
|
||||
"JavaTX Language Server"
|
||||
);
|
||||
diagnostic.setCode(type.isGeneric() ? "GENERIC" : "TYPE");
|
||||
|
||||
return diagnostic;
|
||||
}
|
||||
|
||||
private void updateGlobalMaps(List<Diagnostic> diagnostics, List<InlayHint> typeHint, String uri) {
|
||||
globalDiagnosticsMap.put(uri, diagnostics);
|
||||
globalInlayHintMap.put(uri, typeHint);
|
||||
}
|
||||
|
||||
private void updateClient(LanguageClient client) {
|
||||
client.refreshInlayHints();
|
||||
client.refreshDiagnostics();
|
||||
}
|
||||
|
||||
private void startLoading(String taskName, String title, LanguageClient client) {
|
||||
Either<String, Integer> token = Either.forLeft(taskName);
|
||||
client.createProgress(new WorkDoneProgressCreateParams(token));
|
||||
|
||||
WorkDoneProgressBegin begin = new WorkDoneProgressBegin();
|
||||
begin.setTitle(title);
|
||||
begin.setCancellable(false);
|
||||
begin.setPercentage(0);
|
||||
|
||||
ProgressParams beginParams = new ProgressParams(token, Either.forLeft(begin));
|
||||
client.notifyProgress(beginParams);
|
||||
|
||||
}
|
||||
|
||||
private void stopLoading(String taskName, String title, LanguageClient client) {
|
||||
Either<String, Integer> token = Either.forLeft(taskName);
|
||||
WorkDoneProgressEnd end = new WorkDoneProgressEnd();
|
||||
end.setMessage(title);
|
||||
|
||||
ProgressParams endParams = new ProgressParams(token, Either.forLeft(end));
|
||||
client.notifyProgress(endParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||
log("[didSave] Client triggered didSave-Event.", MessageType.Info);
|
||||
|
||||
startLoading("compile-task", "Inferring types...", client);
|
||||
|
||||
if (!currentlyCalculating) {
|
||||
currentlyCalculating = true;
|
||||
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
|
||||
try {
|
||||
typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()));
|
||||
if (textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()) == null) {
|
||||
log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||
}
|
||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(didSaveTextDocumentParams.getTextDocument().getUri()), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
|
||||
variables = typesOfMethodAndParameters;
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
|
||||
for (var variable : typesOfMethodAndParameters) {
|
||||
|
||||
InlayHint inlayHint = getInlayHint(variable);
|
||||
typeHint.add(inlayHint);
|
||||
|
||||
|
||||
//Diagnostics of Types
|
||||
for (var type : variable.getPossibleTypes()) {
|
||||
Diagnostic diagnostic = getDiagnostic(variable, didSaveTextDocumentParams.getTextDocument().getUri(), type);
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
|
||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(didSaveTextDocumentParams.getTextDocument().getUri(), diagnostics);
|
||||
client.publishDiagnostics(diagnosticsParams);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||
client.showMessage(new MessageParams(MessageType.Error, e.getMessage()));
|
||||
updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
currentlyCalculating = false;
|
||||
sWatch.stop();
|
||||
log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
stopLoading("compile-task", "Types successfully inferred", client);
|
||||
|
||||
dontShowHints = false;
|
||||
updateClient(client);
|
||||
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
|
||||
if (fileRoot != null) {
|
||||
try (Stream<Path> stream = Files.walk(Paths.get(fileRoot.toUri()))) {
|
||||
stream.filter(Files::isRegularFile)
|
||||
.forEach(el -> files.add(el.toFile()));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
||||
log("[inlayHint] The Client requested Inlay-Hints.", MessageType.Info);
|
||||
return CompletableFuture.supplyAsync(() -> dontShowHints ? Collections.emptyList() : globalInlayHintMap.get(params.getTextDocument().getUri()) == null ? Collections.emptyList() : globalInlayHintMap.get(params.getTextDocument().getUri()));
|
||||
}
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());}
|
||||
|
||||
@Override
|
||||
public void willSave(WillSaveTextDocumentParams params) {
|
||||
@@ -609,99 +274,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
||||
|
||||
log("[codeAction] Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].", MessageType.Info);
|
||||
|
||||
log("Code-Action Context was: " + params.getContext().getTriggerKind().name(), MessageType.Info);
|
||||
|
||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||
|
||||
|
||||
List<Diagnostic> diagnosticInCurrentDocument = params.getContext().getDiagnostics();
|
||||
Range requestedRange = params.getRange();
|
||||
|
||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||
List<Diagnostic> diagnosticsOverlappingHover = diagnosticInCurrentDocument.stream()
|
||||
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
||||
|
||||
Range rangeOfInsert = params.getRange();
|
||||
|
||||
|
||||
String documentUri = params.getTextDocument().getUri();
|
||||
|
||||
|
||||
for (Diagnostic typeDiagnostic : diagnosticsOverlappingHover) {
|
||||
try {
|
||||
String typeWithReplacedVariable = typeDiagnostic.getMessage() +
|
||||
" " +
|
||||
textHelper.getTextOfChars(
|
||||
textDocuments.get(params.getTextDocument().getUri()),
|
||||
rangeOfInsert.getStart().getLine(),
|
||||
rangeOfInsert.getStart().getCharacter(),
|
||||
rangeOfInsert.getEnd().getCharacter()
|
||||
);
|
||||
|
||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||
|
||||
if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
||||
for (var diagnostic : globalDiagnosticsMap.get(params.getTextDocument().getUri())) {
|
||||
|
||||
if (diagnostic.getMessage().contains(typeDiagnostic.getMessage()) || typeDiagnostic.getMessage().contains(diagnostic.getMessage())) {
|
||||
String genericType = diagnostic.getMessage() +
|
||||
" " +
|
||||
textHelper.getTextOfChars(
|
||||
textDocuments.get(params.getTextDocument().getUri()),
|
||||
diagnostic.getRange().getStart().getLine(),
|
||||
diagnostic.getRange().getStart().getCharacter(),
|
||||
diagnostic.getRange().getEnd().getCharacter()
|
||||
);
|
||||
listOfChanges.add(new TextEdit(diagnostic.getRange(), genericType));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
listOfChanges.add(new TextEdit(rangeOfInsert, typeWithReplacedVariable));
|
||||
}
|
||||
|
||||
var isTypeImported = false;
|
||||
|
||||
if (!typeDiagnostic.getCode().getLeft().equalsIgnoreCase("generic")) {
|
||||
isTypeImported = typeResolver.isTypeImported(textDocuments.get(params.getTextDocument().getUri()), typeDiagnostic.getMessage());
|
||||
}
|
||||
if (!isTypeImported && !typeDiagnostic.getMessage().equals("void") && !typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
||||
Range importRange = new Range(new Position(0, 0), new Position(0, 0));
|
||||
|
||||
var typeWithoutGenerics = typeDiagnostic.getMessage().contains("<") ? typeDiagnostic.getMessage().substring(0, typeDiagnostic.getMessage().indexOf('<')) : typeDiagnostic.getMessage();
|
||||
listOfChanges.add(new TextEdit(importRange, "import " + typeWithoutGenerics + ";\n"));
|
||||
}
|
||||
|
||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||
changes.put(documentUri, listOfChanges);
|
||||
|
||||
WorkspaceEdit edit = new WorkspaceEdit();
|
||||
edit.setChanges(changes);
|
||||
|
||||
CodeAction action = new CodeAction("Insert " + typeDiagnostic.getMessage());
|
||||
action.setKind(CodeActionKind.QuickFix);
|
||||
action.setEdit(edit);
|
||||
actions.add(Either.forRight(action));
|
||||
} catch (Exception e) {
|
||||
log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return actions;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private boolean rangesOverlap(Range range1, Range range2) {
|
||||
int start1 = range1.getStart().getLine() * 1000 + range1.getStart().getCharacter();
|
||||
int end1 = range1.getEnd().getLine() * 1000 + range1.getEnd().getCharacter();
|
||||
int start2 = range2.getStart().getLine() * 1000 + range2.getStart().getCharacter();
|
||||
int end2 = range2.getEnd().getLine() * 1000 + range2.getEnd().getCharacter();
|
||||
|
||||
return start1 <= end2 && start2 <= end1;
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,96 +0,0 @@
|
||||
package de.dhbw.handler;
|
||||
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.InlayHint;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdatePositionHandler {
|
||||
|
||||
public static List<InlayHint> adjustInlayHintPositions(List<InlayHint> oldHints, List<String> newTextLines) {
|
||||
List<InlayHint> adjusted = new ArrayList<>();
|
||||
|
||||
for (InlayHint hint : oldHints) {
|
||||
Position oldPos = hint.getPosition();
|
||||
int oldLine = oldPos.getLine();
|
||||
String variableName = extractVariableNameFromHint(hint); // z. B. durch .getLabel()
|
||||
|
||||
int searchStart = Math.max(0, oldLine - 3);
|
||||
int searchEnd = Math.min(newTextLines.size(), oldLine + 3);
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for (int i = searchStart; i < searchEnd; i++) {
|
||||
String lineText = newTextLines.get(i);
|
||||
int column = lineText.indexOf(variableName);
|
||||
if (column >= 0) {
|
||||
Position newPos = new Position(i, column + variableName.length());
|
||||
InlayHint adjustedHint = new InlayHint(newPos, hint.getLabel());
|
||||
adjustedHint.setKind(hint.getKind());
|
||||
adjustedHint.setPaddingLeft(false);
|
||||
adjustedHint.setPaddingRight(true);
|
||||
adjusted.add(adjustedHint);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
adjusted.add(hint); // fallback: alte Position beibehalten
|
||||
}
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
private static String extractVariableNameFromHint(InlayHint hint) {
|
||||
// Beispiel: wenn dein Hint-Label z. B. "String ↤" ist, brauchst du Logik, um den Namen zu bestimmen
|
||||
// Wenn du nur Typen zeigst, kannst du Position - Name aus anderer Quelle kombinieren
|
||||
// Temporär: nutze z. B. eine Custom-Property
|
||||
return hint.getLabel().getLeft(); // Pseudocode, je nach Labelstruktur anpassen
|
||||
}
|
||||
|
||||
public static List<Diagnostic> adjustDiagnosticPositions(List<Diagnostic> oldDiagnostics, List<String> newTextLines) {
|
||||
List<Diagnostic> adjusted = new ArrayList<>();
|
||||
|
||||
for (Diagnostic diag : oldDiagnostics) {
|
||||
String keyword = extractKeywordFromDiagnostic(diag); // z. B. "inferred type"
|
||||
|
||||
int oldLine = diag.getRange().getStart().getLine();
|
||||
int searchStart = Math.max(0, oldLine - 3);
|
||||
int searchEnd = Math.min(newTextLines.size(), oldLine + 3);
|
||||
|
||||
boolean found = false;
|
||||
for (int i = searchStart; i < searchEnd; i++) {
|
||||
String lineText = newTextLines.get(i);
|
||||
int col = lineText.indexOf(keyword);
|
||||
if (col >= 0) {
|
||||
Range newRange = new Range(new Position(i, col), new Position(i, col + keyword.length()));
|
||||
Diagnostic adjustedDiag = new Diagnostic(newRange, diag.getMessage(), diag.getSeverity(), diag.getCode().getLeft(), diag.getSource());
|
||||
adjusted.add(adjustedDiag);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
adjusted.add(diag); // fallback
|
||||
}
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
private static String extractKeywordFromDiagnostic(Diagnostic diag) {
|
||||
// z. B. mit Regex oder fixer Konvention aus message
|
||||
return "type"; // Beispiel
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ public class TextHelper {
|
||||
|
||||
for (int i = startChar; i < linesInChar.length; i++) {
|
||||
|
||||
|
||||
if(linesInChar[i].contains("{")){
|
||||
index = i;
|
||||
found = true;
|
||||
@@ -74,6 +75,7 @@ public class TextHelper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return index-1;
|
||||
}
|
||||
|
||||
|
@@ -12,15 +12,11 @@ import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.lsp4j.MessageParams;
|
||||
import org.eclipse.lsp4j.MessageType;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -33,19 +29,6 @@ public class TypeResolver {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
||||
|
||||
private List<LSPVariable> currentTypes = new ArrayList<>();
|
||||
|
||||
private final boolean ENABLE_GENERICS = false;
|
||||
|
||||
private LanguageServerTransferObject current;
|
||||
|
||||
public LanguageServerTransferObject getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public void reduceCurrent() {
|
||||
current.getResultSets().removeFirst();
|
||||
}
|
||||
|
||||
private List<ResultSet> currentResults = new ArrayList<>();
|
||||
|
||||
@@ -64,8 +47,19 @@ public class TypeResolver {
|
||||
public TypeResolver() {
|
||||
}
|
||||
|
||||
public void updatePositions(String path, String input){
|
||||
LanguageServerTransferObject obj = new LanguageServerInterface().getResultSetAndAbstractSyntax(path, input);
|
||||
|
||||
private LanguageServerTransferObject getCacheOrCalculate(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
logger.info("Trying to find cached Compiler-Answer for input with key [" + input.hashCode() + "].");
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
if (dataCache.containsKey(input.hashCode())) {
|
||||
logger.info("Found Cache for the Input with key [" + input.hashCode() + "].");
|
||||
return dataCache.get(input.hashCode());
|
||||
} else {
|
||||
logger.info("Could not find Cache for Input with key [" + input.hashCode() + "]. Using Compiler Interface and Saving the Answer in Cache.");
|
||||
var transferObject = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
dataCache.put(input.hashCode(), transferObject);
|
||||
return transferObject;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTypeImported(String input, String type) {
|
||||
@@ -192,124 +186,70 @@ public class TypeResolver {
|
||||
return genericTypes;
|
||||
}
|
||||
|
||||
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
current = transferObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zum Erhalt für sowohl Parameter als auch Methoden.
|
||||
*/
|
||||
public ArrayList<LSPVariable> infereInput(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
logger.info("Infering Types for Input.");
|
||||
|
||||
LanguageServerTransferObject transferObj;
|
||||
|
||||
if (current == null) {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
current = transferObj;
|
||||
} else {
|
||||
transferObj = current;
|
||||
}
|
||||
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
|
||||
if (!transferObj.getResultSets().isEmpty()) {
|
||||
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
//GENERICS OF CLASS
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||
//GENERICS OF CLASS
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
|
||||
|
||||
for (var clazz : transferObj.getAst().getClasses()) {
|
||||
ArrayList<Type> genericTypes = getClassGenerics(transferObj.getGeneratedGenerics(), method, clazz);
|
||||
TextHelper helper = new TextHelper();
|
||||
if (!genericTypes.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPClass("test", genericTypes, clazz.getOffset().getLine(), helper.getClassPositionForGeneric(clazz.getOffset().getLine() - 1, input, clazz.getOffset().getStopIndex()), clazz.getOffset().getStopIndex(), clazz.getReturnType()));
|
||||
}
|
||||
}
|
||||
|
||||
for (var clazz : transferObj.getAst().getClasses()) {
|
||||
ArrayList<Type> genericTypes = getClassGenerics(transferObj.getGeneratedGenerics(), method, clazz);
|
||||
TextHelper helper = new TextHelper();
|
||||
if (!genericTypes.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPClass("test", genericTypes, clazz.getOffset().getLine(), helper.getClassPositionForGeneric(clazz.getOffset().getLine() - 1, input, clazz.getOffset().getStopIndex()), clazz.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
var types = getAvailableTypes(transferObj.getResultSets(), method);
|
||||
var generics = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
||||
}
|
||||
|
||||
if (!filterOutDuplicates(types).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
var types = getAvailableTypes(transferObj.getResultSets(), method);
|
||||
var generics = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
||||
|
||||
if (!filterOutDuplicates(types).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
if (!generics.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(generics, types);
|
||||
typesThatAreGeneric.forEach(el -> el.setType("<" + el.getType() + "> " + el.getType()));
|
||||
//TODO: Muss Global und wird mehrmals so gemacht. Das if hier ist eigentlich falsch wegen unnötiger Berechnungszeit
|
||||
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
for (var param : method.getParameterList()) {
|
||||
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||
|
||||
if (!typeParam.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
if (!generics.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(generics, types);
|
||||
typesThatAreGeneric.forEach(el -> el.setType("<" + el.getType() + "> " + el.getType()));
|
||||
//TODO: Muss Global und wird mehrmals so gemacht. Das if hier ist eigentlich falsch wegen unnötiger Berechnungszeit
|
||||
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var param : method.getParameterList()) {
|
||||
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||
|
||||
if (!typeParam.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||
}
|
||||
|
||||
if (ENABLE_GENERICS) {
|
||||
if (!genericParam.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
||||
if (!genericParam.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
||||
|
||||
|
||||
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex(), param.getType()));
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, new ArrayList<>(filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex(), method.getReturnType()));
|
||||
}
|
||||
}
|
||||
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, new ArrayList<>(filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTypes.addAll(methodsWithParametersLSPVariableList);
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
|
||||
public void updateTypehints(String input, String path) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
LanguageServerTransferObject transferObj;
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||
var ast = transferObj.getAst();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables, LanguageClient client) {
|
||||
client.logMessage(new MessageParams(MessageType.Info, "Lenght is: " + combinedList.size()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPClass extends LSPVariable{
|
||||
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||
super(name, possibleTypes, line, charPosition, endPosition, originalTphName);
|
||||
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||
super(name, possibleTypes, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPMethod extends LSPVariable {
|
||||
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||
super(name, type, line, charPosition, endPosition, originalTphName);
|
||||
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||
super(name, type, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPParameter extends LSPVariable {
|
||||
public class LSPParameter extends LSPMethod {
|
||||
|
||||
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||
super(name, type, line, charPosition, endPosition, originalTphName);
|
||||
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||
super(name, type, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +1,20 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPVariable {
|
||||
String name;
|
||||
public class LSPVariable { String name;
|
||||
ArrayList<Type> possibleTypes;
|
||||
int line;
|
||||
int charPosition;
|
||||
int endPosition;
|
||||
boolean needsInference;
|
||||
RefTypeOrTPHOrWildcardOrGeneric originalTphName;
|
||||
|
||||
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||
this.name = name;
|
||||
this.possibleTypes = possibleTypes;
|
||||
this.line = line;
|
||||
this.charPosition = charPosition;
|
||||
this.endPosition = endPosition;
|
||||
this.originalTphName = originalTphName;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getOriginalTphName() {
|
||||
return originalTphName;
|
||||
}
|
||||
|
||||
public void setOriginalTphName(RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
||||
this.originalTphName = originalTphName;
|
||||
}
|
||||
|
||||
public int getEndPosition() {
|
||||
|
@@ -1,25 +0,0 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
public class LineCharPosition {
|
||||
public final int line;
|
||||
public final int charPosition;
|
||||
|
||||
public LineCharPosition(int line, int charPosition) {
|
||||
this.line = line;
|
||||
this.charPosition = charPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof LineCharPosition)) return false;
|
||||
LineCharPosition that = (LineCharPosition) o;
|
||||
return line == that.line && charPosition == that.charPosition;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Line " + line + ", Char " + charPosition;
|
||||
}
|
||||
}
|
@@ -1,39 +1,30 @@
|
||||
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CompilerInterfaceTest {
|
||||
|
||||
@Test
|
||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
var res = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
"public class test{\n" +
|
||||
"public main(test){" +
|
||||
"if(0>1){" +
|
||||
"return \"w\";" +
|
||||
"}" +
|
||||
"Integer i = 0;" +
|
||||
"return i;" +
|
||||
"}" +
|
||||
"}", "c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav");
|
||||
|
||||
var res2 = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
"public class test{\n" +
|
||||
"public main(test){" +
|
||||
"if(0>1){" +
|
||||
"return \"w\";" +
|
||||
"}" +
|
||||
"Integer i = 0;" +
|
||||
"return i;" +
|
||||
"}" +
|
||||
"}", "c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav");
|
||||
System.out.println("TEST OUTPUT:");
|
||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException {
|
||||
// LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
// var res = languageServer.getResultSetAndAbstractSyntax("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
// "public class test{\n" +
|
||||
// "public main(test){" +
|
||||
// "if(0>1){" +
|
||||
// "return \"w\";" +
|
||||
// "}" +
|
||||
// "Integer i = 0;" +
|
||||
// "return i;" +
|
||||
// "}" +
|
||||
// "}", "TEST");
|
||||
//
|
||||
// System.out.println("TEST OUTPUT:");
|
||||
//
|
||||
// ArrayList<String> allTypes = new ArrayList<>();
|
||||
//
|
||||
@@ -123,7 +114,7 @@ public class CompilerInterfaceTest {
|
||||
@Test
|
||||
public void testCharEnding() throws IOException, ClassNotFoundException {
|
||||
TextHelper textHelper = new TextHelper();
|
||||
var endingChar = textHelper.getEndingCharOfStartingChar(3, 13, "import java.lang.Integer;\n" +
|
||||
var endingChar = textHelper.getEndingCharOfStartingChar(3,13,"import java.lang.Integer;\n" +
|
||||
"import java.lang.String; \n" +
|
||||
"public class test{\n" +
|
||||
" public main(test, test2){\n" +
|
||||
|
@@ -11,7 +11,6 @@ public class JavaTXLanguageDocumentServiceTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testWordExtraction() {
|
||||
// JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
||||
// service.didSave(new DidSaveTextDocumentParams(new TextDocumentIdentifier("file:///c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav")));
|
||||
JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user