Файли
Pedro Pessoa 50567473f7 feat(plugins): let plugins add to the hover of any language (#1931)
Plugin API 1.3 gains an optional hover-provider export (worlds plugin-hover
and hover): hover(doc, at) returns Markdown and the range it describes. A
plugin declares the hover kind under [[contributes.providers]] for any
language; the host asks it with the language server, under the edit-path
budget, and shows the server's hover first and each plugin's below a rule.
Declaring the kind needs engines.openidea ^1.3. The Rust SDK gains
openidea_plugin::hover and register_plugin!(T, hover); every shipped
component is rebuilt for the WIT change.
2026-11-07 15:29:16 +08:00

39 рядки
991 B
Rust

use crate::types::{Position, Range};
pub use crate::providers::Document;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Hover {
pub markdown: String,
pub range: Option<Range>,
}
impl Hover {
pub fn new(markdown: impl Into<String>) -> Self {
Self { markdown: markdown.into(), range: None }
}
pub fn range(mut self, range: Range) -> Self {
self.range = Some(range);
self
}
}
pub trait HoverProvider {
fn hover(&mut self, doc: &Document, at: Position) -> Option<Hover>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_hover_can_name_the_range_it_describes() {
let range = Range { start: Position { line: 2, character: 4 }, end: Position { line: 2, character: 9 } };
let hover = Hover::new("**route** `orders.index`").range(range);
assert_eq!(hover.markdown, "**route** `orders.index`");
assert_eq!(hover.range, Some(range));
assert_eq!(Hover::new("x").range, None);
}
}