1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Language-agnostic symbol types.
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
/// A symbol found in the codebase.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SymbolInfo {
/// Symbol name (e.g. "MyStruct", "my_function")
pub name: String,
/// Fully qualified name path (e.g. "MyModule/MyStruct/my_method")
pub name_path: String,
pub kind: SymbolKind,
pub file: PathBuf,
/// 0-indexed start line (from LSP selectionRange — points to the symbol name).
pub start_line: u32,
/// 0-indexed end line
pub end_line: u32,
/// Full declaration start line (from LSP range.start — includes attributes, doc
/// comments, decorators). `None` when the source doesn't distinguish selection
/// vs full range (tree-sitter, workspace/symbol), meaning `start_line` already
/// covers the full declaration.
#[serde(default)]
pub range_start_line: Option<u32>,
/// 0-indexed start column
pub start_col: u32,
/// Children symbols (e.g. methods of a class)
pub children: Vec<SymbolInfo>,
/// LSP DocumentSymbol.detail — function signature or type annotation.
/// None when the LSP does not provide it (tree-sitter fallback, flat
/// SymbolInformation path, or symbols with no natural signature like structs).
#[serde(default)]
pub detail: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum SymbolKind {
File,
Module,
Namespace,
Package,
Class,
Method,
Property,
Field,
Constructor,
Enum,
Interface,
Function,
Variable,
Constant,
String,
Number,
Boolean,
Array,
Object,
Key,
Null,
EnumMember,
Struct,
Event,
Operator,
TypeParameter,
Unknown,
}
impl From<lsp_types::SymbolKind> for SymbolKind {
fn from(k: lsp_types::SymbolKind) -> Self {
use lsp_types::SymbolKind as L;
match k {
L::FILE => Self::File,
L::MODULE => Self::Module,
L::NAMESPACE => Self::Namespace,
L::PACKAGE => Self::Package,
L::CLASS => Self::Class,
L::METHOD => Self::Method,
L::PROPERTY => Self::Property,
L::FIELD => Self::Field,
L::CONSTRUCTOR => Self::Constructor,
L::ENUM => Self::Enum,
L::INTERFACE => Self::Interface,
L::FUNCTION => Self::Function,
L::VARIABLE => Self::Variable,
L::CONSTANT => Self::Constant,
L::STRING => Self::String,
L::NUMBER => Self::Number,
L::BOOLEAN => Self::Boolean,
L::ARRAY => Self::Array,
L::OBJECT => Self::Object,
L::KEY => Self::Key,
L::NULL => Self::Null,
L::ENUM_MEMBER => Self::EnumMember,
L::STRUCT => Self::Struct,
L::EVENT => Self::Event,
L::OPERATOR => Self::Operator,
L::TYPE_PARAMETER => Self::TypeParameter,
_ => Self::Unknown,
}
}
}