aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-28 15:03:03 +0000
committerAleksey Kladov <[email protected]>2018-12-28 15:17:43 +0000
commit02924174bb084d73cab67af6665ddf00e91983f6 (patch)
tree35e47a7e720a448a407fbca607f5895aacb68428 /crates/ra_analysis/src
parentd7440a5f4928415f2d2a9f7b2badaff8a9376a09 (diff)
introduce FileRange
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/imp.rs24
-rw-r--r--crates/ra_analysis/src/lib.rs16
2 files changed, 22 insertions, 18 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index e6663810d..fcb4cd957 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -23,7 +23,7 @@ use crate::{
23 AnalysisChange, 23 AnalysisChange,
24 Cancelable, 24 Cancelable,
25 completion::{CompletionItem, completions}, 25 completion::{CompletionItem, completions},
26 CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit, 26 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
27 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, 27 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
28 symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase}, 28 symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase},
29}; 29};
@@ -404,19 +404,21 @@ impl AnalysisImpl {
404 Ok(res) 404 Ok(res)
405 } 405 }
406 406
407 pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { 407 pub fn assists(&self, frange: FileRange) -> Vec<SourceChange> {
408 let file = self.file_syntax(file_id); 408 let file = self.file_syntax(frange.file_id);
409 let offset = range.start(); 409 let offset = frange.range.start();
410 let actions = vec![ 410 let actions = vec![
411 ra_editor::flip_comma(&file, offset).map(|f| f()), 411 ra_editor::flip_comma(&file, offset).map(|f| f()),
412 ra_editor::add_derive(&file, offset).map(|f| f()), 412 ra_editor::add_derive(&file, offset).map(|f| f()),
413 ra_editor::add_impl(&file, offset).map(|f| f()), 413 ra_editor::add_impl(&file, offset).map(|f| f()),
414 ra_editor::make_pub_crate(&file, offset).map(|f| f()), 414 ra_editor::make_pub_crate(&file, offset).map(|f| f()),
415 ra_editor::introduce_variable(&file, range).map(|f| f()), 415 ra_editor::introduce_variable(&file, frange.range).map(|f| f()),
416 ]; 416 ];
417 actions 417 actions
418 .into_iter() 418 .into_iter()
419 .filter_map(|local_edit| Some(SourceChange::from_local_edit(file_id, local_edit?))) 419 .filter_map(|local_edit| {
420 Some(SourceChange::from_local_edit(frange.file_id, local_edit?))
421 })
420 .collect() 422 .collect()
421 } 423 }
422 424
@@ -487,13 +489,15 @@ impl AnalysisImpl {
487 Ok(None) 489 Ok(None)
488 } 490 }
489 491
490 pub fn type_of(&self, file_id: FileId, range: TextRange) -> Cancelable<Option<String>> { 492 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
491 let file = self.db.source_file(file_id); 493 let file = self.db.source_file(frange.file_id);
492 let syntax = file.syntax(); 494 let syntax = file.syntax();
493 let node = find_covering_node(syntax, range); 495 let node = find_covering_node(syntax, frange.range);
494 let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); 496 let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast));
495 let function = ctry!(source_binder::function_from_source( 497 let function = ctry!(source_binder::function_from_source(
496 &*self.db, file_id, parent_fn 498 &*self.db,
499 frange.file_id,
500 parent_fn
497 )?); 501 )?);
498 let infer = function.infer(&*self.db)?; 502 let infer = function.infer(&*self.db)?;
499 Ok(infer.type_of_node(node).map(|t| t.to_string())) 503 Ok(infer.type_of_node(node).map(|t| t.to_string()))
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index b26e9e9ff..3fa4189ce 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -38,7 +38,7 @@ pub use ra_editor::{
38pub use hir::FnSignatureInfo; 38pub use hir::FnSignatureInfo;
39 39
40pub use ra_db::{ 40pub use ra_db::{
41 Canceled, Cancelable, FilePosition, 41 Canceled, Cancelable, FilePosition, FileRange,
42 CrateGraph, CrateId, SourceRootId, FileId 42 CrateGraph, CrateId, SourceRootId, FileId
43}; 43};
44 44
@@ -287,9 +287,9 @@ impl Analysis {
287 let file = self.imp.file_syntax(file_id); 287 let file = self.imp.file_syntax(file_id);
288 ra_editor::syntax_tree(&file) 288 ra_editor::syntax_tree(&file)
289 } 289 }
290 pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { 290 pub fn join_lines(&self, frange: FileRange) -> SourceChange {
291 let file = self.imp.file_syntax(file_id); 291 let file = self.imp.file_syntax(frange.file_id);
292 SourceChange::from_local_edit(file_id, ra_editor::join_lines(&file, range)) 292 SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range))
293 } 293 }
294 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { 294 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
295 let file = self.imp.file_syntax(position.file_id); 295 let file = self.imp.file_syntax(position.file_id);
@@ -346,8 +346,8 @@ impl Analysis {
346 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { 346 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
347 self.imp.completions(position) 347 self.imp.completions(position)
348 } 348 }
349 pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> { 349 pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> {
350 Ok(self.imp.assists(file_id, range)) 350 Ok(self.imp.assists(frange))
351 } 351 }
352 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 352 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
353 self.imp.diagnostics(file_id) 353 self.imp.diagnostics(file_id)
@@ -358,8 +358,8 @@ impl Analysis {
358 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { 358 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
359 self.imp.resolve_callable(position) 359 self.imp.resolve_callable(position)
360 } 360 }
361 pub fn type_of(&self, file_id: FileId, range: TextRange) -> Cancelable<Option<String>> { 361 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
362 self.imp.type_of(file_id, range) 362 self.imp.type_of(frange)
363 } 363 }
364} 364}
365 365