Skip to content

Commit

Permalink
Support for textDocument/InlayHint
Browse files Browse the repository at this point in the history
Fixes #595

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Apr 1, 2022
1 parent 3a9f9c2 commit cec54cf
Show file tree
Hide file tree
Showing 26 changed files with 1,267 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.lsp4j.proposed;

import java.util.List;

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;

import com.google.gson.annotations.JsonAdapter;

/**
* Inlay hint information.
*
* @since 3.17.0 - proposed state
*/
public class InlayHint {

/**
* The position of this hint.
*/
@NonNull
private Position position;

/**
* The label of this hint. A human readable string or an array of
* InlayHintLabelPart label parts.
*
* *Note* that neither the string nor the label part can be empty.
*/
@NonNull
private Either<String, List<InlayHintLabelPart>> label;

/**
* The kind of this hint. Can be omitted in which case the client should fall
* back to a reasonable default.
*/
private InlayHintKind kind;

/**
* A data entry field that is preserved on a completion item between a
* completion and a completion resolve request.
*/
@JsonAdapter(JsonElementTypeAdapter.Factory.class)
private Object data;

public InlayHint(@NonNull Position position, Either<String, List<InlayHintLabelPart>> label) {
this.position = Preconditions.<Position>checkNotNull(position, "position");
this.label = label;

}

public InlayHint() {

}

public Position getPosition() {
return position;
}

public void setPosition(Position position) {
this.position = position;
}

public Either<String, List<InlayHintLabelPart>> getLabel() {
return label;
}

public void setLabel(Either<String, List<InlayHintLabelPart>> label) {
this.label = label;
}

public InlayHintKind getKind() {
return kind;
}

public void setKind(InlayHintKind kind) {
this.kind = kind;
}

/**
* A data entry field that is preserved on a completion item between a
* completion and a completion resolve request.
*/
@Pure
public Object getData() {
return this.data;
}

/**
* A data entry field that is preserved on a completion item between a
* completion and a completion resolve request.
*/
public void setData(final Object data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.lsp4j.proposed;

public enum InlayHintKind {

/**
* An inlay hint that for a type annotation.
*/
Type(1),

/**
* An inlay hint that is for a parameter.
*/
Parameter(2);

private final int value;

InlayHintKind(int value) {
this.value = value;
}

public int getValue() {
return value;
}

public static InlayHintKind forValue(int value) {
InlayHintKind[] allValues = InlayHintKind.values();
if (value < 1 || value > allValues.length)
throw new IllegalArgumentException("Illegal enum value: " + value);
return allValues[value - 1];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat Inc. and others.
* Copyright (c) 2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
Expand All @@ -9,18 +9,10 @@
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.qute.project;
package com.redhat.lsp4j.proposed;

import java.util.concurrent.CompletableFuture;
public class InlayHintLabelPart {

import com.redhat.qute.parser.template.Template;

public interface TemplateProvider {

CompletableFuture<Template> getTemplate();

String getProjectUri();

String getTemplateId();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.lsp4j.proposed;

import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.WorkDoneProgressParams;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;

public class InlayHintParams implements WorkDoneProgressParams {

/**
* An optional token that a server can use to report work done progress.
*/
private Either<String, Integer> workDoneToken;

/**
* The document to format.
*/
@NonNull
private TextDocumentIdentifier textDocument;

/**
* The visible document range for which inlay hints should be computed.
*/
@NonNull
private Range range;

/**
* An optional token that a server can use to report work done progress.
*/
@Pure
@Override
public Either<String, Integer> getWorkDoneToken() {
return this.workDoneToken;
}

/**
* An optional token that a server can use to report work done progress.
*/
public void setWorkDoneToken(final Either<String, Integer> workDoneToken) {
this.workDoneToken = workDoneToken;
}

public void setWorkDoneToken(final String workDoneToken) {
if (workDoneToken == null) {
this.workDoneToken = null;
return;
}
this.workDoneToken = Either.forLeft(workDoneToken);
}

/**
* The document to format.
*/
@Pure
@NonNull
public TextDocumentIdentifier getTextDocument() {
return this.textDocument;
}

/**
* The document to format.
*/
public void setTextDocument(@NonNull final TextDocumentIdentifier textDocument) {
this.textDocument = Preconditions.checkNotNull(textDocument, "textDocument");
}

public void setWorkDoneToken(final Integer workDoneToken) {
if (workDoneToken == null) {
this.workDoneToken = null;
return;
}
this.workDoneToken = Either.forRight(workDoneToken);
}

/**
* Returns the visible document range for which inlay hints should be computed.
*
* @return the visible document range for which inlay hints should be computed.
*/
@Pure
@NonNull
public Range getRange() {
return range;
}

/**
* Set the visible document range for which inlay hints should be computed.
*
* @param range
*/
public void setRange(@NonNull Range range) {
this.range = Preconditions.checkNotNull(range, "range");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.lsp4j.proposed;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;

public interface QuteInlayHintProvider {

/**
* The inlay hints request is sent from the client to the server to compute
* inlay hints for a given [text document, range] tuple that may be rendered in
* the editor in place with other text.
* <p>
* Since 3.17.0
*/
@JsonRequest("textDocument/inlayHint")
default CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
throw new UnsupportedOperationException();
}

/**
* The request is sent from the client to the server to resolve additional
* information for a given inlay hint. This is usually used to compute the
* {@code tooltip}, {@code location} or {@code command} properties of an inlay
* hint's label part to avoid its unnecessary computation during the
* {@code textDocument/inlayHint} request.
* <p>
* Since 3.17.0
*/
@JsonRequest(value = "inlayHint/resolve", useSegment = false)
default CompletableFuture<InlayHint> resolveInlayHint(InlayHint unresolved) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.TextDocumentService;

import com.redhat.lsp4j.proposed.InlayHint;
import com.redhat.lsp4j.proposed.InlayHintParams;
import com.redhat.qute.ls.commons.client.ExtendedClientCapabilities;
import com.redhat.qute.settings.SharedSettings;

Expand Down Expand Up @@ -160,6 +162,10 @@ public CompletableFuture<LinkedEditingRanges> linkedEditingRange(LinkedEditingRa
return CompletableFuture.completedFuture(null);
}

public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
return CompletableFuture.completedFuture(null);
}

public boolean isHierarchicalDocumentSymbolSupport() {
return hierarchicalDocumentSymbolSupport;
}
Expand Down
Loading

0 comments on commit cec54cf

Please sign in to comment.