1use crate::{
2 Command, InsertTextFormat, Range, StaticRegistrationOptions, TextDocumentPositionParams,
3 TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams,
4};
5use serde::{Deserialize, Serialize};
6
7/// Client capabilities specific to inline completions.
8///
9/// @since 3.18.0
10#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct InlineCompletionClientCapabilities {
13 /// Whether implementation supports dynamic registration for inline completion providers.
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub dynamic_registration: Option<bool>,
16}
17
18/// Inline completion options used during static registration.
19///
20/// @since 3.18.0
21#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
22pub struct InlineCompletionOptions {
23 #[serde(flatten)]
24 pub work_done_progress_options: WorkDoneProgressOptions,
25}
26
27/// Inline completion options used during static or dynamic registration.
28///
29// @since 3.18.0
30#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
31pub struct InlineCompletionRegistrationOptions {
32 #[serde(flatten)]
33 pub inline_completion_options: InlineCompletionOptions,
34
35 #[serde(flatten)]
36 pub text_document_registration_options: TextDocumentRegistrationOptions,
37
38 #[serde(flatten)]
39 pub static_registration_options: StaticRegistrationOptions,
40}
41
42/// A parameter literal used in inline completion requests.
43///
44/// @since 3.18.0
45#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
46#[serde(rename_all = "camelCase")]
47pub struct InlineCompletionParams {
48 #[serde(flatten)]
49 pub work_done_progress_params: WorkDoneProgressParams,
50
51 #[serde(flatten)]
52 pub text_document_position: TextDocumentPositionParams,
53
54 /// Additional information about the context in which inline completions were requested.
55 pub context: InlineCompletionContext,
56}
57
58/// Describes how an [`InlineCompletionItemProvider`] was triggered.
59///
60/// @since 3.18.0
61#[derive(Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
62pub struct InlineCompletionTriggerKind(i32);
63lsp_enum! {
64impl InlineCompletionTriggerKind {
65 /// Completion was triggered explicitly by a user gesture.
66 /// Return multiple completion items to enable cycling through them.
67 pub const Invoked: InlineCompletionTriggerKind = InlineCompletionTriggerKind(1);
68
69 /// Completion was triggered automatically while editing.
70 /// It is sufficient to return a single completion item in this case.
71 pub const Automatic: InlineCompletionTriggerKind = InlineCompletionTriggerKind(2);
72}
73}
74
75/// Describes the currently selected completion item.
76///
77/// @since 3.18.0
78#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
79pub struct SelectedCompletionInfo {
80 /// The range that will be replaced if this completion item is accepted.
81 pub range: Range,
82 /// The text the range will be replaced with if this completion is
83 /// accepted.
84 pub text: String,
85}
86
87/// Provides information about the context in which an inline completion was
88/// requested.
89///
90/// @since 3.18.0
91#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
92#[serde(rename_all = "camelCase")]
93pub struct InlineCompletionContext {
94 /// Describes how the inline completion was triggered.
95 pub trigger_kind: InlineCompletionTriggerKind,
96 /// Provides information about the currently selected item in the
97 /// autocomplete widget if it is visible.
98 ///
99 /// If set, provided inline completions must extend the text of the
100 /// selected item and use the same range, otherwise they are not shown as
101 /// preview.
102 /// As an example, if the document text is `console.` and the selected item
103 /// is `.log` replacing the `.` in the document, the inline completion must
104 /// also replace `.` and start with `.log`, for example `.log()`.
105 ///
106 /// Inline completion providers are requested again whenever the selected
107 /// item changes.
108 #[serde(skip_serializing_if = "Option::is_none")]
109 pub selected_completion_info: Option<SelectedCompletionInfo>,
110}
111
112/// InlineCompletion response can be multiple completion items, or a list of completion items
113#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
114#[serde(untagged)]
115pub enum InlineCompletionResponse {
116 Array(Vec<InlineCompletionItem>),
117 List(InlineCompletionList),
118}
119
120/// Represents a collection of [`InlineCompletionItem`] to be presented in the editor.
121///
122/// @since 3.18.0
123#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
124pub struct InlineCompletionList {
125 /// The inline completion items
126 pub items: Vec<InlineCompletionItem>,
127}
128
129/// An inline completion item represents a text snippet that is proposed inline
130/// to complete text that is being typed.
131///
132/// @since 3.18.0
133#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
134#[serde(rename_all = "camelCase")]
135pub struct InlineCompletionItem {
136 /// The text to replace the range with. Must be set.
137 /// Is used both for the preview and the accept operation.
138 pub insert_text: String,
139 /// A text that is used to decide if this inline completion should be
140 /// shown. When `falsy` the [`InlineCompletionItem::insertText`] is
141 /// used.
142 ///
143 /// An inline completion is shown if the text to replace is a prefix of the
144 /// filter text.
145 #[serde(skip_serializing_if = "Option::is_none")]
146 pub filter_text: Option<String>,
147 /// The range to replace.
148 /// Must begin and end on the same line.
149 ///
150 /// Prefer replacements over insertions to provide a better experience when
151 /// the user deletes typed text.
152 #[serde(skip_serializing_if = "Option::is_none")]
153 pub range: Option<Range>,
154 /// An optional command that is executed *after* inserting this
155 /// completion.
156 #[serde(skip_serializing_if = "Option::is_none")]
157 pub command: Option<Command>,
158 /// The format of the insert text. The format applies to the `insertText`.
159 /// If omitted defaults to `InsertTextFormat.PlainText`.
160 #[serde(skip_serializing_if = "Option::is_none")]
161 pub insert_text_format: Option<InsertTextFormat>,
162}
163