Compare commits

...

2 Commits

Author SHA1 Message Date
Ruben
60f8352fb4 Merge remote-tracking branch 'origin/main' 2024-11-19 18:38:16 +01:00
Ruben
397e9e4026 docs: add Java-Docs 2024-11-19 18:38:06 +01:00
6 changed files with 94 additions and 6 deletions

View File

@ -8,7 +8,11 @@ import org.eclipse.lsp4j.services.LanguageServer;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/**
*
* Configuration of the Language Server
*
* */
public class JavaTXLanguageServer implements LanguageServer { public class JavaTXLanguageServer implements LanguageServer {
private LanguageClient client; private LanguageClient client;
@ -21,6 +25,9 @@ public class JavaTXLanguageServer implements LanguageServer {
private final JavaTXTextDocumentService textDocumentService = new JavaTXTextDocumentService(); private final JavaTXTextDocumentService textDocumentService = new JavaTXTextDocumentService();
private final JavaTXWorkspaceService workspaceService = new JavaTXWorkspaceService(); private final JavaTXWorkspaceService workspaceService = new JavaTXWorkspaceService();
/**
* Configure the Features of the LanguageServer
* */
@Override @Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) { public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
ServerCapabilities capabilities = new ServerCapabilities(); ServerCapabilities capabilities = new ServerCapabilities();
@ -35,16 +42,25 @@ public class JavaTXLanguageServer implements LanguageServer {
return CompletableFuture.supplyAsync(() -> new InitializeResult(capabilities)); return CompletableFuture.supplyAsync(() -> new InitializeResult(capabilities));
} }
/**
* @return the TextDocumentService
* */
@Override @Override
public TextDocumentService getTextDocumentService() { public TextDocumentService getTextDocumentService() {
return textDocumentService; return textDocumentService;
} }
/**
* @return the WorkspaceService
* */
@Override @Override
public WorkspaceService getWorkspaceService() { public WorkspaceService getWorkspaceService() {
return workspaceService; return workspaceService;
} }
/**
* @return the Client
* */
public LanguageClient getClient() { public LanguageClient getClient() {
return client; return client;
} }

View File

@ -7,6 +7,11 @@ import org.eclipse.lsp4j.services.LanguageClient;
import java.util.HashSet; import java.util.HashSet;
/**
*
* Start the JavaTX language Server and use System In and System Out for Communication
*
* */
public class JavaTXLanguageServerLauncher { public class JavaTXLanguageServerLauncher {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -22,6 +22,11 @@ import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.antlr.v4.runtime.tree.ParseTreeWalker;
/**
*
* Handles Actions in Documents, such as Autocompletion, Change-Events and Syntax-Checks
*
* */
public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService { public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService {
LanguageClient client; LanguageClient client;
@ -33,6 +38,14 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
this.client = client; this.client = client;
} }
/**
*
* Handles Completion Events
*
* @param params the completion Context
* @return the Auto-Completion Items that will be displayed
* */
@Override @Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams params) { public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams params) {
List<CompletionItem> completions = new ArrayList<>(); List<CompletionItem> completions = new ArrayList<>();
@ -50,11 +63,23 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
return CompletableFuture.completedFuture(Either.forLeft(completions)); return CompletableFuture.completedFuture(Either.forLeft(completions));
} }
/**
*
* Handles didOpen Events
*
* @param params the Context of the newly opened Document
* */
@Override @Override
public void didOpen(DidOpenTextDocumentParams params) { public void didOpen(DidOpenTextDocumentParams params) {
client.showMessage(new MessageParams(MessageType.Info, "Datei geöffnet: " + params.getTextDocument().getUri())); client.showMessage(new MessageParams(MessageType.Info, "Datei geöffnet: " + params.getTextDocument().getUri()));
} }
/**
*
* Handles didChange
*
* @param params the Context of the Changed Document, including the incremental change as well as the whole Document
* */
@Override @Override
public void didChange(DidChangeTextDocumentParams params) { public void didChange(DidChangeTextDocumentParams params) {
@ -84,6 +109,12 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
} }
/**
*
* Handles a Formatting-Event
*
* @param params the Context of the Formatting
* */
@Override @Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) { public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
List<TextEdit> edits = new ArrayList<>(); List<TextEdit> edits = new ArrayList<>();
@ -196,8 +227,18 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
return null; return null;
} }
/**
*
* returns the whole Word of the selected Character - Currently not correctly working
*
* @param line the line of the Character
* @param character the character in the line
* @param document the Document-Content as String
*
* @return the String containing the Word
* */
public String getWordOfLineAndCharacter(int line, int character, String document) { public String getWordOfLineAndCharacter(int line, int character, String document) {
var textArr = document.split("\n"); var textArr = document.replace(";", " ; ").replace("{", " { ").replace("}", " } ").split("\n");
var selectedLine = textArr[line]; var selectedLine = textArr[line];
var hoverWord = ""; var hoverWord = "";
@ -207,13 +248,19 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
index += word.length(); index += word.length();
if (index - word.length() <= character && index >= character) { if (index - word.length() <= character && index >= character) {
hoverWord = word; hoverWord = word.replace(" ", "");
} }
} }
return hoverWord; return hoverWord;
} }
/**
*
* Handles a Hover-Event
*
* @param params the Context of the Hovering
* */
@Override @Override
public CompletableFuture<Hover> hover(HoverParams params) { public CompletableFuture<Hover> hover(HoverParams params) {

View File

@ -4,6 +4,11 @@ import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.services.WorkspaceService; import org.eclipse.lsp4j.services.WorkspaceService;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams; import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
/**
*
* Handles Actions in Workspace
*
* */
public class JavaTXWorkspaceService implements WorkspaceService { public class JavaTXWorkspaceService implements WorkspaceService {

View File

@ -4,6 +4,10 @@ import de.dhbw.model.SnippetWithName;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Helper-Class containing all Snippets
*
* */
public class CodeSnippetOptions { public class CodeSnippetOptions {
private ArrayList<SnippetWithName> snippets = new ArrayList<>(); private ArrayList<SnippetWithName> snippets = new ArrayList<>();

View File

@ -6,11 +6,22 @@ import java.util.Arrays;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
/**
* Helper-Class for finding the Type of a selected Word
*
* */
public class TypeFinder { public class TypeFinder {
/**
* find the Type of a specific Word, given by its line and character. The character must be any Part of the Word.
*
* DOES NOT WORK RIGHT NOW
*
* @param line the line of the character
* @param character the character of the character or the char-Number of the String
* @param currentTextDocument the String of the Content of the current Document.
* */
public String find(int line, int character, String currentTextDocument) { public String find(int line, int character, String currentTextDocument) {
String[] validTypes = { String[] validTypes = {