Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/static_index.rs')
-rw-r--r--crates/ide/src/static_index.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs
index 052de0f38e..0cf2e15bc6 100644
--- a/crates/ide/src/static_index.rs
+++ b/crates/ide/src/static_index.rs
@@ -10,7 +10,6 @@ use ide_db::{
documentation::Documentation,
famous_defs::FamousDefs,
};
-use span::Edition;
use syntax::{AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, T, TextRange};
use crate::navigation_target::UpmappingResult;
@@ -42,9 +41,18 @@ pub struct ReferenceData {
#[derive(Debug)]
pub struct TokenStaticData {
- pub documentation: Option<Documentation>,
+ // FIXME: Make this have the lifetime of the database.
+ pub documentation: Option<Documentation<'static>>,
pub hover: Option<HoverResult>,
+ /// The position of the token itself.
+ ///
+ /// For example, in `fn foo() {}` this is the position of `foo`.
pub definition: Option<FileRange>,
+ /// The position of the entire definition that this token belongs to.
+ ///
+ /// For example, in `fn foo() {}` this is the position from `fn`
+ /// to the closing brace.
+ pub definition_body: Option<FileRange>,
pub references: Vec<ReferenceData>,
pub moniker: Option<MonikerResult>,
pub display_name: Option<String>,
@@ -109,7 +117,7 @@ fn documentation_for_definition(
sema: &Semantics<'_, RootDatabase>,
def: Definition,
scope_node: &SyntaxNode,
-) -> Option<Documentation> {
+) -> Option<Documentation<'static>> {
let famous_defs = match &def {
Definition::BuiltinType(_) => Some(FamousDefs(sema, sema.scope(scope_node)?.krate())),
_ => None,
@@ -124,6 +132,7 @@ fn documentation_for_definition(
})
.to_display_target(sema.db),
)
+ .map(Documentation::into_owned)
}
// FIXME: This is a weird function
@@ -194,10 +203,7 @@ impl StaticIndex<'_> {
// hovers
let sema = hir::Semantics::new(self.db);
let root = sema.parse_guess_edition(file_id).syntax().clone();
- let edition = sema
- .attach_first_edition(file_id)
- .map(|it| it.edition(self.db))
- .unwrap_or(Edition::CURRENT);
+ let edition = sema.attach_first_edition(file_id).edition(sema.db);
let display_target = match sema.first_crate(file_id) {
Some(krate) => krate.to_display_target(sema.db),
None => return,
@@ -248,6 +254,10 @@ impl StaticIndex<'_> {
definition: def.try_to_nav(&sema).map(UpmappingResult::call_site).map(|it| {
FileRange { file_id: it.file_id, range: it.focus_or_full_range() }
}),
+ definition_body: def
+ .try_to_nav(&sema)
+ .map(UpmappingResult::call_site)
+ .map(|it| FileRange { file_id: it.file_id, range: it.full_range }),
references: vec![],
moniker: current_crate.and_then(|cc| def_to_moniker(self.db, def, cc)),
display_name: def