Skip to content

Commit

Permalink
Polish bean completion items optics
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Feb 27, 2025
1 parent 1630eb1 commit b8322a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2019 Pivotal, Inc.
* Copyright (c) 2016, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@

import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.CompletionItemLabelDetails;
import org.springframework.ide.vscode.commons.util.Renderable;

/**
Expand Down Expand Up @@ -63,4 +64,8 @@ default Optional<Command> getCommand() {
return Optional.empty();
}

default CompletionItemLabelDetails getLabelDetails() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private CompletionItem adaptItem(TextDocument doc, ICompletionProposal completio
item.setSortText(sortkeys.next());
item.setFilterText(completion.getFilterText());
item.setInsertTextMode(InsertTextMode.AsIs);
item.setLabelDetails(completion.getLabelDetails());
if (completion.isDeprecated()) {
item.setTags(List.of(CompletionItemTag.Deprecated));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.CompletionItemLabelDetails;
import org.openrewrite.java.tree.JavaType;
import org.springframework.ide.vscode.boot.java.rewrite.RewriteRefactorings;
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposalWithScore;
Expand All @@ -32,6 +34,8 @@
*/
public class BeanCompletionProposal implements ICompletionProposalWithScore {

private static final String DETAIL = " - autowire bean";

private DocumentEdits edits;
private IDocument doc;
private String beanId;
Expand All @@ -54,12 +58,12 @@ public BeanCompletionProposal(DocumentEdits edits, IDocument doc, String beanId,

@Override
public String getLabel() {
return this.beanId;
return beanId;
}

@Override
public CompletionItemKind getKind() {
return CompletionItemKind.Constructor;
return CompletionItemKind.Field;
}

@Override
Expand All @@ -71,6 +75,14 @@ public DocumentEdits getTextEdit() {
public String getDetail() {
return "Autowire a bean";
}

@Override
public CompletionItemLabelDetails getLabelDetails() {
CompletionItemLabelDetails labelDetails = new CompletionItemLabelDetails();
labelDetails.setDetail(DETAIL);
labelDetails.setDescription(JavaType.ShallowClass.build(beanType).getClassName());
return labelDetails;
}

@Override
public Renderable getDocumentation() {
Expand Down

0 comments on commit b8322a0

Please sign in to comment.