aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-02 20:24:58 +0000
committerAleksey Kladov <[email protected]>2019-01-03 09:26:40 +0000
commit267a89bca2b606faafacfe69db7fda1ef27bb39f (patch)
treeaeba5501cce0417dd79b0be0cab653589354523c /crates/ra_analysis
parentf534d2132b90fca8c0646cc81f8a60fa20423fe1 (diff)
use LocalSyntaxPtr for file symbol
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/imp.rs84
-rw-r--r--crates/ra_analysis/src/lib.rs4
-rw-r--r--crates/ra_analysis/src/symbol_index.rs14
3 files changed, 49 insertions, 53 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 5f67c95f6..7604c7def 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -360,52 +360,52 @@ impl db::RootDatabase {
360 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 360 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
361 let file_symbols = self.index_resolve(name_ref)?; 361 let file_symbols = self.index_resolve(name_ref)?;
362 for (fn_file_id, fs) in file_symbols { 362 for (fn_file_id, fs) in file_symbols {
363 if fs.kind == FN_DEF { 363 if fs.ptr.kind() == FN_DEF {
364 let fn_file = self.source_file(fn_file_id); 364 let fn_file = self.source_file(fn_file_id);
365 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { 365 let fn_def = fs.ptr.resolve(&fn_file);
366 let descr = ctry!(source_binder::function_from_source( 366 let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap();
367 self, fn_file_id, fn_def 367 let descr = ctry!(source_binder::function_from_source(
368 )?); 368 self, fn_file_id, fn_def
369 if let Some(descriptor) = descr.signature_info(self) { 369 )?);
370 // If we have a calling expression let's find which argument we are on 370 if let Some(descriptor) = descr.signature_info(self) {
371 let mut current_parameter = None; 371 // If we have a calling expression let's find which argument we are on
372 372 let mut current_parameter = None;
373 let num_params = descriptor.params.len(); 373
374 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); 374 let num_params = descriptor.params.len();
375 375 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
376 if num_params == 1 { 376
377 if !has_self { 377 if num_params == 1 {
378 current_parameter = Some(0); 378 if !has_self {
379 } 379 current_parameter = Some(0);
380 } else if num_params > 1 {
381 // Count how many parameters into the call we are.
382 // TODO: This is best effort for now and should be fixed at some point.
383 // It may be better to see where we are in the arg_list and then check
384 // where offset is in that list (or beyond).
385 // Revisit this after we get documentation comments in.
386 if let Some(ref arg_list) = calling_node.arg_list() {
387 let start = arg_list.syntax().range().start();
388
389 let range_search = TextRange::from_to(start, position.offset);
390 let mut commas: usize = arg_list
391 .syntax()
392 .text()
393 .slice(range_search)
394 .to_string()
395 .matches(',')
396 .count();
397
398 // If we have a method call eat the first param since it's just self.
399 if has_self {
400 commas += 1;
401 }
402
403 current_parameter = Some(commas);
404 }
405 } 380 }
381 } else if num_params > 1 {
382 // Count how many parameters into the call we are.
383 // TODO: This is best effort for now and should be fixed at some point.
384 // It may be better to see where we are in the arg_list and then check
385 // where offset is in that list (or beyond).
386 // Revisit this after we get documentation comments in.
387 if let Some(ref arg_list) = calling_node.arg_list() {
388 let start = arg_list.syntax().range().start();
389
390 let range_search = TextRange::from_to(start, position.offset);
391 let mut commas: usize = arg_list
392 .syntax()
393 .text()
394 .slice(range_search)
395 .to_string()
396 .matches(',')
397 .count();
398
399 // If we have a method call eat the first param since it's just self.
400 if has_self {
401 commas += 1;
402 }
406 403
407 return Ok(Some((descriptor, current_parameter))); 404 current_parameter = Some(commas);
405 }
408 } 406 }
407
408 return Ok(Some((descriptor, current_parameter)));
409 } 409 }
410 } 410 }
411 } 411 }
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 8247914c0..69d6754d6 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -231,9 +231,9 @@ impl NavigationTarget {
231 fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget { 231 fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget {
232 NavigationTarget { 232 NavigationTarget {
233 name: symbol.name.clone(), 233 name: symbol.name.clone(),
234 kind: symbol.kind.clone(), 234 kind: symbol.ptr.kind(),
235 file_id, 235 file_id,
236 range: symbol.node_range.clone(), 236 range: symbol.ptr.range(),
237 } 237 }
238 } 238 }
239 pub fn name(&self) -> &SmolStr { 239 pub fn name(&self) -> &SmolStr {
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index 65abaec2e..1b6815bbf 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -5,12 +5,12 @@ use std::{
5 5
6use fst::{self, Streamer}; 6use fst::{self, Streamer};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodeRef, SourceFileNode, SmolStr, TextRange, 8 SyntaxNodeRef, SourceFileNode, SmolStr,
9 algo::visit::{visitor, Visitor}, 9 algo::visit::{visitor, Visitor},
10 SyntaxKind::{self, *}, 10 SyntaxKind::{self, *},
11 ast::{self, NameOwner}, 11 ast::{self, NameOwner},
12}; 12};
13use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase}; 13use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase, LocalSyntaxPtr};
14use salsa::ParallelDatabase; 14use salsa::ParallelDatabase;
15use rayon::prelude::*; 15use rayon::prelude::*;
16 16
@@ -140,7 +140,7 @@ impl Query {
140 let idx = indexed_value.value as usize; 140 let idx = indexed_value.value as usize;
141 141
142 let (file_id, symbol) = &file_symbols.symbols[idx]; 142 let (file_id, symbol) = &file_symbols.symbols[idx];
143 if self.only_types && !is_type(symbol.kind) { 143 if self.only_types && !is_type(symbol.ptr.kind()) {
144 continue; 144 continue;
145 } 145 }
146 if self.exact && symbol.name != self.query { 146 if self.exact && symbol.name != self.query {
@@ -163,9 +163,7 @@ fn is_type(kind: SyntaxKind) -> bool {
163#[derive(Debug, Clone, PartialEq, Eq, Hash)] 163#[derive(Debug, Clone, PartialEq, Eq, Hash)]
164pub(crate) struct FileSymbol { 164pub(crate) struct FileSymbol {
165 pub(crate) name: SmolStr, 165 pub(crate) name: SmolStr,
166 pub(crate) node_range: TextRange, 166 pub(crate) ptr: LocalSyntaxPtr,
167 pub(crate) kind: SyntaxKind,
168 _x: (),
169} 167}
170 168
171fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> { 169fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
@@ -173,9 +171,7 @@ fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> {
173 let name = node.name()?; 171 let name = node.name()?;
174 Some(FileSymbol { 172 Some(FileSymbol {
175 name: name.text(), 173 name: name.text(),
176 node_range: node.syntax().range(), 174 ptr: LocalSyntaxPtr::new(node.syntax()),
177 kind: node.syntax().kind(),
178 _x: (),
179 }) 175 })
180 } 176 }
181 visitor() 177 visitor()