#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SymbolRange {
pub start: usize,
pub end: usize,
}
impl SymbolRange {
pub fn new(start: usize, end: usize) -> Self {
Self { start, end }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Utf16Position {
pub line: u32,
pub character: u32,
}
impl Utf16Position {
pub fn new(line: u32, character: u32) -> Self {
Self { line, character }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Utf16Range {
pub start: Utf16Position,
pub end: Utf16Position,
}
impl Utf16Range {
pub fn new(start: Utf16Position, end: Utf16Position) -> Self {
Self { start, end }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SymbolLocation {
pub uri: String,
pub range: Utf16Range,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
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,
Custom(u32),
}
impl SymbolKind {
pub fn from_lsp_kind(kind: u32) -> Self {
match kind {
1 => Self::File,
2 => Self::Module,
3 => Self::Namespace,
4 => Self::Package,
5 => Self::Class,
6 => Self::Method,
7 => Self::Property,
8 => Self::Field,
9 => Self::Constructor,
10 => Self::Enum,
11 => Self::Interface,
12 => Self::Function,
13 => Self::Variable,
14 => Self::Constant,
15 => Self::String,
16 => Self::Number,
17 => Self::Boolean,
18 => Self::Array,
19 => Self::Object,
20 => Self::Key,
21 => Self::Null,
22 => Self::EnumMember,
23 => Self::Struct,
24 => Self::Event,
25 => Self::Operator,
26 => Self::TypeParameter,
other => Self::Custom(other),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DocumentSymbol {
pub name: String,
pub detail: Option<String>,
pub kind: SymbolKind,
pub range: SymbolRange,
pub selection_range: SymbolRange,
pub children: Vec<DocumentSymbol>,
pub data_json: Option<String>,
}
impl DocumentSymbol {
pub fn flatten_preorder<'a>(&'a self, out: &mut Vec<&'a DocumentSymbol>) {
out.push(self);
for child in &self.children {
child.flatten_preorder(out);
}
}
pub fn find_by_name<'a>(&'a self, name: &str, out: &mut Vec<&'a DocumentSymbol>) {
if self.name == name {
out.push(self);
}
for child in &self.children {
child.find_by_name(name, out);
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct DocumentOutline {
pub symbols: Vec<DocumentSymbol>,
}
impl DocumentOutline {
pub fn new(symbols: Vec<DocumentSymbol>) -> Self {
Self { symbols }
}
pub fn is_empty(&self) -> bool {
self.symbols.is_empty()
}
pub fn top_level_count(&self) -> usize {
self.symbols.len()
}
pub fn flatten_preorder(&self) -> Vec<&DocumentSymbol> {
let mut out = Vec::new();
for sym in &self.symbols {
sym.flatten_preorder(&mut out);
}
out
}
pub fn find_by_name(&self, name: &str) -> Vec<&DocumentSymbol> {
let mut out = Vec::new();
for sym in &self.symbols {
sym.find_by_name(name, &mut out);
}
out
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkspaceSymbol {
pub name: String,
pub detail: Option<String>,
pub kind: SymbolKind,
pub location: SymbolLocation,
pub container_name: Option<String>,
pub data_json: Option<String>,
}