Compare commits

..

2 Commits

Author SHA1 Message Date
Ruben
028a005b01 Merge remote-tracking branch 'origin/main' 2024-11-07 16:19:30 +01:00
Ruben
1fbcc78085 feat: add CodeSnippets for main, for and foreach 2024-11-07 16:19:19 +01:00
3 changed files with 68 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package com.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;
@ -26,6 +28,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
String currentTextDocument;
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
public void setClient(LanguageClient client) {
this.client = client;
}
@ -34,11 +38,13 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams params) {
List<CompletionItem> completions = new ArrayList<>();
CompletionItem item = new CompletionItem("HelloWorld");
item.setKind(CompletionItemKind.Text);
item.setInsertText("Hello, JavaTX World!");
completions.add(item);
for(SnippetWithName elem : codeSnippetOptions.getSnippets()) {
CompletionItem item = new CompletionItem(elem.getName());
item.setKind(CompletionItemKind.Text);
item.setInsertText(elem.getSnippet());
completions.add(item);
}
client.showMessage(new MessageParams(MessageType.Info, "Returning completion suggestions: " + completions));
return CompletableFuture.completedFuture(Either.forLeft(completions));

View File

@ -0,0 +1,31 @@
package com.dhbw.helper;
import com.dhbw.model.SnippetWithName;
import java.util.ArrayList;
public class CodeSnippetOptions {
private ArrayList<SnippetWithName> snippets = new ArrayList<>();
public CodeSnippetOptions() {
snippets.add(getMainSnippet());
snippets.add(getForLoopSnippet());
snippets.add(getForEachSnippet());
}
public SnippetWithName getMainSnippet(){
return new SnippetWithName("main", "public main(args){\n System.out.println(\"Hello World\");\n}\n");
}
public SnippetWithName getForLoopSnippet(){
return new SnippetWithName("forLoop", "for(i = 0; i < list.size(); i++){\n\n}");
}
public SnippetWithName getForEachSnippet(){
return new SnippetWithName("forEachLoop", "for(el : list){\n\n}");
}
public ArrayList<SnippetWithName> getSnippets() {
return snippets;
}
}

View File

@ -0,0 +1,27 @@
package com.dhbw.model;
public class SnippetWithName {
private String name;
private String snippet;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSnippet() {
return snippet;
}
public void setSnippet(String snippet) {
this.snippet = snippet;
}
public SnippetWithName(String name, String snippet) {
this.name = name;
this.snippet = snippet;
}
}