Skip to content

Commit

Permalink
feat: Provide InlayHint for property expression in
Browse files Browse the repository at this point in the history
microprofile-config.properties (#971)

Fixes #971

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jun 23, 2023
1 parent 3e86087 commit 988a3c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.codeInsight.hints.presentation.MouseButton;
import com.intellij.codeInsight.hints.presentation.PresentationFactory;
import com.intellij.codeInsight.hints.presentation.SequencePresentation;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
Expand All @@ -27,21 +28,15 @@
import com.redhat.devtools.intellij.lsp4ij.AbstractLSPInlayProvider;
import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils;
import com.redhat.devtools.intellij.lsp4ij.LanguageServiceAccessor;
import org.eclipse.lsp4j.InlayHint;
import org.eclipse.lsp4j.InlayHintLabelPart;
import org.eclipse.lsp4j.InlayHintParams;
import org.eclipse.lsp4j.InlayHintRegistrationOptions;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageServer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.Component;
import java.awt.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -69,10 +64,10 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
try {
URI docURI = LSPIJUtils.toUri(editor.getDocument());
if (docURI != null) {
Range viewPortRange = new Range(new Position(0, 0), new Position(0,0));
Range viewPortRange = getViewPortRange(editor);
InlayHintParams param = new InlayHintParams(new TextDocumentIdentifier(docURI.toString()), viewPortRange);
BlockingDeque<Pair<InlayHint, LanguageServer>> pairs = new LinkedBlockingDeque<>();
List<Pair<Integer,Pair<InlayHint, LanguageServer>>> inlayhints = new ArrayList<>();
List<Pair<Integer, Pair<InlayHint, LanguageServer>>> inlayhints = new ArrayList<>();
CompletableFuture<Void> future = LanguageServiceAccessor.getInstance(psiElement.getProject())
.getLanguageServers(editor.getDocument(), capabilities -> capabilities.getInlayHintProvider() != null)
.thenComposeAsync(languageServers -> CompletableFuture.allOf(languageServers.stream()
Expand All @@ -93,8 +88,8 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
inlayhints.add(Pair.create(offset, pair));
}
}
Map<Integer, List<Pair<Integer,Pair<InlayHint, LanguageServer>>>> elements = inlayhints.stream().collect(Collectors.groupingBy(p -> p.first));
elements.forEach((offset,list) -> inlayHintsSink.addInlineElement(offset, false,
Map<Integer, List<Pair<Integer, Pair<InlayHint, LanguageServer>>>> elements = inlayhints.stream().collect(Collectors.groupingBy(p -> p.first));
elements.forEach((offset, list) -> inlayHintsSink.addInlineElement(offset, false,
toPresentation(editor, offset, list, getFactory()), false));
}
} catch (InterruptedException e) {
Expand All @@ -106,6 +101,14 @@ public boolean collect(@NotNull PsiElement psiElement, @NotNull Editor editor, @
};
}

@NotNull
private static Range getViewPortRange(Editor editor) {
Position start = new Position(0, 0);
Document document = editor.getDocument();
Position end = LSPIJUtils.toPosition(document.getTextLength(), document);
return new Range(start, end);
}

private InlayPresentation toPresentation(Editor editor, int offset,
List<Pair<Integer, Pair<InlayHint, LanguageServer>>> elements,
PresentationFactory factory) {
Expand All @@ -116,7 +119,7 @@ private InlayPresentation toPresentation(Editor editor, int offset,
presentations.add(factory.smallText(label.getLeft()));
} else {
int index = 0;
for(InlayHintLabelPart part : label.getRight()) {
for (InlayHintLabelPart part : label.getRight()) {
InlayPresentation presentation = factory.smallText(part.getValue());
if (part.getCommand() != null) {
int finalIndex = index;
Expand Down Expand Up @@ -156,7 +159,7 @@ private boolean isResolveSupported(Either<Boolean, InlayHintRegistrationOptions>
private String getInlayHintString(InlayHint inlayHint) {
Either<String, List<InlayHintLabelPart>> label = inlayHint.getLabel();
return label.map(Function.identity(), parts -> {
return parts==null?null:parts.stream().map(InlayHintLabelPart::getValue).collect(Collectors.joining());
return parts == null ? null : parts.stream().map(InlayHintLabelPart::getValue).collect(Collectors.joining());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,23 @@ public QuarkusServer() {

@Override
public Object getInitializationOptions(URI rootUri) {

Map<String, Object> root = new HashMap<>();
Map<String, Object> settings = new HashMap<>();
Map<String, Object> quarkus = new HashMap<>();
Map<String, Object> tools = new HashMap<>();
Map<String, Object> trace = new HashMap<>();
trace.put("server", "verbose");
tools.put("trace", trace);

Map<String, Object> codeLens = new HashMap<>();
codeLens.put("urlCodeLensEnabled", "true");
tools.put("codeLens", codeLens);

Map<String, Object> inlayHint = new HashMap<>();
inlayHint.put("enabled", "true");
tools.put("inlayHint", inlayHint);

quarkus.put("tools", tools);
settings.put("microprofile", quarkus);
root.put("settings", settings);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/lsp4ij-quarkus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
implementationClass="com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator"/>
<externalAnnotator language="JAVA"
implementationClass="com.redhat.devtools.intellij.lsp4ij.operations.documentLink.LSPDocumentLinkAnnotator"/>
<codeInsight.inlayProvider language="Properties"
implementationClass="com.redhat.devtools.intellij.lsp4ij.operations.inlayhint.LSPInlayHintInlayProvider"/>
</extensions>

</idea-plugin>

0 comments on commit 988a3c2

Please sign in to comment.