Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ repositories {
}

dependencies {
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.12.0"
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.12.0"
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.20.0"
implementation "org.apache.groovy:groovy:4.0.26"
implementation "com.google.code.gson:gson:2.13.1"
implementation "io.github.classgraph:classgraph:4.8.179"
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/prominic/groovyls/GroovyServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.eclipse.lsp4j.TypeDefinitionParams;
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
Expand Down Expand Up @@ -359,7 +360,7 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
}

@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
public CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbol(WorkspaceSymbolParams params) {
WorkspaceSymbolProvider provider = new WorkspaceSymbolProvider(astVisitor);
return provider.provideWorkspaceSymbols(params.getQuery());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.codehaus.groovy.ast.ImportNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.ModuleNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.PropertyNode;
import org.codehaus.groovy.ast.VariableScope;
import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
Expand All @@ -48,6 +49,7 @@
import org.eclipse.lsp4j.CompletionContext;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.CompletionItemLabelDetails;
import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;
Expand Down Expand Up @@ -293,6 +295,9 @@ private void populateItemsFromPropertiesAndFields(List<PropertyNode> properties,
if (markdownDocs != null) {
item.setDocumentation(new MarkupContent(MarkupKind.MARKDOWN, markdownDocs));
}
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDescription(property.getType().getNameWithoutPackage());
item.setLabelDetails(labelDetails);
return item;
}).collect(Collectors.toList());
items.addAll(propItems);
Expand All @@ -312,6 +317,9 @@ private void populateItemsFromPropertiesAndFields(List<PropertyNode> properties,
if (markdownDocs != null) {
item.setDocumentation(new MarkupContent(MarkupKind.MARKDOWN, markdownDocs));
}
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDescription(field.getType().getNameWithoutPackage());
item.setLabelDetails(labelDetails);
return item;
}).collect(Collectors.toList());
items.addAll(fieldItems);
Expand All @@ -330,6 +338,17 @@ private void populateItemsFromMethods(List<MethodNode> methods, String memberNam
}).map(method -> {
CompletionItem item = new CompletionItem();
item.setLabel(method.getName());
String methodParams = "(";
for (Parameter p : method.getParameters()) {
methodParams += p.getType().getNameWithoutPackage() + ' ' + p.getName() + ", ";
}
if (!methodParams.equals("("))
methodParams = methodParams.substring(0, methodParams.length() - 2);
methodParams += ')';
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDetail(methodParams);
labelDetails.setDescription(method.getReturnType().getNameWithoutPackage());
item.setLabelDetails(labelDetails);
item.setKind(GroovyLanguageServerUtils.astNodeToCompletionItemKind(method));
String markdownDocs = GroovydocUtils.groovydocToMarkdownDescription(method.getGroovydoc());
if (markdownDocs != null) {
Expand Down Expand Up @@ -366,6 +385,9 @@ private void populateItemsFromVariableScope(VariableScope variableScope, String
CompletionItem item = new CompletionItem();
item.setLabel(variable.getName());
item.setKind(GroovyLanguageServerUtils.astNodeToCompletionItemKind((ASTNode) variable));
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDescription(variable.getType().getNameWithoutPackage());
item.setLabelDetails(labelDetails);
if (variable instanceof AnnotatedNode) {
AnnotatedNode annotatedVar = (AnnotatedNode) variable;
String markdownDocs = GroovydocUtils.groovydocToMarkdownDescription(annotatedVar.getGroovydoc());
Expand Down Expand Up @@ -437,7 +459,9 @@ private void populateTypes(ASTNode offsetNode, String namePrefix, Set<String> ex
CompletionItem item = new CompletionItem();
item.setLabel(classNode.getNameWithoutPackage());
item.setKind(GroovyLanguageServerUtils.astNodeToCompletionItemKind(classNode));
item.setDetail(packageName);
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDescription(packageName);
item.setLabelDetails(labelDetails);
String markdownDocs = GroovydocUtils.groovydocToMarkdownDescription(classNode.getGroovydoc());
if (markdownDocs != null) {
item.setDocumentation(new MarkupContent(MarkupKind.MARKDOWN, markdownDocs));
Expand Down Expand Up @@ -477,8 +501,10 @@ private void populateTypes(ASTNode offsetNode, String namePrefix, Set<String> ex
String packageName = classInfo.getPackageName();
CompletionItem item = new CompletionItem();
item.setLabel(classInfo.getSimpleName());
item.setDetail(packageName);
item.setKind(classInfoToCompletionItemKind(classInfo));
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDescription(packageName);
item.setLabelDetails(labelDetails);
if (packageName != null && !packageName.equals(enclosingPackageName) && !importNames.contains(className)) {
List<TextEdit> additionalTextEdits = new ArrayList<>();
TextEdit addImportEdit = createAddImportTextEdit(className, addImportRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.PropertyNode;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import net.prominic.groovyls.compiler.ast.ASTNodeVisitor;
import net.prominic.groovyls.compiler.util.GroovyASTUtils;
Expand All @@ -43,11 +45,11 @@ public WorkspaceSymbolProvider(ASTNodeVisitor ast) {
this.ast = ast;
}

public CompletableFuture<List<? extends SymbolInformation>> provideWorkspaceSymbols(String query) {
public CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> provideWorkspaceSymbols(String query) {
if (ast == null) {
// this shouldn't happen, but let's avoid an exception if something
// goes terribly wrong.
return CompletableFuture.completedFuture(Collections.emptyList());
return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList()));
}
String lowerCaseQuery = query.toLowerCase();
List<ASTNode> nodes = ast.getNodes();
Expand Down Expand Up @@ -92,6 +94,6 @@ public CompletableFuture<List<? extends SymbolInformation>> provideWorkspaceSymb
// this should never happen
return null;
}).filter(symbolInformation -> symbolInformation != null).collect(Collectors.toList());
return CompletableFuture.completedFuture(symbols);
return CompletableFuture.completedFuture(Either.forLeft(symbols));
}
}
Loading