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 tags + List tags /** * An array of related diagnostic information, e.g. when symbol-names within a scope collide @@ -6061,6 +6070,14 @@ class ServerCapabilities { */ Either inlineValueProvider + /** + * The server provides inline completions. + *

+ * @since 3.18.0 + */ + @Draft + Either inlineCompletionProvider + /** * The server has support for pull model diagnostics. *

@@ -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 items + + new() { + } + + new(@NonNull List items) { + this.items = Preconditions.checkNotNull(items, 'items') + } +} + +/** + * An inline completion item represents a text snippet that is proposed inline + * to complete text that is being typed. + *

+ * @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 insertText + + /** + * A text that is used to decide if this inline completion should be + * shown. When `falsy`, the {@link InlineCompletionItem#insertText} is + * used. + *

+ * 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 insertText) { + this.insertText = Preconditions.checkNotNull(insertText, 'insertText') + } +} diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/TextDocumentService.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/TextDocumentService.java index d628d9814..6086787e8 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/TextDocumentService.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/TextDocumentService.java @@ -57,6 +57,9 @@ import org.eclipse.lsp4j.ImplementationParams; import org.eclipse.lsp4j.InlayHint; import org.eclipse.lsp4j.InlayHintParams; +import org.eclipse.lsp4j.InlineCompletionItem; +import org.eclipse.lsp4j.InlineCompletionList; +import org.eclipse.lsp4j.InlineCompletionParams; import org.eclipse.lsp4j.InlineValue; import org.eclipse.lsp4j.InlineValueParams; import org.eclipse.lsp4j.LinkedEditingRangeParams; @@ -97,6 +100,7 @@ import org.eclipse.lsp4j.adapters.LocationLinkListAdapter; import org.eclipse.lsp4j.adapters.PrepareRenameResponseAdapter; import org.eclipse.lsp4j.adapters.SemanticTokensFullDeltaResponseAdapter; +import org.eclipse.lsp4j.jsonrpc.Draft; import org.eclipse.lsp4j.jsonrpc.json.ResponseJsonAdapter; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.jsonrpc.messages.Either3; @@ -151,7 +155,7 @@ default CompletableFuture hover(HoverParams params) { default CompletableFuture signatureHelp(SignatureHelpParams params) { throw new UnsupportedOperationException(); } - + /** * The go to declaration request is sent from the client to the server to resolve * the declaration location of a symbol at a given text document position. @@ -177,7 +181,7 @@ default CompletableFuture, List, List>> definition(DefinitionParams params) { throw new UnsupportedOperationException(); } - + /** * The goto type definition request is sent from the client to the server to resolve * the type definition location of a symbol at a given text document position. @@ -191,7 +195,7 @@ default CompletableFuture, List, List>> typeDefinition(TypeDefinitionParams params) { throw new UnsupportedOperationException(); } - + /** * The goto implementation request is sent from the client to the server to resolve * the implementation location of a symbol at a given text document position. @@ -405,7 +409,7 @@ default CompletableFuture linkedEditingRange(LinkedEditingR */ @JsonNotification default void willSave(WillSaveTextDocumentParams params) {} - + /** * The document will save request is sent from the client to the server before the document is actually saved. * The request can return an array of TextEdits which will be applied to the text document before it is saved. @@ -418,7 +422,7 @@ default void willSave(WillSaveTextDocumentParams params) {} 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. *

@@ -428,7 +432,7 @@ default CompletableFuture> 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 documentLinkResolve(DocumentLink params) { throw new UnsupportedOperationException(); } - + /** * The document color request is sent from the client to the server to list all color references found in a given text * document. Along with the range, a color value in RGB is returned. @@ -453,7 +457,7 @@ default CompletableFuture documentLinkResolve(DocumentLink params) 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

    *
  1. first a type hierarchy item is prepared for the given text document position. @@ -690,4 +694,29 @@ default CompletableFuture> inlineValue(InlineValueParams param default CompletableFuture diagnostic(DocumentDiagnosticParams params) { throw new UnsupportedOperationException(); } + + /** + * The inline completion request is sent from the client to the server to compute inline completions for a given text document + * either explicitly by a user gesture or implicitly when typing. + *

    + * 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, InlineCompletionList>> inlineCompletion(InlineCompletionParams params) { + throw new UnsupportedOperationException(); + } }