Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/******************************************************************************
* 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 com.google.common.annotations.Beta;


/**
* Describes how an {@link InlineCompletionItemProvider inline completion
* provider} was triggered.
*
* @since 3.18.0
*/
@Beta
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];
}
}
256 changes: 256 additions & 0 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
******************************************************************************/
package org.eclipse.lsp4j

import com.google.common.annotations.Beta
import com.google.gson.annotations.JsonAdapter
import java.util.ArrayList
import java.util.Arrays
Expand Down Expand Up @@ -6061,6 +6062,14 @@ class ServerCapabilities {
*/
Either<Boolean, InlineValueRegistrationOptions> inlineValueProvider

/**
* The server provides inline completions.
*
* @since 3.18.0
*/
@Beta
Either<Boolean, InlineCompletionOptions> inlineCompletionProvider;
Comment thread
rubenporras marked this conversation as resolved.
Outdated

/**
* The server has support for pull model diagnostics.
* <p>
Expand Down Expand Up @@ -11161,3 +11170,250 @@ class NotebookDocumentIdentifier {
this.uri = Preconditions.checkNotNull(uri, 'uri')
}
}

/**
* A string value used as a snippet is a template which allows to insert text
* and to control the editor cursor when insertion happens.
*
Comment thread
rubenporras marked this conversation as resolved.
Outdated
* 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
*/
@Beta
@JsonRpcData
class StringValue {
/**
* The kind of string value.
*/
public static val kind = 'snippet'
Comment thread
rubenporras marked this conversation as resolved.
Outdated

/**
* The snippet string.
*/
String value
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}
Comment thread
rubenporras marked this conversation as resolved.

/**
* Client capabilities specific to inline completions.
*
* @since 3.18.0
*/
@Beta
class InlineCompletionClientCapabilities extends DynamicRegistrationCapabilities {
Comment thread
rubenporras marked this conversation as resolved.
new() {
}

new(Boolean dynamicRegistration) {
super(dynamicRegistration)
}
}

/**
* Inline completion options used during static registration.
*
* @since 3.18.0
*/
@Beta
interface InlineCompletionOptions extends WorkDoneProgressOptions {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

/**
* Inline completion options used during static or dynamic registration.
*
* @since 3.18.0
*/
@Beta
@JsonRpcData
class InlineCompletionRegistrationOptions extends StaticRegistrationOptions implements InlineCompletionOptions {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
Boolean done

override Boolean getWorkDoneProgress() {
done
}

override void setWorkDoneProgress(Boolean workDoneProgress) {
this.done = workDoneProgress
}
}

/**
* A parameter literal used in inline completion requests.
*
* @since 3.18.0
*/
@Beta
@JsonRpcData
class InlineCompletionParams extends TextDocumentPositionParams implements WorkDoneProgressParams {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
Either<String, Integer> token
Comment thread
rubenporras marked this conversation as resolved.
Outdated

/**
* Additional information about the context in which inline completions
* were requested.
*/
@NonNull
InlineCompletionContext context
Comment thread
pisv marked this conversation as resolved.

private new() {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

new(@NonNull TextDocumentIdentifier textDocument, @NonNull Position position, @NonNull InlineCompletionContext context) {
super(textDocument, position)
this.context = Preconditions.checkNotNull(context, 'context')
}

override Either<String, Integer> getWorkDoneToken() {
token
}

override void setWorkDoneToken(Either<String, Integer> token) {
this.token = token
}
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

/**
* Provides information about the context in which an inline completion was
* requested.
*
* @since 3.18.0
*/
@Beta
@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.
*
Comment thread
rubenporras marked this conversation as resolved.
Outdated
* 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()`.
*
Comment thread
rubenporras marked this conversation as resolved.
Outdated
* Inline completion providers are requested again whenever the selected
* item changes.
*/
SelectedCompletionInfo selectedCompletionInfo
Comment thread
pisv marked this conversation as resolved.

private new() {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

new(@NonNull InlineCompletionTriggerKind triggerKind) {
this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
}

new(@NonNull InlineCompletionTriggerKind triggerKind, @NonNull SelectedCompletionInfo selectedCompletionInfo) {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
this.selectedCompletionInfo = Preconditions.checkNotNull(selectedCompletionInfo, 'selectedCompletionInfo')
}
}

/**
* Describes the currently selected completion item.
*
* @since 3.18.0
*/
@Beta
@JsonRpcData
class SelectedCompletionInfo {
/**
* The range that will be replaced if this completion item is accepted.
*/
Range range
Comment thread
rubenporras marked this conversation as resolved.

/**
* The text the range will be replaced with if this completion is
* accepted.
*/
String text
Comment thread
rubenporras marked this conversation as resolved.

private new() {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

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 inline completion
* items} to be presented in the editor.
*
* @since 3.18.0
*/
@Beta
@JsonRpcData
class InlineCompletionList {
/**
* The inline completion items.
*/
List<InlineCompletionItem> items
Comment thread
rubenporras marked this conversation as resolved.

private new() {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

new(@NonNull List<InlineCompletionItem> 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
*/
@Beta
@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<String, StringValue> 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.
*/
@NonNull
Comment thread
rubenporras marked this conversation as resolved.
Outdated
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

private new() {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
}

new(@NonNull Either<String, StringValue> insertText, @NonNull String filterText) {
Comment thread
rubenporras marked this conversation as resolved.
Outdated
this.insertText = Preconditions.checkNotNull(insertText, 'insertText')
this.filterText = Preconditions.checkNotNull(filterText, 'filterText')
}
}
Comment thread
rubenporras marked this conversation as resolved.
Outdated
Loading