use oak_core::{Arc, Range, language::UniversalElementRole};
pub use oak_folding::FoldingRange;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LspRange {
pub start: usize,
pub end: usize,
}
impl From<Range<usize>> for LspRange {
fn from(range: Range<usize>) -> Self {
Self { start: range.start, end: range.end }
}
}
impl From<LspRange> for Range<usize> {
fn from(range: LspRange) -> Self {
Self { start: range.start, end: range.end }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(bound(serialize = "R: serde::Serialize", deserialize = "R: serde::Deserialize<'de>")))]
pub struct Location<R = Range<usize>> {
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_arc_str"))]
pub uri: Arc<str>,
pub range: R,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LocationRange {
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_arc_str"))]
pub uri: Arc<str>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub range: Range<usize>,
}
impl From<LocationRange> for Location<Range<usize>> {
fn from(loc: LocationRange) -> Self {
Self { uri: loc.uri, range: loc.range }
}
}
impl From<Location<Range<usize>>> for LocationRange {
fn from(loc: Location<Range<usize>>) -> Self {
Self { uri: loc.uri, range: loc.range }
}
}
impl From<oak_navigation::Location> for Location<Range<usize>> {
fn from(loc: oak_navigation::Location) -> Self {
Self { uri: loc.uri, range: loc.range }
}
}
impl From<oak_navigation::Location> for LocationRange {
fn from(loc: oak_navigation::Location) -> Self {
Self { uri: loc.uri, range: loc.range }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SourcePosition {
pub line: u32,
pub column: u32,
pub offset: usize,
pub length: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SourceLocation {
pub line: u32,
pub column: u32,
pub url: Option<url::Url>,
}
impl Default for SourceLocation {
fn default() -> Self {
Self { line: 1, column: 1, url: None }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DocumentHighlightKind {
Text = 1,
Read = 2,
Write = 3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DocumentHighlight {
pub range: LspRange,
pub kind: Option<DocumentHighlightKind>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Color {
pub red: f32,
pub green: f32,
pub blue: f32,
pub alpha: f32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ColorInformation {
pub range: LspRange,
pub color: Color,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hover {
pub contents: String,
#[cfg_attr(feature = "serde", serde(with = "serde_range_opt"))]
pub range: Option<Range<usize>>,
}
#[cfg(feature = "serde")]
mod serde_range_opt {
use super::*;
use serde::{Deserialize, Deserializer, Serializer};
pub fn serialize<S>(value: &Option<Range<usize>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match value {
Some(range) => oak_core::serde_range::serialize(range, serializer),
None => serializer.serialize_none(),
}
}
#[derive(Deserialize)]
struct RangeDef {
start: usize,
end: usize,
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Range<usize>>, D::Error>
where
D: Deserializer<'de>,
{
let opt: Option<RangeDef> = Option::deserialize(deserializer)?;
Ok(opt.map(|def| Range { start: def.start, end: def.end }))
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StructureItem {
pub name: String,
pub detail: Option<String>,
pub role: UniversalElementRole,
pub kind: SymbolKind,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub range: Range<usize>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub selection_range: Range<usize>,
pub deprecated: bool,
pub children: Vec<StructureItem>,
}
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeParams {
pub root_uri: Option<String>,
pub workspace_folders: Vec<WorkspaceFolder>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WorkspaceFolder {
pub uri: String,
pub name: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SymbolKind {
File = 1,
Module = 2,
Namespace = 3,
Package = 4,
Class = 5,
Method = 6,
Property = 7,
Field = 8,
Constructor = 9,
Enum = 10,
Interface = 11,
Function = 12,
Variable = 13,
Constant = 14,
String = 15,
Number = 16,
Boolean = 17,
Array = 18,
Object = 19,
Key = 20,
Null = 21,
EnumMember = 22,
Struct = 23,
Event = 24,
Operator = 25,
TypeParameter = 26,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WorkspaceSymbol {
pub name: String,
pub kind: SymbolKind,
pub location: LocationRange,
pub container_name: Option<String>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SymbolInformation {
pub name: String,
pub kind: SymbolKind,
pub location: LocationRange,
pub container_name: Option<String>,
}
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WorkspaceEdit {
pub changes: std::collections::HashMap<String, Vec<TextEdit>>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextEdit {
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub range: Range<usize>,
pub new_text: String,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CompletionItem {
pub label: String,
pub kind: Option<CompletionItemKind>,
pub detail: Option<String>,
pub documentation: Option<String>,
pub insert_text: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CompletionItemKind {
Text = 1,
Method = 2,
Function = 3,
Constructor = 4,
Field = 5,
Variable = 6,
Class = 7,
Interface = 8,
Module = 9,
Property = 10,
Unit = 11,
Value = 12,
Enum = 13,
Keyword = 14,
Snippet = 15,
Color = 16,
File = 17,
Reference = 18,
Folder = 19,
EnumMember = 20,
Constant = 21,
Struct = 22,
Event = 23,
Operator = 24,
TypeParameter = 25,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Diagnostic {
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub range: Range<usize>,
pub severity: Option<DiagnosticSeverity>,
pub code: Option<String>,
pub source: Option<String>,
pub message: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DiagnosticSeverity {
Error = 1,
Warning = 2,
Information = 3,
Hint = 4,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SemanticToken {
pub delta_line: u32,
pub delta_start: u32,
pub length: u32,
pub token_type: u32,
pub token_modifiers_bitset: u32,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SemanticTokens {
pub result_id: Option<String>,
pub data: Vec<SemanticToken>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SelectionRange {
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub range: Range<usize>,
pub parent: Option<Box<SelectionRange>>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParameterInformation {
pub label: String,
pub documentation: Option<String>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignatureInformation {
pub label: String,
pub documentation: Option<String>,
pub parameters: Option<Vec<ParameterInformation>>,
pub active_parameter: Option<u32>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignatureHelp {
pub signatures: Vec<SignatureInformation>,
pub active_signature: Option<u32>,
pub active_parameter: Option<u32>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InlayHint {
pub position: SourcePosition,
pub label: String,
pub kind: Option<InlayHintKind>,
pub tooltip: Option<String>,
pub padding_left: Option<bool>,
pub padding_right: Option<bool>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum InlayHintKind {
Type = 1,
Parameter = 2,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CodeAction {
pub title: String,
pub kind: Option<String>,
pub diagnostics: Option<Vec<Diagnostic>>,
pub edit: Option<WorkspaceEdit>,
pub command: Option<Command>,
pub is_preferred: Option<bool>,
pub disabled: Option<CodeActionDisabled>,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CodeActionDisabled {
pub reason: String,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Command {
pub title: String,
pub command: String,
pub arguments: Option<Vec<serde_json::Value>>,
}
impl From<UniversalElementRole> for SymbolKind {
fn from(role: UniversalElementRole) -> Self {
match role {
UniversalElementRole::Root => SymbolKind::File,
UniversalElementRole::Container => SymbolKind::Module,
UniversalElementRole::Definition => SymbolKind::Function,
UniversalElementRole::Binding => SymbolKind::Variable,
UniversalElementRole::Reference => SymbolKind::Variable,
UniversalElementRole::Typing => SymbolKind::Class,
UniversalElementRole::Statement => SymbolKind::Function,
UniversalElementRole::Expression => SymbolKind::Variable,
UniversalElementRole::Call => SymbolKind::Function,
UniversalElementRole::Metadata => SymbolKind::Property,
UniversalElementRole::Attribute => SymbolKind::Property,
UniversalElementRole::Documentation => SymbolKind::String,
UniversalElementRole::Value => SymbolKind::Constant,
UniversalElementRole::Error => SymbolKind::Null,
_ => SymbolKind::Function,
}
}
}
impl From<oak_symbols::SymbolInformation> for WorkspaceSymbol {
fn from(s: oak_symbols::SymbolInformation) -> Self {
Self { name: s.name, kind: SymbolKind::from(s.role), location: LocationRange { uri: s.uri, range: s.range }, container_name: s.container_name }
}
}
impl From<oak_symbols::SymbolInformation> for StructureItem {
fn from(s: oak_symbols::SymbolInformation) -> Self {
Self { name: s.name, detail: None, role: s.role, kind: SymbolKind::from(s.role), range: s.range.clone(), selection_range: s.range.clone(), deprecated: false, children: vec![] }
}
}