ls_types/
document_symbols.rs

1use crate::{
2    Location, PartialResultParams, Range, SymbolKind, SymbolKindCapability, TextDocumentIdentifier,
3    WorkDoneProgressParams,
4};
5
6use crate::{SymbolTag, TagSupport};
7
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct DocumentSymbolClientCapabilities {
13    /// This capability supports dynamic registration.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub dynamic_registration: Option<bool>,
16
17    /// Specific capabilities for the `SymbolKind`.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub symbol_kind: Option<SymbolKindCapability>,
20
21    /// The client support hierarchical document symbols.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub hierarchical_document_symbol_support: Option<bool>,
24
25    /// The client supports tags on `SymbolInformation`. Tags are supported on
26    /// `DocumentSymbol` if `hierarchicalDocumentSymbolSupport` is set to true.
27    /// Clients supporting tags have to handle unknown tags gracefully.
28    ///
29    /// @since 3.16.0
30    #[serde(
31        default,
32        skip_serializing_if = "Option::is_none",
33        deserialize_with = "TagSupport::deserialize_compat"
34    )]
35    pub tag_support: Option<TagSupport<SymbolTag>>,
36
37    /// The client supports an additional label presented in the UI when
38    /// registering a document symbol provider.
39    ///
40    /// @since 3.16.0
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub label_support: Option<bool>,
43}
44
45#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum DocumentSymbolResponse {
48    Flat(Vec<SymbolInformation>),
49    Nested(Vec<DocumentSymbol>),
50}
51
52impl From<Vec<SymbolInformation>> for DocumentSymbolResponse {
53    fn from(info: Vec<SymbolInformation>) -> Self {
54        Self::Flat(info)
55    }
56}
57
58impl From<Vec<DocumentSymbol>> for DocumentSymbolResponse {
59    fn from(symbols: Vec<DocumentSymbol>) -> Self {
60        Self::Nested(symbols)
61    }
62}
63
64#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub struct DocumentSymbolParams {
67    /// The text document.
68    pub text_document: TextDocumentIdentifier,
69
70    #[serde(flatten)]
71    pub work_done_progress_params: WorkDoneProgressParams,
72
73    #[serde(flatten)]
74    pub partial_result_params: PartialResultParams,
75}
76
77/// Represents programming constructs like variables, classes, interfaces etc.
78///
79/// that appear in a document. Document symbols can be hierarchical and they have two ranges:
80/// one that encloses its definition and one that points to its most interesting range,
81/// e.g. the range of an identifier.
82#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
83#[serde(rename_all = "camelCase")]
84pub struct DocumentSymbol {
85    /// The name of this symbol.
86    pub name: String,
87    /// More detail for this symbol, e.g the signature of a function. If not provided the
88    /// name is used.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub detail: Option<String>,
91    /// The kind of this symbol.
92    pub kind: SymbolKind,
93    /// Tags for this completion item.
94    ///
95    /// @since 3.15.0
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub tags: Option<Vec<SymbolTag>>,
98    /// Indicates if this symbol is deprecated.
99    #[serde(skip_serializing_if = "Option::is_none")]
100    #[deprecated(note = "Use tags instead")]
101    pub deprecated: Option<bool>,
102    /// The range enclosing this symbol not including leading/trailing whitespace but everything else
103    /// like comments. This information is typically used to determine if the the clients cursor is
104    /// inside the symbol to reveal in the symbol in the UI.
105    pub range: Range,
106    /// The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
107    /// Must be contained by the the `range`.
108    pub selection_range: Range,
109    /// Children of this symbol, e.g. properties of a class.
110    #[serde(skip_serializing_if = "Option::is_none")]
111    pub children: Option<Vec<DocumentSymbol>>,
112}
113
114/// Represents information about programming constructs like variables, classes,
115/// interfaces etc.
116#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
117#[serde(rename_all = "camelCase")]
118pub struct SymbolInformation {
119    /// The name of this symbol.
120    pub name: String,
121
122    /// The kind of this symbol.
123    pub kind: SymbolKind,
124
125    /// Tags for this completion item.
126    ///
127    /// @since 3.16.0
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub tags: Option<Vec<SymbolTag>>,
130
131    /// Indicates if this symbol is deprecated.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    #[deprecated(note = "Use tags instead")]
134    pub deprecated: Option<bool>,
135
136    /// The location of this symbol.
137    pub location: Location,
138
139    /// The name of the symbol containing this symbol.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub container_name: Option<String>,
142}