Skip to main content

Mountain/Command/Hover/
Interface.rs

1//! # Hover Interface
2//!
3//! Defines types and traits for hover functionality.
4//!
5//! ## Responsibilities
6//!
7//! - Position and range types for document navigation
8//! - Hover request/response DTOs
9//! - Language-agnostic hover content definitions
10//!
11//! ## Architectural Role
12//!
13//! This module is part of the **Command layer**, providing type definitions
14//! for the Hover language feature command.
15
16use serde::{Deserialize, Serialize};
17
18/// Position in a document (LSP-compatible)
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Position {
21	/// Zero-based line number
22	pub line:u32,
23	/// Zero-based character offset within the line
24	pub character:u32,
25}
26
27/// A range in a document
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct Range {
30	/// Start of the range
31	pub start:Position,
32	/// End of the range
33	pub end:Position,
34}
35
36/// Request payload for hover operation
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct HoverRequest {
39	/// The URI of the document to get hover for
40	pub uri:String,
41	/// The position in the document
42	pub position:Position,
43}
44
45/// Represents the content of a hover result
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(tag = "kind", content = "value")]
48pub enum HoverContent {
49	/// Plain text content
50	PlainText(String),
51	/// Markdown content
52	Markdown(String),
53	/// Structured content with language
54	Markup {
55		/// The content value
56		value:String,
57		/// The programming language (if applicable)
58		language:Option<String>,
59	},
60}
61
62/// Response from hover operation
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct HoverResponse {
65	/// The hover contents
66	pub contents:Vec<HoverContent>,
67	/// Optional range this hover applies to
68	#[serde(skip_serializing_if = "Option::is_none")]
69	pub range:Option<Range>,
70}
71
72impl Default for HoverResponse {
73	fn default() -> Self { Self { contents:Vec::new(), range:None } }
74}
75
76impl HoverResponse {
77	/// Create a new hover response with content
78	pub fn new(contents:Vec<HoverContent>) -> Self { Self { contents, range:None } }
79
80	/// Create a hover response with content and range
81	pub fn with_range(contents:Vec<HoverContent>, range:Range) -> Self { Self { contents, range:Some(range) } }
82}