use LocalSyntaxPtr for file symbol
This commit is contained in:
parent
f534d2132b
commit
267a89bca2
@ -360,52 +360,52 @@ pub(crate) fn resolve_callable(
|
||||
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
||||
let file_symbols = self.index_resolve(name_ref)?;
|
||||
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);
|
||||
if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
|
||||
let descr = ctry!(source_binder::function_from_source(
|
||||
self, fn_file_id, fn_def
|
||||
)?);
|
||||
if let Some(descriptor) = descr.signature_info(self) {
|
||||
// If we have a calling expression let's find which argument we are on
|
||||
let mut current_parameter = None;
|
||||
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(
|
||||
self, fn_file_id, fn_def
|
||||
)?);
|
||||
if let Some(descriptor) = descr.signature_info(self) {
|
||||
// If we have a calling expression let's find which argument we are on
|
||||
let mut current_parameter = None;
|
||||
|
||||
let num_params = descriptor.params.len();
|
||||
let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
|
||||
let num_params = descriptor.params.len();
|
||||
let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
|
||||
|
||||
if num_params == 1 {
|
||||
if !has_self {
|
||||
current_parameter = Some(0);
|
||||
}
|
||||
} else if num_params > 1 {
|
||||
// Count how many parameters into the call we are.
|
||||
// TODO: This is best effort for now and should be fixed at some point.
|
||||
// It may be better to see where we are in the arg_list and then check
|
||||
// where offset is in that list (or beyond).
|
||||
// Revisit this after we get documentation comments in.
|
||||
if let Some(ref arg_list) = calling_node.arg_list() {
|
||||
let start = arg_list.syntax().range().start();
|
||||
|
||||
let range_search = TextRange::from_to(start, position.offset);
|
||||
let mut commas: usize = arg_list
|
||||
.syntax()
|
||||
.text()
|
||||
.slice(range_search)
|
||||
.to_string()
|
||||
.matches(',')
|
||||
.count();
|
||||
|
||||
// If we have a method call eat the first param since it's just self.
|
||||
if has_self {
|
||||
commas += 1;
|
||||
}
|
||||
|
||||
current_parameter = Some(commas);
|
||||
}
|
||||
if num_params == 1 {
|
||||
if !has_self {
|
||||
current_parameter = Some(0);
|
||||
}
|
||||
} else if num_params > 1 {
|
||||
// Count how many parameters into the call we are.
|
||||
// TODO: This is best effort for now and should be fixed at some point.
|
||||
// It may be better to see where we are in the arg_list and then check
|
||||
// where offset is in that list (or beyond).
|
||||
// Revisit this after we get documentation comments in.
|
||||
if let Some(ref arg_list) = calling_node.arg_list() {
|
||||
let start = arg_list.syntax().range().start();
|
||||
|
||||
return Ok(Some((descriptor, current_parameter)));
|
||||
let range_search = TextRange::from_to(start, position.offset);
|
||||
let mut commas: usize = arg_list
|
||||
.syntax()
|
||||
.text()
|
||||
.slice(range_search)
|
||||
.to_string()
|
||||
.matches(',')
|
||||
.count();
|
||||
|
||||
// If we have a method call eat the first param since it's just self.
|
||||
if has_self {
|
||||
commas += 1;
|
||||
}
|
||||
|
||||
current_parameter = Some(commas);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(Some((descriptor, current_parameter)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,9 +231,9 @@ impl NavigationTarget {
|
||||
fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget {
|
||||
NavigationTarget {
|
||||
name: symbol.name.clone(),
|
||||
kind: symbol.kind.clone(),
|
||||
kind: symbol.ptr.kind(),
|
||||
file_id,
|
||||
range: symbol.node_range.clone(),
|
||||
range: symbol.ptr.range(),
|
||||
}
|
||||
}
|
||||
pub fn name(&self) -> &SmolStr {
|
||||
|
@ -5,12 +5,12 @@
|
||||
|
||||
use fst::{self, Streamer};
|
||||
use ra_syntax::{
|
||||
SyntaxNodeRef, SourceFileNode, SmolStr, TextRange,
|
||||
SyntaxNodeRef, SourceFileNode, SmolStr,
|
||||
algo::visit::{visitor, Visitor},
|
||||
SyntaxKind::{self, *},
|
||||
ast::{self, NameOwner},
|
||||
};
|
||||
use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase};
|
||||
use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase, LocalSyntaxPtr};
|
||||
use salsa::ParallelDatabase;
|
||||
use rayon::prelude::*;
|
||||
|
||||
@ -140,7 +140,7 @@ pub(crate) fn search(self, indices: &[Arc<SymbolIndex>]) -> Vec<(FileId, FileSym
|
||||
let idx = indexed_value.value as usize;
|
||||
|
||||
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;
|
||||
}
|
||||
if self.exact && symbol.name != self.query {
|
||||
@ -163,9 +163,7 @@ fn is_type(kind: SyntaxKind) -> bool {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct FileSymbol {
|
||||
pub(crate) name: SmolStr,
|
||||
pub(crate) node_range: TextRange,
|
||||
pub(crate) kind: SyntaxKind,
|
||||
_x: (),
|
||||
pub(crate) ptr: LocalSyntaxPtr,
|
||||
}
|
||||
|
||||
fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
|
||||
@ -173,9 +171,7 @@ fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<FileSymbol> {
|
||||
let name = node.name()?;
|
||||
Some(FileSymbol {
|
||||
name: name.text(),
|
||||
node_range: node.syntax().range(),
|
||||
kind: node.syntax().kind(),
|
||||
_x: (),
|
||||
ptr: LocalSyntaxPtr::new(node.syntax()),
|
||||
})
|
||||
}
|
||||
visitor()
|
||||
|
Loading…
Reference in New Issue
Block a user