Skip to content

Commit dee7e1b

Browse files
authored
feat: add Beta support for Inline Completion Request (#886)
1 parent 68ba2bc commit dee7e1b

File tree

4 files changed

+403
-11
lines changed

4 files changed

+403
-11
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2025 Avaloq Group AG.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
package org.eclipse.lsp4j.jsonrpc;
13+
14+
import java.lang.annotation.Documented;
15+
import java.lang.annotation.ElementType;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
/**
21+
* An API using this annotation is part of an upcomming Language Server Protocol Specification and
22+
* in a draft state. Therefore it is subject to incompatible changes (including even removal)
23+
* in a future release.
24+
*
25+
*/
26+
@Retention(RetentionPolicy.CLASS)
27+
@Target({
28+
ElementType.CONSTRUCTOR,
29+
ElementType.FIELD,
30+
ElementType.METHOD,
31+
ElementType.TYPE
32+
})
33+
@Documented
34+
public @interface Draft {}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Avaloq Group AG.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
******************************************************************************/
12+
package org.eclipse.lsp4j;
13+
14+
import org.eclipse.lsp4j.jsonrpc.Draft;
15+
16+
/**
17+
* Describes how an inline completion request was triggered.
18+
* <p>
19+
* @since 3.18.0
20+
*/
21+
@Draft
22+
public enum InlineCompletionTriggerKind {
23+
/**
24+
* Completion was triggered explicitly by a user gesture. Return multiple
25+
* completion items to enable cycling through them.
26+
*/
27+
Invoked(1),
28+
29+
/**
30+
* Completion was triggered automatically while editing. It is sufficient to
31+
* return a single completion item in this case.
32+
*/
33+
Automatic(2);
34+
35+
private final int value;
36+
37+
InlineCompletionTriggerKind(final int value) {
38+
this.value = value;
39+
}
40+
41+
public int getValue() {
42+
return value;
43+
}
44+
45+
public static InlineCompletionTriggerKind forValue(final int value) {
46+
InlineCompletionTriggerKind[] allValues = InlineCompletionTriggerKind.values();
47+
if (value < 1 || value > allValues.length) {
48+
throw new IllegalArgumentException("Illegal enum value: " + value);
49+
}
50+
return allValues[value - 1];
51+
}
52+
}

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend

Lines changed: 278 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.eclipse.lsp4j.adapters.VersionedTextDocumentIdentifierTypeAdapter
2929
import org.eclipse.lsp4j.adapters.WorkspaceDocumentDiagnosticReportListAdapter
3030
import org.eclipse.lsp4j.adapters.WorkspaceSymbolLocationTypeAdapter
3131
import org.eclipse.lsp4j.generator.JsonRpcData
32+
import org.eclipse.lsp4j.jsonrpc.Draft
3233
import org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter
3334
import org.eclipse.lsp4j.jsonrpc.messages.Either
3435
import org.eclipse.lsp4j.jsonrpc.messages.Either3
@@ -2241,6 +2242,14 @@ class TextDocumentClientCapabilities {
22412242
*/
22422243
DiagnosticCapabilities diagnostic
22432244

2245+
/**
2246+
* Capabilities specific to the `textDocument/inlineCompletion` request.
2247+
* <p>
2248+
* @since 3.18.0
2249+
*/
2250+
@Draft
2251+
InlineCompletionClientCapabilities inlineCompletion
2252+
22442253
new() {
22452254
}
22462255
}
@@ -3330,7 +3339,7 @@ class Diagnostic {
33303339
* <p>
33313340
* Since 3.15.0
33323341
*/
3333-
List<DiagnosticTag> tags
3342+
List<DiagnosticTag> tags
33343343

33353344
/**
33363345
* An array of related diagnostic information, e.g. when symbol-names within a scope collide
@@ -6061,6 +6070,14 @@ class ServerCapabilities {
60616070
*/
60626071
Either<Boolean, InlineValueRegistrationOptions> inlineValueProvider
60636072

6073+
/**
6074+
* The server provides inline completions.
6075+
* <p>
6076+
* @since 3.18.0
6077+
*/
6078+
@Draft
6079+
Either<Boolean, InlineCompletionRegistrationOptions> inlineCompletionProvider
6080+
60646081
/**
60656082
* The server has support for pull model diagnostics.
60666083
* <p>
@@ -11161,3 +11178,263 @@ class NotebookDocumentIdentifier {
1116111178
this.uri = Preconditions.checkNotNull(uri, 'uri')
1116211179
}
1116311180
}
11181+
11182+
/**
11183+
* Describes kind of {@link StringValue}.
11184+
* <p>
11185+
* Since 3.18.0
11186+
*/
11187+
@Draft
11188+
final class StringValueKind {
11189+
/**
11190+
* Indicates a snippet {@link StringValue}.
11191+
*/
11192+
public static val SNIPPET = 'snippet'
11193+
11194+
private new() {
11195+
}
11196+
}
11197+
11198+
/**
11199+
* A string value used as a snippet is a template which allows to insert text
11200+
* and to control the editor cursor when insertion happens.
11201+
* <p>
11202+
* A snippet can define tab stops and placeholders with `$1`, `$2`
11203+
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
11204+
* the end of the snippet. Variables are defined with `$name` and
11205+
* `${name:default value}`.
11206+
* <p>
11207+
* @since 3.18.0
11208+
*/
11209+
@Draft
11210+
@JsonRpcData
11211+
class StringValue {
11212+
/**
11213+
* The kind of the string value.
11214+
* <p>
11215+
* See {@link StringValueKind} for allowed values.
11216+
*/
11217+
@NonNull
11218+
String kind
11219+
11220+
/**
11221+
* The string value.
11222+
*/
11223+
@NonNull
11224+
String value
11225+
11226+
new() {
11227+
}
11228+
11229+
new(@NonNull String kind, @NonNull String value) {
11230+
this.kind = Preconditions.checkNotNull(kind, 'kind')
11231+
this.value = Preconditions.checkNotNull(value, 'value')
11232+
}
11233+
}
11234+
11235+
/**
11236+
* Client capabilities specific to inline completions.
11237+
* <p>
11238+
* @since 3.18.0
11239+
*/
11240+
@Draft
11241+
@JsonRpcData
11242+
class InlineCompletionClientCapabilities extends DynamicRegistrationCapabilities {
11243+
new() {
11244+
}
11245+
11246+
new(Boolean dynamicRegistration) {
11247+
super(dynamicRegistration)
11248+
}
11249+
}
11250+
11251+
/**
11252+
* Inline completion options used during static or dynamic registration.
11253+
* <p>
11254+
* @since 3.18.0
11255+
*/
11256+
@Draft
11257+
@JsonRpcData
11258+
class InlineCompletionRegistrationOptions extends AbstractTextDocumentRegistrationAndWorkDoneProgressOptions {
11259+
/**
11260+
* The id used to register the request. The id can be used to deregister
11261+
* the request again. See also {@link Registration#id}.
11262+
*/
11263+
String id
11264+
11265+
new() {
11266+
}
11267+
11268+
new(String id) {
11269+
this.id = id
11270+
}
11271+
}
11272+
11273+
/**
11274+
* A parameter literal used in inline completion requests.
11275+
* <p>
11276+
* @since 3.18.0
11277+
*/
11278+
@Draft
11279+
@JsonRpcData
11280+
class InlineCompletionParams extends TextDocumentPositionAndWorkDoneProgressParams {
11281+
/**
11282+
* Additional information about the context in which inline completions
11283+
* were requested.
11284+
*/
11285+
@NonNull
11286+
InlineCompletionContext context
11287+
11288+
new() {
11289+
}
11290+
11291+
new(@NonNull TextDocumentIdentifier textDocument, @NonNull Position position, @NonNull InlineCompletionContext context) {
11292+
super(textDocument, position)
11293+
this.context = Preconditions.checkNotNull(context, 'context')
11294+
}
11295+
}
11296+
11297+
/**
11298+
* Provides information about the context in which an inline completion was
11299+
* requested.
11300+
* <p>
11301+
* @since 3.18.0
11302+
*/
11303+
@Draft
11304+
@JsonRpcData
11305+
class InlineCompletionContext {
11306+
/**
11307+
* Describes how the inline completion was triggered.
11308+
*/
11309+
@NonNull
11310+
InlineCompletionTriggerKind triggerKind
11311+
11312+
/**
11313+
* Provides information about the currently selected item in the
11314+
* autocomplete widget if it is visible.
11315+
*<p>
11316+
* If set, provided inline completions must extend the text of the
11317+
* selected item and use the same range, otherwise they are not shown as
11318+
* preview.
11319+
* As an example, if the document text is `console.` and the selected item
11320+
* is `.log` replacing the `.` in the document, the inline completion must
11321+
* also replace `.` and start with `.log`, for example `.log()`.
11322+
*<p>
11323+
* Inline completion providers are requested again whenever the selected
11324+
* item changes.
11325+
*/
11326+
SelectedCompletionInfo selectedCompletionInfo
11327+
11328+
new() {
11329+
}
11330+
11331+
new(@NonNull InlineCompletionTriggerKind triggerKind) {
11332+
this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
11333+
}
11334+
11335+
new(@NonNull InlineCompletionTriggerKind triggerKind, SelectedCompletionInfo selectedCompletionInfo) {
11336+
this.triggerKind = Preconditions.checkNotNull(triggerKind, 'triggerKind')
11337+
this.selectedCompletionInfo = selectedCompletionInfo
11338+
}
11339+
}
11340+
11341+
/**
11342+
* Describes the currently selected completion item.
11343+
* <p>
11344+
* @since 3.18.0
11345+
*/
11346+
@Draft
11347+
@JsonRpcData
11348+
class SelectedCompletionInfo {
11349+
/**
11350+
* The range that will be replaced if this completion item is accepted.
11351+
*/
11352+
@NonNull
11353+
Range range
11354+
11355+
/**
11356+
* The text the range will be replaced with if this completion is
11357+
* accepted.
11358+
*/
11359+
@NonNull
11360+
String text
11361+
11362+
new() {
11363+
}
11364+
11365+
new(@NonNull Range range, @NonNull String text) {
11366+
this.range = Preconditions.checkNotNull(range, 'range')
11367+
this.text = Preconditions.checkNotNull(text, 'text')
11368+
}
11369+
}
11370+
11371+
/**
11372+
* Represents a collection of {@link InlineCompletionItem} to be presented in the editor.
11373+
* <p>
11374+
* @since 3.18.0
11375+
*/
11376+
@Draft
11377+
@JsonRpcData
11378+
class InlineCompletionList {
11379+
/**
11380+
* The inline completion items.
11381+
*/
11382+
@NonNull
11383+
List<InlineCompletionItem> items
11384+
11385+
new() {
11386+
}
11387+
11388+
new(@NonNull List<InlineCompletionItem> items) {
11389+
this.items = Preconditions.checkNotNull(items, 'items')
11390+
}
11391+
}
11392+
11393+
/**
11394+
* An inline completion item represents a text snippet that is proposed inline
11395+
* to complete text that is being typed.
11396+
* <p>
11397+
* @since 3.18.0
11398+
*/
11399+
@Draft
11400+
@JsonRpcData
11401+
class InlineCompletionItem {
11402+
/**
11403+
* The text to replace the range with. Must be set.
11404+
* Is used both for the preview and the accept operation.
11405+
*/
11406+
@NonNull
11407+
Either<String, StringValue> insertText
11408+
11409+
/**
11410+
* A text that is used to decide if this inline completion should be
11411+
* shown. When `falsy`, the {@link InlineCompletionItem#insertText} is
11412+
* used.
11413+
* <p>
11414+
* An inline completion is shown if the text to replace is a prefix of the
11415+
* filter text.
11416+
*/
11417+
String filterText
11418+
11419+
/**
11420+
* The range to replace.
11421+
* Must begin and end on the same line.
11422+
* <p>
11423+
* Prefer replacements over insertions to provide a better experience when
11424+
* the user deletes typed text.
11425+
*/
11426+
Range range
11427+
11428+
/**
11429+
* An optional {@link Command} that is executed *after* inserting this
11430+
* completion.
11431+
*/
11432+
Command command
11433+
11434+
new() {
11435+
}
11436+
11437+
new(@NonNull Either<String, StringValue> insertText) {
11438+
this.insertText = Preconditions.checkNotNull(insertText, 'insertText')
11439+
}
11440+
}

0 commit comments

Comments
 (0)