Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 7ad5329

Browse files
committed
Auto merge of #1295 - vhakulinen:hover-range, r=Xanewok
Implement range for hover response Implement optional `range` property for `textDocument/hover` response: https://microsoft.github.io/language-server-protocol/specification#textDocument_hover
2 parents 7070570 + 7c0d62b commit 7ad5329

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/actions/hover.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ use crate::server::ResponseError;
1818
use home;
1919
use racer;
2020
use rls_analysis::{Def, DefKind};
21-
use rls_span::{Column, Row, Span, ZeroIndexed};
21+
use rls_span::{Column, Range, Row, Span, ZeroIndexed};
2222
use rls_vfs::{self as vfs, Vfs};
2323
use rustfmt_nightly::NewlineStyle;
24+
use serde_derive::{Deserialize, Serialize};
2425

2526
use log::*;
2627
use std::path::{Path, PathBuf};
2728

29+
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
30+
pub struct Tooltip {
31+
pub contents: Vec<MarkedString>,
32+
pub range: Range<ZeroIndexed>,
33+
}
34+
2835
/// Cleanup documentation code blocks. The `docs` are expected to have
2936
/// the preceding `///` or `//!` prefixes already trimmed away. Rust code
3037
/// blocks will ignore lines beginning with `#`. Code block annotations
@@ -878,7 +885,7 @@ fn format_method(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
878885
pub fn tooltip(
879886
ctx: &InitActionContext,
880887
params: &TextDocumentPositionParams,
881-
) -> Result<Vec<MarkedString>, ResponseError> {
888+
) -> Result<Tooltip, ResponseError> {
882889
let analysis = &ctx.analysis;
883890

884891
let hover_file_path = parse_file_path!(&params.text_document.uri, "hover")?;
@@ -965,7 +972,7 @@ pub fn tooltip(
965972
Vec::default()
966973
};
967974
debug!("tooltip: contents.len: {}", contents.len());
968-
Ok(contents)
975+
Ok(Tooltip{ contents, range: hover_span.range })
969976
}
970977

971978
#[cfg(test)]

src/actions/requests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl RequestAction for Hover {
146146
let tooltip = hover::tooltip(&ctx, &params)?;
147147

148148
Ok(lsp_data::Hover {
149-
contents: HoverContents::Array(tooltip),
150-
range: None, // TODO: maybe add?
149+
contents: HoverContents::Array(tooltip.contents),
150+
range: Some(ls_util::rls_to_range(tooltip.range)),
151151
})
152152
}
153153
}

tests/tooltip.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl Test {
103103
let doc_id = TextDocumentIdentifier::new(url);
104104
let position = Position::new(self.line - 1u64, self.col - 1u64);
105105
let params = TextDocumentPositionParams::new(doc_id, position);
106-
let result = tooltip(&ctx, &params).map_err(|e| format!("tooltip error: {:?}", e));
106+
let result = tooltip(&ctx, &params)
107+
.map_err(|e| format!("tooltip error: {:?}", e))
108+
.map(|v| v.contents);
107109

108110
TestResult {
109111
test: self.clone(),

0 commit comments

Comments
 (0)