diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 60 |
1 files changed, 25 insertions, 35 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 | ||
6 | use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit, Severity}; | ||
7 | use ra_syntax::{ | ||
8 | ast::{self, ArgListOwner, Expr, NameOwner, FnDef}, | ||
9 | algo::find_covering_node, | ||
10 | AstNode, SourceFileNode, | ||
11 | SyntaxKind::*, | ||
12 | SyntaxNodeRef, TextRange, TextUnit, | ||
13 | }; | ||
14 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | ||
15 | use rayon::prelude::*; | 6 | use rayon::prelude::*; |
16 | use salsa::{Database, ParallelDatabase}; | 7 | use salsa::{Database, ParallelDatabase}; |
8 | |||
17 | use hir::{ | 9 | use hir::{ |
18 | self, | 10 | self, |
19 | source_binder, | ||
20 | FnSignatureInfo, | 11 | FnSignatureInfo, |
21 | Problem, | 12 | Problem, |
13 | source_binder, | ||
14 | }; | ||
15 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | ||
16 | use ra_editor::{self, FileSymbol, find_node_at_offset, LineIndex, LocalEdit, Severity}; | ||
17 | use 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 | ||
24 | use crate::{ | 25 | use 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 | ||
543 | impl SourceChange { | 533 | impl 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 |