mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
use LocalSyntaxPtr for file symbol
This commit is contained in:
parent
f534d2132b
commit
267a89bca2
3 changed files with 47 additions and 51 deletions
|
@ -360,9 +360,10 @@ impl db::RootDatabase {
|
||||||
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
||||||
let file_symbols = self.index_resolve(name_ref)?;
|
let file_symbols = self.index_resolve(name_ref)?;
|
||||||
for (fn_file_id, fs) in file_symbols {
|
for (fn_file_id, fs) in file_symbols {
|
||||||
if fs.kind == FN_DEF {
|
if fs.ptr.kind() == FN_DEF {
|
||||||
let fn_file = self.source_file(fn_file_id);
|
let fn_file = self.source_file(fn_file_id);
|
||||||
if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
|
let fn_def = fs.ptr.resolve(&fn_file);
|
||||||
|
let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap();
|
||||||
let descr = ctry!(source_binder::function_from_source(
|
let descr = ctry!(source_binder::function_from_source(
|
||||||
self, fn_file_id, fn_def
|
self, fn_file_id, fn_def
|
||||||
)?);
|
)?);
|
||||||
|
@ -408,7 +409,6 @@ impl db::RootDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,9 +231,9 @@ impl NavigationTarget {
|
||||||
fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget {
|
fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget {
|
||||||
NavigationTarget {
|
NavigationTarget {
|
||||||
name: symbol.name.clone(),
|
name: symbol.name.clone(),
|
||||||
kind: symbol.kind.clone(),
|
kind: symbol.ptr.kind(),
|
||||||
file_id,
|
file_id,
|
||||||
range: symbol.node_range.clone(),
|
range: symbol.ptr.range(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn name(&self) -> &SmolStr {
|
pub fn name(&self) -> &SmolStr {
|
||||||
|
|
|
@ -5,12 +5,12 @@ use std::{
|
||||||
|
|
||||||
use fst::{self, Streamer};
|
use fst::{self, Streamer};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SyntaxNodeRef, SourceFileNode, SmolStr, TextRange,
|
SyntaxNodeRef, SourceFileNode, SmolStr,
|
||||||
algo::visit::{visitor, Visitor},
|
algo::visit::{visitor, Visitor},
|
||||||
SyntaxKind::{self, *},
|
SyntaxKind::{self, *},
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
};
|
};
|
||||||
use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase};
|
use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase, LocalSyntaxPtr};
|
||||||
use salsa::ParallelDatabase;
|
use salsa::ParallelDatabase;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ impl Query {
|
||||||
let idx = indexed_value.value as usize;
|
let idx = indexed_value.value as usize;
|
||||||
|
|
||||||
let (file_id, symbol) = &file_symbols.symbols[idx];
|
let (file_id, symbol) = &file_symbols.symbols[idx];
|
||||||
if self.only_types && !is_type(symbol.kind) {
|
if self.only_types && !is_type(symbol.ptr.kind()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if self.exact && symbol.name != self.query {
|
if self.exact && symbol.name != self.query {
|
||||||
|
@ -163,9 +163,7 @@ fn is_type(kind: SyntaxKind) -> bool {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct FileSymbol {
|
pub(crate) struct FileSymbol {
|
||||||
pub(crate) name: SmolStr,
|
pub(crate) name: SmolStr,
|
||||||
pub(crate) node_range: TextRange,
|
pub(crate) ptr: LocalSyntaxPtr,
|
||||||
pub(crate) kind: SyntaxKind,
|
|
||||||
_x: (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
|
fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
|
||||||
|
@ -173,9 +171,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
|
||||||
let name = node.name()?;
|
let name = node.name()?;
|
||||||
Some(FileSymbol {
|
Some(FileSymbol {
|
||||||
name: name.text(),
|
name: name.text(),
|
||||||
node_range: node.syntax().range(),
|
ptr: LocalSyntaxPtr::new(node.syntax()),
|
||||||
kind: node.syntax().kind(),
|
|
||||||
_x: (),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
visitor()
|
visitor()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue