ls_types/
signature_help.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    Documentation, MarkupKind, TextDocumentPositionParams, TextDocumentRegistrationOptions,
5    WorkDoneProgressOptions, WorkDoneProgressParams, macros::lsp_enum,
6};
7
8#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct SignatureInformationSettings {
11    /// Client supports the follow content formats for the documentation
12    /// property. The order describes the preferred format of the client.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub documentation_format: Option<Vec<MarkupKind>>,
15
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub parameter_information: Option<ParameterInformationSettings>,
18
19    /// The client support the `activeParameter` property on `SignatureInformation`
20    /// literal.
21    ///
22    /// @since 3.16.0
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub active_parameter_support: Option<bool>,
25}
26
27#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct ParameterInformationSettings {
30    /// The client supports processing label offsets instead of a
31    /// simple label string.
32    ///
33    /// @since 3.14.0
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub label_offset_support: Option<bool>,
36}
37
38#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
39#[serde(rename_all = "camelCase")]
40pub struct SignatureHelpClientCapabilities {
41    /// Whether completion supports dynamic registration.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub dynamic_registration: Option<bool>,
44
45    /// The client supports the following `SignatureInformation`
46    /// specific properties.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub signature_information: Option<SignatureInformationSettings>,
49
50    /// The client supports to send additional context information for a
51    /// `textDocument/signatureHelp` request. A client that opts into
52    /// contextSupport will also support the `retriggerCharacters` on
53    /// `SignatureHelpOptions`.
54    ///
55    /// @since 3.15.0
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub context_support: Option<bool>,
58}
59
60/// Signature help options.
61#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
62#[serde(rename_all = "camelCase")]
63pub struct SignatureHelpOptions {
64    /// The characters that trigger signature help automatically.
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub trigger_characters: Option<Vec<String>>,
67
68    /// List of characters that re-trigger signature help.
69    /// These trigger characters are only active when signature help is already showing. All trigger characters
70    /// are also counted as re-trigger characters.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub retrigger_characters: Option<Vec<String>>,
73
74    #[serde(flatten)]
75    pub work_done_progress_options: WorkDoneProgressOptions,
76}
77
78/// Signature help options.
79#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
80pub struct SignatureHelpRegistrationOptions {
81    #[serde(flatten)]
82    pub text_document_registration_options: TextDocumentRegistrationOptions,
83}
84
85/// Signature help options.
86#[derive(Clone, PartialEq, Eq, Deserialize, Serialize)]
87#[serde(transparent)]
88pub struct SignatureHelpTriggerKind(i32);
89
90lsp_enum! {
91    impl SignatureHelpTriggerKind {
92        /// Signature help was invoked manually by the user or by a command.
93        const INVOKED = 1;
94        /// Signature help was triggered by a trigger character.
95        const TRIGGER_CHARACTER = 2;
96        /// Signature help was triggered by the cursor moving or by the document content changing.
97        const CONTENT_CHANGE = 3;
98    }
99}
100
101#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
102#[serde(rename_all = "camelCase")]
103pub struct SignatureHelpParams {
104    /// The signature help context. This is only available if the client specifies
105    /// to send this using the client capability  `textDocument.signatureHelp.contextSupport === true`
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub context: Option<SignatureHelpContext>,
108
109    #[serde(flatten)]
110    pub text_document_position_params: TextDocumentPositionParams,
111
112    #[serde(flatten)]
113    pub work_done_progress_params: WorkDoneProgressParams,
114}
115
116#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
117#[serde(rename_all = "camelCase")]
118pub struct SignatureHelpContext {
119    /// Action that caused signature help to be triggered.
120    pub trigger_kind: SignatureHelpTriggerKind,
121
122    /// Character that caused signature help to be triggered.
123    /// This is undefined when `triggerKind !== SignatureHelpTriggerKind.TriggerCharacter`
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub trigger_character: Option<String>,
126
127    /// `true` if signature help was already showing when it was triggered.
128    /// Retriggers occur when the signature help is already active and can be caused by actions such as
129    /// typing a trigger character, a cursor move, or document content changes.
130    pub is_retrigger: bool,
131
132    /// The currently active `SignatureHelp`.
133    /// The `activeSignatureHelp` has its `SignatureHelp.activeSignature` field updated based on
134    /// the user navigating through available signatures.
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub active_signature_help: Option<SignatureHelp>,
137}
138
139/// Signature help represents the signature of something
140/// callable. There can be multiple signature but only one
141/// active and only one active parameter.
142#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
143#[serde(rename_all = "camelCase")]
144pub struct SignatureHelp {
145    /// One or more signatures.
146    pub signatures: Vec<SignatureInformation>,
147
148    /// The active signature.
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub active_signature: Option<u32>,
151
152    /// The active parameter of the active signature.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub active_parameter: Option<u32>,
155}
156
157/// Represents the signature of something callable. A signature
158/// can have a label, like a function-name, a doc-comment, and
159/// a set of parameters.
160#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
161#[serde(rename_all = "camelCase")]
162pub struct SignatureInformation {
163    /// The label of this signature. Will be shown in
164    /// the UI.
165    pub label: String,
166
167    /// The human-readable doc-comment of this signature. Will be shown
168    /// in the UI but can be omitted.
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub documentation: Option<Documentation>,
171
172    /// The parameters of this signature.
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub parameters: Option<Vec<ParameterInformation>>,
175
176    /// The index of the active parameter.
177    ///
178    /// If provided, this is used in place of `SignatureHelp.activeParameter`.
179    ///
180    /// @since 3.16.0
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub active_parameter: Option<u32>,
183}
184
185/// Represents a parameter of a callable-signature. A parameter can
186/// have a label and a doc-comment.
187#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
188#[serde(rename_all = "camelCase")]
189pub struct ParameterInformation {
190    /// The label of this parameter information.
191    ///
192    /// Either a string or an inclusive start and exclusive end offsets within its containing
193    /// signature label. (see SignatureInformation.label). *Note*: A label of type string must be
194    /// a substring of its containing signature label.
195    pub label: ParameterLabel,
196
197    /// The human-readable doc-comment of this parameter. Will be shown
198    /// in the UI but can be omitted.
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub documentation: Option<Documentation>,
201}
202
203#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
204#[serde(untagged)]
205pub enum ParameterLabel {
206    Simple(String),
207    LabelOffsets([u32; 2]),
208}