mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
move typeof to hover
This commit is contained in:
parent
9f44d4c56d
commit
bdbdade036
3 changed files with 18 additions and 18 deletions
|
@ -2,7 +2,7 @@ use ra_db::{Cancelable, SyntaxDatabase};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
AstNode, SyntaxNode,
|
AstNode, SyntaxNode,
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
algo::visit::{visitor, Visitor},
|
algo::{find_covering_node, visit::{visitor, Visitor}},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
|
use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
|
||||||
|
@ -27,7 +27,7 @@ pub(crate) fn hover(
|
||||||
file_id: position.file_id,
|
file_id: position.file_id,
|
||||||
range: expr.syntax().range(),
|
range: expr.syntax().range(),
|
||||||
};
|
};
|
||||||
res.extend(db.type_of(frange)?);
|
res.extend(type_of(db, frange)?);
|
||||||
expr.syntax().range()
|
expr.syntax().range()
|
||||||
};
|
};
|
||||||
if res.is_empty() {
|
if res.is_empty() {
|
||||||
|
@ -37,6 +37,20 @@ pub(crate) fn hover(
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option<String>> {
|
||||||
|
let file = db.source_file(frange.file_id);
|
||||||
|
let syntax = file.syntax();
|
||||||
|
let node = find_covering_node(syntax, frange.range);
|
||||||
|
let parent_fn = ctry!(node.ancestors().find_map(ast::FnDef::cast));
|
||||||
|
let function = ctry!(hir::source_binder::function_from_source(
|
||||||
|
db,
|
||||||
|
frange.file_id,
|
||||||
|
parent_fn
|
||||||
|
)?);
|
||||||
|
let infer = function.infer(db)?;
|
||||||
|
Ok(infer.type_of_node(node).map(|t| t.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: this should not really use navigation target. Rather, approximatelly
|
// FIXME: this should not really use navigation target. Rather, approximatelly
|
||||||
// resovled symbol should return a `DefId`.
|
// resovled symbol should return a `DefId`.
|
||||||
fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<String>> {
|
||||||
|
|
|
@ -8,8 +8,7 @@ use hir::{
|
||||||
use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
|
use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
|
||||||
use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity};
|
use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::find_covering_node,
|
ast::{self, ArgListOwner, Expr, NameOwner},
|
||||||
ast::{self, ArgListOwner, Expr, FnDef, NameOwner},
|
|
||||||
AstNode, SourceFileNode,
|
AstNode, SourceFileNode,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
SyntaxNodeRef, TextRange, TextUnit,
|
SyntaxNodeRef, TextRange, TextUnit,
|
||||||
|
@ -398,19 +397,6 @@ impl db::RootDatabase {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
|
|
||||||
let file = self.source_file(frange.file_id);
|
|
||||||
let syntax = file.syntax();
|
|
||||||
let node = find_covering_node(syntax, frange.range);
|
|
||||||
let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast));
|
|
||||||
let function = ctry!(source_binder::function_from_source(
|
|
||||||
self,
|
|
||||||
frange.file_id,
|
|
||||||
parent_fn
|
|
||||||
)?);
|
|
||||||
let infer = function.infer(self)?;
|
|
||||||
Ok(infer.type_of_node(node).map(|t| t.to_string()))
|
|
||||||
}
|
|
||||||
pub(crate) fn rename(
|
pub(crate) fn rename(
|
||||||
&self,
|
&self,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
|
|
|
@ -450,7 +450,7 @@ impl Analysis {
|
||||||
}
|
}
|
||||||
/// Computes the type of the expression at the given position.
|
/// Computes the type of the expression at the given position.
|
||||||
pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
|
pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
|
||||||
self.db.type_of(frange)
|
hover::type_of(&*self.db, frange)
|
||||||
}
|
}
|
||||||
/// Returns the edit required to rename reference at the position to the new
|
/// Returns the edit required to rename reference at the position to the new
|
||||||
/// name.
|
/// name.
|
||||||
|
|
Loading…
Reference in a new issue