aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/imp.rs60
-rw-r--r--crates/ra_analysis/src/lib.rs5
2 files changed, 27 insertions, 38 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index a547c5a20..69c9b104e 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -3,31 +3,32 @@ use std::{
3 sync::Arc, 3 sync::Arc,
4}; 4};
5 5
6use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit, Severity};
7use ra_syntax::{
8 ast::{self, ArgListOwner, Expr, NameOwner, FnDef},
9 algo::find_covering_node,
10 AstNode, SourceFileNode,
11 SyntaxKind::*,
12 SyntaxNodeRef, TextRange, TextUnit,
13};
14use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
15use rayon::prelude::*; 6use rayon::prelude::*;
16use salsa::{Database, ParallelDatabase}; 7use salsa::{Database, ParallelDatabase};
8
17use hir::{ 9use hir::{
18 self, 10 self,
19 source_binder,
20 FnSignatureInfo, 11 FnSignatureInfo,
21 Problem, 12 Problem,
13 source_binder,
14};
15use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
16use ra_editor::{self, FileSymbol, find_node_at_offset, LineIndex, LocalEdit, Severity};
17use ra_syntax::{
18 algo::find_covering_node,
19 ast::{self, ArgListOwner, Expr, FnDef, NameOwner},
20 AstNode, SourceFileNode,
21 SyntaxKind::*,
22 SyntaxNodeRef, TextRange, TextUnit,
22}; 23};
23 24
24use crate::{ 25use crate::{
25 completion::{completions, CompletionItem}, 26 AnalysisChange,
26 db, 27 Cancelable,
27 symbol_index::{SymbolIndex, SymbolsDatabase, LibrarySymbolsQuery}, 28 completion::{CompletionItem, completions},
28 AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId, 29 CrateId, db, Diagnostic, FileId, FilePosition, FileSystemEdit,
29 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit, 30 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
30 ReferenceResolution, 31 symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase},
31}; 32};
32 33
33#[derive(Debug, Default)] 34#[derive(Debug, Default)]
@@ -366,7 +367,7 @@ impl AnalysisImpl {
366 range: d.range, 367 range: d.range,
367 message: d.msg, 368 message: d.msg,
368 severity: d.severity, 369 severity: d.severity,
369 fix: None, 370 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
370 }) 371 })
371 .collect::<Vec<_>>(); 372 .collect::<Vec<_>>();
372 if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? { 373 if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? {
@@ -425,25 +426,14 @@ impl AnalysisImpl {
425 let file = self.file_syntax(file_id); 426 let file = self.file_syntax(file_id);
426 let offset = range.start(); 427 let offset = range.start();
427 let actions = vec![ 428 let actions = vec![
428 ( 429 ra_editor::flip_comma(&file, offset).map(|f| f()),
429 "flip comma", 430 ra_editor::add_derive(&file, offset).map(|f| f()),
430 ra_editor::flip_comma(&file, offset).map(|f| f()), 431 ra_editor::add_impl(&file, offset).map(|f| f()),
431 ), 432 ra_editor::introduce_variable(&file, range).map(|f| f()),
432 (
433 "add `#[derive]`",
434 ra_editor::add_derive(&file, offset).map(|f| f()),
435 ),
436 ("add impl", ra_editor::add_impl(&file, offset).map(|f| f())),
437 (
438 "introduce variable",
439 ra_editor::introduce_variable(&file, range).map(|f| f()),
440 ),
441 ]; 433 ];
442 actions 434 actions
443 .into_iter() 435 .into_iter()
444 .filter_map(|(name, local_edit)| { 436 .filter_map(|local_edit| Some(SourceChange::from_local_edit(file_id, local_edit?)))
445 Some(SourceChange::from_local_edit(file_id, name, local_edit?))
446 })
447 .collect() 437 .collect()
448 } 438 }
449 439
@@ -541,13 +531,13 @@ impl AnalysisImpl {
541} 531}
542 532
543impl SourceChange { 533impl SourceChange {
544 pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { 534 pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange {
545 let file_edit = SourceFileEdit { 535 let file_edit = SourceFileEdit {
546 file_id, 536 file_id,
547 edit: edit.edit, 537 edit: edit.edit,
548 }; 538 };
549 SourceChange { 539 SourceChange {
550 label: label.to_string(), 540 label: edit.label,
551 source_file_edits: vec![file_edit], 541 source_file_edits: vec![file_edit],
552 file_system_edits: vec![], 542 file_system_edits: vec![],
553 cursor_position: edit 543 cursor_position: edit
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index a029f66b4..476d1b438 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -288,19 +288,18 @@ impl Analysis {
288 } 288 }
289 pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { 289 pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange {
290 let file = self.imp.file_syntax(file_id); 290 let file = self.imp.file_syntax(file_id);
291 SourceChange::from_local_edit(file_id, "join lines", ra_editor::join_lines(&file, range)) 291 SourceChange::from_local_edit(file_id, ra_editor::join_lines(&file, range))
292 } 292 }
293 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { 293 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
294 let file = self.imp.file_syntax(position.file_id); 294 let file = self.imp.file_syntax(position.file_id);
295 let edit = ra_editor::on_enter(&file, position.offset)?; 295 let edit = ra_editor::on_enter(&file, position.offset)?;
296 let res = SourceChange::from_local_edit(position.file_id, "on enter", edit); 296 let res = SourceChange::from_local_edit(position.file_id, edit);
297 Some(res) 297 Some(res)
298 } 298 }
299 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { 299 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
300 let file = self.imp.file_syntax(position.file_id); 300 let file = self.imp.file_syntax(position.file_id);
301 Some(SourceChange::from_local_edit( 301 Some(SourceChange::from_local_edit(
302 position.file_id, 302 position.file_id,
303 "add semicolon",
304 ra_editor::on_eq_typed(&file, position.offset)?, 303 ra_editor::on_eq_typed(&file, position.offset)?,
305 )) 304 ))
306 } 305 }