1use serde::{Deserialize, Serialize};
2
3pub mod reference;
4
5#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
6pub struct TextRange {
7 pub start_line: u32, pub end_line: u32, }
10
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12#[serde(rename_all = "snake_case")]
13pub enum SymbolKind {
14 Function,
15 Method,
16 Struct,
17 Enum,
18 Trait,
19 Module,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
23pub struct SymbolId(pub String);
24
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
26pub struct Symbol {
27 pub id: SymbolId,
28 pub name: String,
29 pub kind: SymbolKind,
30 pub file: String,
31 pub range: TextRange,
32 pub language: String,
33}
34
35impl SymbolId {
36 pub fn new(lang: &str, file: &str, kind: &SymbolKind, name: &str, start_line: u32) -> Self {
37 let k = match kind {
38 SymbolKind::Function => "fn",
39 SymbolKind::Method => "method",
40 SymbolKind::Struct => "struct",
41 SymbolKind::Enum => "enum",
42 SymbolKind::Trait => "trait",
43 SymbolKind::Module => "mod",
44 };
45 Self(format!("{}:{}:{}:{}:{}", lang, file, k, name, start_line))
46 }
47}