feat: Extend the server with the hover_range capability
This commit is contained in:
parent
6a2a0b7abb
commit
20c64cc0e6
@ -241,6 +241,13 @@ fn try_hover_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option<RangeInfo
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn hover_range(
|
||||||
|
db: &RootDatabase,
|
||||||
|
range: FileRange,
|
||||||
|
config: &HoverConfig,
|
||||||
|
) -> Option<RangeInfo<HoverResult>> {
|
||||||
|
}
|
||||||
|
|
||||||
fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
|
fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
|
||||||
fn to_action(nav_target: NavigationTarget) -> HoverAction {
|
fn to_action(nav_target: NavigationTarget) -> HoverAction {
|
||||||
HoverAction::Implementation(FilePosition {
|
HoverAction::Implementation(FilePosition {
|
||||||
|
@ -423,6 +423,15 @@ pub fn hover(
|
|||||||
self.with_db(|db| hover::hover(db, position, config))
|
self.with_db(|db| hover::hover(db, position, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a short text displaying the type for the expression.
|
||||||
|
pub fn hover_range(
|
||||||
|
&self,
|
||||||
|
config: &HoverConfig,
|
||||||
|
range: FileRange,
|
||||||
|
) -> Cancellable<Option<RangeInfo<HoverResult>>> {
|
||||||
|
self.with_db(|db| hover::hover_range(db, range, config))
|
||||||
|
}
|
||||||
|
|
||||||
/// Return URL(s) for the documentation of the symbol under the cursor.
|
/// Return URL(s) for the documentation of the symbol under the cursor.
|
||||||
pub fn external_docs(
|
pub fn external_docs(
|
||||||
&self,
|
&self,
|
||||||
|
@ -867,14 +867,29 @@ pub(crate) fn handle_signature_help(
|
|||||||
|
|
||||||
pub(crate) fn handle_hover(
|
pub(crate) fn handle_hover(
|
||||||
snap: GlobalStateSnapshot,
|
snap: GlobalStateSnapshot,
|
||||||
params: lsp_types::HoverParams,
|
params: lsp_ext::HoverParams,
|
||||||
) -> Result<Option<lsp_ext::Hover>> {
|
) -> Result<Option<lsp_ext::Hover>> {
|
||||||
let _p = profile::span("handle_hover");
|
let _p = profile::span("handle_hover");
|
||||||
let position = from_proto::file_position(&snap, params.text_document_position_params)?;
|
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||||
let info = match snap.analysis.hover(&snap.config.hover(), position)? {
|
let range = from_proto::file_range(&snap, params.text_document, params.range)?;
|
||||||
None => return Ok(None),
|
|
||||||
Some(info) => info,
|
let info = if range.end - range.start == 1 {
|
||||||
|
// It's a hover over a position
|
||||||
|
match snap
|
||||||
|
.analysis
|
||||||
|
.hover(&snap.config.hover(), FilePosition { file_id, offset: range.start })?
|
||||||
|
{
|
||||||
|
None => return Ok(None),
|
||||||
|
Some(info) => info,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's a hover over a range
|
||||||
|
match snap.analysis.hover_range(&snap.config.hover(), range)? {
|
||||||
|
None => return Ok(None),
|
||||||
|
Some(info) => info,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let line_index = snap.file_line_index(position.file_id)?;
|
let line_index = snap.file_line_index(position.file_id)?;
|
||||||
let range = to_proto::range(&line_index, info.range);
|
let range = to_proto::range(&line_index, info.range);
|
||||||
let hover = lsp_ext::Hover {
|
let hover = lsp_ext::Hover {
|
||||||
|
@ -376,11 +376,18 @@ pub struct SnippetTextEdit {
|
|||||||
pub enum HoverRequest {}
|
pub enum HoverRequest {}
|
||||||
|
|
||||||
impl Request for HoverRequest {
|
impl Request for HoverRequest {
|
||||||
type Params = lsp_types::HoverParams;
|
type Params = HoverParams;
|
||||||
type Result = Option<Hover>;
|
type Result = Option<Hover>;
|
||||||
const METHOD: &'static str = "textDocument/hover";
|
const METHOD: &'static str = "textDocument/hover";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct HoverParams {
|
||||||
|
pub text_document: TextDocumentIdentifier,
|
||||||
|
pub range: Range,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
pub struct Hover {
|
pub struct Hover {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
Loading…
Reference in New Issue
Block a user