Skip to content

Commit a7da334

Browse files
committed
feat: add Beta support for Inline Completion Request
1 parent e315573 commit a7da334

File tree

3 files changed

+347
-10
lines changed

3 files changed

+347
-10
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Avaloq Group AG
3+
* Schwerzistrasse 6, 8807 Freienbach, Switzerland, http://www.avaloq.com
4+
* All Rights Reserved.
5+
*
6+
* This software is the confidential and proprietary information of Avaloq Group AG.
7+
* You shall not disclose whole or parts of it and shall use it only in accordance with the terms of the
8+
* licence agreement you entered into with Avaloq Group AG.
9+
*/
10+
package org.eclipse.lsp4j;
11+
12+
import com.google.common.annotations.Beta;
13+
14+
15+
/**
16+
* Describes how an {@link InlineCompletionItemProvider inline completion
17+
* provider} was triggered.
18+
*
19+
* @since 3.18.0
20+
*/
21+
@Beta
22+
public enum InlineCompletionTriggerKind {
23+
/**
24+
* Completion was triggered explicitly by a user gesture.
25+
* Return multiple completion items to enable cycling through them.
26+
*/
27+
Invoked(1),
28+
29+
/**
30+
* Completion was triggered automatically while editing.
31+
* It is sufficient to 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: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212
package org.eclipse.lsp4j
1313

14+
import com.google.common.annotations.Beta
1415
import com.google.gson.annotations.JsonAdapter
1516
import java.util.ArrayList
1617
import java.util.Arrays
@@ -6061,6 +6062,14 @@ class ServerCapabilities {
60616062
*/
60626063
Either<Boolean, InlineValueRegistrationOptions> inlineValueProvider
60636064

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

0 commit comments

Comments
 (0)