diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Draft.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Draft.java new file mode 100644 index 000000000..823208193 --- /dev/null +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Draft.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2025 Avaloq Group AG. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package org.eclipse.lsp4j.jsonrpc; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An API using this annotation is part of an upcomming Language Server Protocol Specification and + * in a draft state. Therefore it is subject to incompatible changes (including even removal) + * in a future release. + * + */ +@Retention(RetentionPolicy.CLASS) +@Target({ +ElementType.CONSTRUCTOR, +ElementType.FIELD, +ElementType.METHOD, +ElementType.TYPE +}) +@Documented +public @interface Draft {} diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/InlineCompletionTriggerKind.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/InlineCompletionTriggerKind.java new file mode 100644 index 000000000..05f5d2a87 --- /dev/null +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/InlineCompletionTriggerKind.java @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (c) 2025 Avaloq Group AG. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + ******************************************************************************/ +package org.eclipse.lsp4j; + +import org.eclipse.lsp4j.jsonrpc.Draft; + +/** + * Describes how an inline completion request was triggered. + *
+ * @since 3.18.0 + */ +@Draft +public enum InlineCompletionTriggerKind { + /** + * Completion was triggered explicitly by a user gesture. Return multiple + * completion items to enable cycling through them. + */ + Invoked(1), + + /** + * Completion was triggered automatically while editing. It is sufficient to + * return a single completion item in this case. + */ + Automatic(2); + + private final int value; + + InlineCompletionTriggerKind(final int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static InlineCompletionTriggerKind forValue(final int value) { + InlineCompletionTriggerKind[] allValues = InlineCompletionTriggerKind.values(); + if (value < 1 || value > allValues.length) { + throw new IllegalArgumentException("Illegal enum value: " + value); + } + return allValues[value - 1]; + } +} diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend index 5e5565113..8ea266bbd 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend @@ -29,6 +29,7 @@ import org.eclipse.lsp4j.adapters.VersionedTextDocumentIdentifierTypeAdapter import org.eclipse.lsp4j.adapters.WorkspaceDocumentDiagnosticReportListAdapter import org.eclipse.lsp4j.adapters.WorkspaceSymbolLocationTypeAdapter import org.eclipse.lsp4j.generator.JsonRpcData +import org.eclipse.lsp4j.jsonrpc.Draft import org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.lsp4j.jsonrpc.messages.Either3 @@ -2241,6 +2242,14 @@ class TextDocumentClientCapabilities { */ DiagnosticCapabilities diagnostic + /** + * Capabilities specific to the `textDocument/inlineCompletion` request. + *
+ * @since 3.18.0 + */ + @Draft + InlineCompletionClientCapabilities inlineCompletion + new() { } } @@ -3330,7 +3339,7 @@ class Diagnostic { *
* Since 3.15.0
*/
- List
+ * @since 3.18.0
+ */
+ @Draft
+ Either
@@ -11161,3 +11178,263 @@ class NotebookDocumentIdentifier {
this.uri = Preconditions.checkNotNull(uri, 'uri')
}
}
+
+/**
+ * Describes kind of {@link StringValue}.
+ *
+ * Since 3.18.0
+ */
+@Draft
+final class StringValueKind {
+ /**
+ * Indicates a snippet {@link StringValue}.
+ */
+ public static val SNIPPET = 'snippet'
+
+ private new() {
+ }
+}
+
+/**
+ * A string value used as a snippet is a template which allows to insert text
+ * and to control the editor cursor when insertion happens.
+ *
+ * A snippet can define tab stops and placeholders with `$1`, `$2`
+ * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
+ * the end of the snippet. Variables are defined with `$name` and
+ * `${name:default value}`.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class StringValue {
+ /**
+ * The kind of the string value.
+ *
+ * See {@link StringValueKind} for allowed values.
+ */
+ @NonNull
+ String kind
+
+ /**
+ * The string value.
+ */
+ @NonNull
+ String value
+
+ new() {
+ }
+
+ new(@NonNull String kind, @NonNull String value) {
+ this.kind = Preconditions.checkNotNull(kind, 'kind')
+ this.value = Preconditions.checkNotNull(value, 'value')
+ }
+}
+
+/**
+ * Client capabilities specific to inline completions.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionClientCapabilities extends DynamicRegistrationCapabilities {
+ new() {
+ }
+
+ new(Boolean dynamicRegistration) {
+ super(dynamicRegistration)
+ }
+}
+
+/**
+ * Inline completion options used during static or dynamic registration.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionRegistrationOptions extends AbstractTextDocumentRegistrationAndWorkDoneProgressOptions {
+ /**
+ * The id used to register the request. The id can be used to deregister
+ * the request again. See also {@link Registration#id}.
+ */
+ String id
+
+ new() {
+ }
+
+ new(String id) {
+ this.id = id
+ }
+}
+
+/**
+ * A parameter literal used in inline completion requests.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionParams extends TextDocumentPositionAndWorkDoneProgressParams {
+ /**
+ * Additional information about the context in which inline completions
+ * were requested.
+ */
+ @NonNull
+ InlineCompletionContext context
+
+ new() {
+ }
+
+ new(@NonNull TextDocumentIdentifier textDocument, @NonNull Position position, @NonNull InlineCompletionContext context) {
+ super(textDocument, position)
+ this.context = Preconditions.checkNotNull(context, 'context')
+ }
+}
+
+/**
+ * Provides information about the context in which an inline completion was
+ * requested.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionContext {
+ /**
+ * Describes how the inline completion was triggered.
+ */
+ @NonNull
+ InlineCompletionTriggerKind triggerKind
+
+ /**
+ * Provides information about the currently selected item in the
+ * autocomplete widget if it is visible.
+ *
+ * If set, provided inline completions must extend the text of the
+ * selected item and use the same range, otherwise they are not shown as
+ * preview.
+ * As an example, if the document text is `console.` and the selected item
+ * is `.log` replacing the `.` in the document, the inline completion must
+ * also replace `.` and start with `.log`, for example `.log()`.
+ *
+ * Inline completion providers are requested again whenever the selected
+ * item changes.
+ */
+ SelectedCompletionInfo selectedCompletionInfo
+
+ new() {
+ }
+
+ new(@NonNull InlineCompletionTriggerKind triggerKind) {
+ this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
+ }
+
+ new(@NonNull InlineCompletionTriggerKind triggerKind, SelectedCompletionInfo selectedCompletionInfo) {
+ this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
+ this.selectedCompletionInfo = selectedCompletionInfo
+ }
+}
+
+/**
+ * Describes the currently selected completion item.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class SelectedCompletionInfo {
+ /**
+ * The range that will be replaced if this completion item is accepted.
+ */
+ @NonNull
+ Range range
+
+ /**
+ * The text the range will be replaced with if this completion is
+ * accepted.
+ */
+ @NonNull
+ String text
+
+ new() {
+ }
+
+ new(@NonNull Range range, @NonNull String text) {
+ this.range = Preconditions.checkNotNull(range, 'range')
+ this.text = Preconditions.checkNotNull(text, 'text')
+ }
+}
+
+/**
+ * Represents a collection of {@link InlineCompletionItem} to be presented in the editor.
+ *
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionList {
+ /**
+ * The inline completion items.
+ */
+ @NonNull
+ List
+ * @since 3.18.0
+ */
+@Draft
+@JsonRpcData
+class InlineCompletionItem {
+ /**
+ * The text to replace the range with. Must be set.
+ * Is used both for the preview and the accept operation.
+ */
+ @NonNull
+ Either
+ * An inline completion is shown if the text to replace is a prefix of the
+ * filter text.
+ */
+ String filterText
+
+ /**
+ * The range to replace.
+ * Must begin and end on the same line.
+ *
+ * Prefer replacements over insertions to provide a better experience when
+ * the user deletes typed text.
+ */
+ Range range
+
+ /**
+ * An optional {@link Command} that is executed *after* inserting this
+ * completion.
+ */
+ Command command
+
+ new() {
+ }
+
+ new(@NonNull Either
@@ -428,7 +432,7 @@ default CompletableFuture
+ * Inline completion items usually complete bigger portions of text (e.g., whole methods) and in contrast to completions, items
+ * can complete code that might be syntactically or semantically incorrect.
+ *
+ * Due to this, inline completion items are usually not suited to be presented in normal code completion widgets like a list of
+ * items. One possible approach can be to present the information inline in the editor with lower contrast.
+ *
+ * When multiple inline completion items are returned, the client may decide whether the user can cycle through them or if they,
+ * along with their filterText, are merely for filtering if the user continues to type without yet accepting the inline
+ * completion item.
+ *
+ * Clients may choose to send information about the user’s current completion selection via context if completions are visible at
+ * the same time. In this case, returned inline completions should extend the text of the provided completion.
+ *
+ * Since 3.18.0
+ */
+ @Draft
+ @JsonRequest
+ default CompletableFuture> willSaveWaitUntil(WillSaveTextDocumentParams params) {
throw new UnsupportedOperationException();
}
-
+
/**
* The document links request is sent from the client to the server to request the location of links in a document.
*
> willSaveWaitUntil(WillSaveTextDocument
default CompletableFuture
> documentLink(DocumentLinkParams params) {
throw new UnsupportedOperationException();
}
-
+
/**
* The document link resolve request is sent from the client to the server to resolve the target of a given document link.
*/
@@ -436,7 +440,7 @@ default CompletableFuture
> documentLink(DocumentLinkParams pa
default CompletableFuture
> documentColor(DocumentColorParams params) {
throw new UnsupportedOperationException();
}
-
+
/**
* The color presentation request is sent from the client to the server to obtain a list of presentations for a color
* value at a given location. Clients can use the result to
@@ -468,7 +472,7 @@ default CompletableFuture
> documentColor(DocumentColorPar
default CompletableFuture
> colorPresentation(ColorPresentationParams params) {
throw new UnsupportedOperationException();
}
-
+
/**
* The folding range request is sent from the client to the server to return all folding
* ranges found in a given text document.
@@ -494,7 +498,7 @@ default CompletableFuture
*
> inlineValue(InlineValueParams param
default CompletableFuture