lsp_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
38#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DocumentSymbolResponse {
41    Flat(Vec<SymbolInformation>),
42    Nested(Vec<DocumentSymbol>),
43}
44
45impl From<Vec<SymbolInformation>> for DocumentSymbolResponse {
46    fn from(info: Vec<SymbolInformation>) -> Self {
47        DocumentSymbolResponse::Flat(info)
48    }
49}
50
51impl From<Vec<DocumentSymbol>> for DocumentSymbolResponse {
52    fn from(symbols: Vec<DocumentSymbol>) -> Self {
53        DocumentSymbolResponse::Nested(symbols)
54    }
55}
56
57#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
58#[serde(rename_all = "camelCase")]
59pub struct DocumentSymbolParams {
60    /// The text document.
61    pub text_document: TextDocumentIdentifier,
62
63    #[serde(flatten)]
64    pub work_done_progress_params: WorkDoneProgressParams,
65
66    #[serde(flatten)]
67    pub partial_result_params: PartialResultParams,
68}
69
70/// Represents programming constructs like variables, classes, interfaces etc.
71/// that appear in a document. Document symbols can be hierarchical and they have two ranges:
72/// one that encloses its definition and one that points to its most interesting range,
73/// e.g. the range of an identifier.
74#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct DocumentSymbol {
77    /// The name of this symbol.
78    pub name: String,
79    /// More detail for this symbol, e.g the signature of a function. If not provided the
80    /// name is used.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub detail: Option<String>,
83    /// The kind of this symbol.
84    pub kind: SymbolKind,
85    /// Tags for this completion item.
86    ///
87    /// @since 3.15.0
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub tags: Option<Vec<SymbolTag>>,
90    /// Indicates if this symbol is deprecated.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    #[deprecated(note = "Use tags instead")]
93    pub deprecated: Option<bool>,
94    /// The range enclosing this symbol not including leading/trailing whitespace but everything else
95    /// like comments. This information is typically used to determine if the the clients cursor is
96    /// inside the symbol to reveal in the symbol in the UI.
97    pub range: Range,
98    /// The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
99    /// Must be contained by the the `range`.
100    pub selection_range: Range,
101    /// Children of this symbol, e.g. properties of a class.
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub children: Option<Vec<DocumentSymbol>>,
104}
105
106/// Represents information about programming constructs like variables, classes,
107/// interfaces etc.
108#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
109#[serde(rename_all = "camelCase")]
110pub struct SymbolInformation {
111    /// The name of this symbol.
112    pub name: String,
113
114    /// The kind of this symbol.
115    pub kind: SymbolKind,
116
117    /// Tags for this completion item.
118    ///
119    /// @since 3.16.0
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub tags: Option<Vec<SymbolTag>>,
122
123    /// Indicates if this symbol is deprecated.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    #[deprecated(note = "Use tags instead")]
126    pub deprecated: Option<bool>,
127
128    /// The location of this symbol.
129    pub location: Location,
130
131    /// The name of the symbol containing this symbol.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub container_name: Option<String>,
134}