Skip to main content

ruby_lsp/lsp/
mod.rs

1//! Ruby LSP functionality
2//!
3//! This module contains the LSP-related functionality for Ruby, including
4//! hover providers, highlighters, and formatters.
5
6pub mod formatter;
7pub mod highlighter;
8
9use core::range::Range;
10use oak_core::tree::RedNode;
11use oak_lsp::Hover;
12use oak_ruby::RubyLanguage;
13
14/// Hover provider implementation for Ruby.
15pub struct RubyHoverProvider;
16
17impl RubyHoverProvider {
18    /// Creates a new `RubyHoverProvider`.
19    pub fn new() -> Self {
20        Self
21    }
22}
23
24impl RubyHoverProvider {
25    /// Provides hover information for Ruby code.
26    pub fn hover(&self, node: &RedNode<RubyLanguage>, _range: Range<usize>) -> Option<Hover> {
27        let kind = node.green.kind;
28        // Provide context-aware hover information
29        let contents = match kind {
30            oak_ruby::RubyElementType::MethodDefinition => "### Ruby Method\nDefines a callable block of code.",
31            oak_ruby::RubyElementType::ClassDefinition => "### Ruby Class\nDefines a blueprint for objects.",
32            _ => return None,
33        };
34        Some(Hover { contents: contents.to_string(), range: Some(node.span()) })
35    }
36}