feat: changed package name and add Hover of hovered Element

This commit is contained in:
Ruben 2024-11-13 18:18:54 +01:00
parent 8acd8c7ff1
commit 782ea67831
18 changed files with 83 additions and 31 deletions

View File

@ -8,10 +8,38 @@
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.13.0</version>
<artifactId>antlr4</artifactId>
<version>4.11.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.172</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.0-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
@ -38,8 +66,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source> <!-- Stelle sicher, dass dies mit deiner installierten Java-Version übereinstimmt -->
<target>11</target>
<source>23</source>
<target>23</target>
</configuration>
</plugin>
@ -53,7 +81,7 @@
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dhbw.JavaTXLanguageServerLauncher</mainClass> <!-- Deine Main-Klasse -->
<mainClass>de.dhbw.JavaTXLanguageServerLauncher</mainClass> <!-- Deine Main-Klasse -->
</manifest>
</archive>
</configuration>

View File

@ -1,4 +1,4 @@
package com.dhbw;
package de.dhbw;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.services.LanguageClient;

View File

@ -1,16 +1,22 @@
package com.dhbw;
package de.dhbw;
import de.dhbw.compiler.syntaxtree.type.RefType;
import de.dhbw.compiler.typedeployment.KindOfTypeInsertPoint;
import de.dhbw.compiler.typedeployment.TypeInsert;
import de.dhbw.compiler.typedeployment.TypeInsertPoint;
import org.antlr.v4.runtime.Token;
import org.eclipse.lsp4j.launch.LSPLauncher;
import org.eclipse.lsp4j.services.LanguageClient;
import java.util.HashSet;
public class JavaTXLanguageServerLauncher {
public static void main(String[] args) {
try {
JavaTXLanguageServer server = new JavaTXLanguageServer();
var launcher = LSPLauncher.createServerLauncher(server, System.in, System.out);
LanguageClient client = launcher.getRemoteProxy();

View File

@ -1,18 +1,18 @@
package com.dhbw;
package de.dhbw;
import com.dhbw.helper.CodeSnippetOptions;
import com.dhbw.model.ParseError.DiagnoseErrorListener;
import com.dhbw.model.SnippetWithName;
import com.dhbw.parser.Java17Lexer;
import com.dhbw.parser.Java17Parser;
import com.dhbw.parser.Java17ParserBaseListener;
import de.dhbw.compiler.typedeployment.TypeInsert;
import de.dhbw.compiler.typedeployment.TypeInsertPoint;
import de.dhbw.helper.CodeSnippetOptions;
import de.dhbw.model.ParseError.DiagnoseErrorListener;
import de.dhbw.model.SnippetWithName;
import de.dhbw.parser.Java17Lexer;
import de.dhbw.parser.Java17Parser;
import de.dhbw.parser.Java17ParserBaseListener;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.TextDocumentService;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
@ -39,7 +39,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
List<CompletionItem> completions = new ArrayList<>();
for(SnippetWithName elem : codeSnippetOptions.getSnippets()) {
for (SnippetWithName elem : codeSnippetOptions.getSnippets()) {
CompletionItem item = new CompletionItem(elem.getName());
item.setKind(CompletionItemKind.Snippet);
item.setInsertText(elem.getSnippet());
@ -197,10 +197,29 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
return null;
}
public String getWordOfLineAndCharacter(int line, int character, String document) {
var textArr = document.split("\n");
var selectedLine = textArr[line];
var hoverWord = "";
var index = 0;
for (String word : selectedLine.split(" ")) {
index += word.length();
if (index - word.length() <= character && index >= character) {
hoverWord = word;
}
}
return hoverWord;
}
@Override
public CompletableFuture<Hover> hover(HoverParams params) {
String hoverText = "Test";
String hoverText = getWordOfLineAndCharacter(params.getPosition().getLine(), params.getPosition().getCharacter(), currentTextDocument);
// Verwende MarkupContent für den Hover-Inhalt
MarkupContent markupContent = new MarkupContent();
@ -213,7 +232,6 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
}
@Override
public CompletableFuture<SignatureHelp> signatureHelp(SignatureHelpParams params) {
return null;

View File

@ -1,4 +1,4 @@
package com.dhbw;
package de.dhbw;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.services.WorkspaceService;

View File

@ -1,6 +1,6 @@
package com.dhbw.helper;
package de.dhbw.helper;
import com.dhbw.model.SnippetWithName;
import de.dhbw.model.SnippetWithName;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package com.dhbw.model.ParseError;
package de.dhbw.model.ParseError;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATNConfigSet;

View File

@ -1,4 +1,4 @@
package com.dhbw.model;
package de.dhbw.model;
public class SnippetWithName {
private String name;

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.*;

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**

View File

@ -1,4 +1,4 @@
package com.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
package de.dhbw.parser;// Generated from /home/ruben/Documents/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**