diff options
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 09f602fe1..97ff67ee8 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -16,7 +16,6 @@ macro_rules! eprintln { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
19 | mod source_change; | ||
20 | 19 | ||
21 | mod prime_caches; | 20 | mod prime_caches; |
22 | mod status; | 21 | mod status; |
@@ -32,7 +31,6 @@ mod syntax_highlighting; | |||
32 | mod parent_module; | 31 | mod parent_module; |
33 | mod references; | 32 | mod references; |
34 | mod impls; | 33 | mod impls; |
35 | mod assists; | ||
36 | mod diagnostics; | 34 | mod diagnostics; |
37 | mod syntax_tree; | 35 | mod syntax_tree; |
38 | mod folding_ranges; | 36 | mod folding_ranges; |
@@ -44,11 +42,6 @@ mod inlay_hints; | |||
44 | mod expand_macro; | 42 | mod expand_macro; |
45 | mod ssr; | 43 | mod ssr; |
46 | 44 | ||
47 | #[cfg(test)] | ||
48 | mod marks; | ||
49 | #[cfg(test)] | ||
50 | mod test_utils; | ||
51 | |||
52 | use std::sync::Arc; | 45 | use std::sync::Arc; |
53 | 46 | ||
54 | use ra_cfg::CfgOptions; | 47 | use ra_cfg::CfgOptions; |
@@ -65,7 +58,6 @@ use ra_syntax::{SourceFile, TextRange, TextSize}; | |||
65 | use crate::display::ToNav; | 58 | use crate::display::ToNav; |
66 | 59 | ||
67 | pub use crate::{ | 60 | pub use crate::{ |
68 | assists::{Assist, AssistId}, | ||
69 | call_hierarchy::CallItem, | 61 | call_hierarchy::CallItem, |
70 | completion::{ | 62 | completion::{ |
71 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 63 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
@@ -78,7 +70,6 @@ pub use crate::{ | |||
78 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 70 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
79 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, | 71 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, |
80 | runnables::{Runnable, RunnableKind, TestId}, | 72 | runnables::{Runnable, RunnableKind, TestId}, |
81 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | ||
82 | ssr::SsrError, | 73 | ssr::SsrError, |
83 | syntax_highlighting::{ | 74 | syntax_highlighting::{ |
84 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 75 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, |
@@ -86,17 +77,19 @@ pub use crate::{ | |||
86 | }; | 77 | }; |
87 | 78 | ||
88 | pub use hir::Documentation; | 79 | pub use hir::Documentation; |
80 | pub use ra_assists::{AssistConfig, AssistId}; | ||
89 | pub use ra_db::{ | 81 | pub use ra_db::{ |
90 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, | 82 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, |
91 | }; | 83 | }; |
92 | pub use ra_ide_db::{ | 84 | pub use ra_ide_db::{ |
93 | change::{AnalysisChange, LibraryData}, | 85 | change::{AnalysisChange, LibraryData}, |
94 | line_index::{LineCol, LineIndex}, | 86 | line_index::{LineCol, LineIndex}, |
95 | line_index_utils::translate_offset_with_edit, | ||
96 | search::SearchScope, | 87 | search::SearchScope, |
88 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | ||
97 | symbol_index::Query, | 89 | symbol_index::Query, |
98 | RootDatabase, | 90 | RootDatabase, |
99 | }; | 91 | }; |
92 | pub use ra_text_edit::{Indel, TextEdit}; | ||
100 | 93 | ||
101 | pub type Cancelable<T> = Result<T, Canceled>; | 94 | pub type Cancelable<T> = Result<T, Canceled>; |
102 | 95 | ||
@@ -135,10 +128,12 @@ pub struct AnalysisHost { | |||
135 | db: RootDatabase, | 128 | db: RootDatabase, |
136 | } | 129 | } |
137 | 130 | ||
138 | impl Default for AnalysisHost { | 131 | #[derive(Debug)] |
139 | fn default() -> AnalysisHost { | 132 | pub struct Assist { |
140 | AnalysisHost::new(None) | 133 | pub id: AssistId, |
141 | } | 134 | pub label: String, |
135 | pub group_label: Option<String>, | ||
136 | pub source_change: SourceChange, | ||
142 | } | 137 | } |
143 | 138 | ||
144 | impl AnalysisHost { | 139 | impl AnalysisHost { |
@@ -176,18 +171,20 @@ impl AnalysisHost { | |||
176 | pub fn request_cancellation(&mut self) { | 171 | pub fn request_cancellation(&mut self) { |
177 | self.db.request_cancellation(); | 172 | self.db.request_cancellation(); |
178 | } | 173 | } |
179 | pub fn raw_database( | 174 | pub fn raw_database(&self) -> &RootDatabase { |
180 | &self, | ||
181 | ) -> &(impl hir::db::HirDatabase + salsa::Database + ra_db::SourceDatabaseExt) { | ||
182 | &self.db | 175 | &self.db |
183 | } | 176 | } |
184 | pub fn raw_database_mut( | 177 | pub fn raw_database_mut(&mut self) -> &mut RootDatabase { |
185 | &mut self, | ||
186 | ) -> &mut (impl hir::db::HirDatabase + salsa::Database + ra_db::SourceDatabaseExt) { | ||
187 | &mut self.db | 178 | &mut self.db |
188 | } | 179 | } |
189 | } | 180 | } |
190 | 181 | ||
182 | impl Default for AnalysisHost { | ||
183 | fn default() -> AnalysisHost { | ||
184 | AnalysisHost::new(None) | ||
185 | } | ||
186 | } | ||
187 | |||
191 | /// Analysis is a snapshot of a world state at a moment in time. It is the main | 188 | /// Analysis is a snapshot of a world state at a moment in time. It is the main |
192 | /// entry point for asking semantic information about the world. When the world | 189 | /// entry point for asking semantic information about the world. When the world |
193 | /// state is advanced using `AnalysisHost::apply_change` method, all existing | 190 | /// state is advanced using `AnalysisHost::apply_change` method, all existing |
@@ -289,14 +286,10 @@ impl Analysis { | |||
289 | 286 | ||
290 | /// Returns an edit to remove all newlines in the range, cleaning up minor | 287 | /// Returns an edit to remove all newlines in the range, cleaning up minor |
291 | /// stuff like trailing commas. | 288 | /// stuff like trailing commas. |
292 | pub fn join_lines(&self, frange: FileRange) -> Cancelable<SourceChange> { | 289 | pub fn join_lines(&self, frange: FileRange) -> Cancelable<TextEdit> { |
293 | self.with_db(|db| { | 290 | self.with_db(|db| { |
294 | let parse = db.parse(frange.file_id); | 291 | let parse = db.parse(frange.file_id); |
295 | let file_edit = SourceFileEdit { | 292 | join_lines::join_lines(&parse.tree(), frange.range) |
296 | file_id: frange.file_id, | ||
297 | edit: join_lines::join_lines(&parse.tree(), frange.range), | ||
298 | }; | ||
299 | SourceChange::source_file_edit("join lines", file_edit) | ||
300 | }) | 293 | }) |
301 | } | 294 | } |
302 | 295 | ||
@@ -456,16 +449,26 @@ impl Analysis { | |||
456 | /// Computes completions at the given position. | 449 | /// Computes completions at the given position. |
457 | pub fn completions( | 450 | pub fn completions( |
458 | &self, | 451 | &self, |
459 | position: FilePosition, | ||
460 | config: &CompletionConfig, | 452 | config: &CompletionConfig, |
453 | position: FilePosition, | ||
461 | ) -> Cancelable<Option<Vec<CompletionItem>>> { | 454 | ) -> Cancelable<Option<Vec<CompletionItem>>> { |
462 | self.with_db(|db| completion::completions(db, position, config).map(Into::into)) | 455 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) |
463 | } | 456 | } |
464 | 457 | ||
465 | /// Computes assists (aka code actions aka intentions) for the given | 458 | /// Computes assists (aka code actions aka intentions) for the given |
466 | /// position. | 459 | /// position. |
467 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> { | 460 | pub fn assists(&self, config: &AssistConfig, frange: FileRange) -> Cancelable<Vec<Assist>> { |
468 | self.with_db(|db| assists::assists(db, frange)) | 461 | self.with_db(|db| { |
462 | ra_assists::Assist::resolved(db, config, frange) | ||
463 | .into_iter() | ||
464 | .map(|assist| Assist { | ||
465 | id: assist.assist.id, | ||
466 | label: assist.assist.label, | ||
467 | group_label: assist.assist.group.map(|it| it.0), | ||
468 | source_change: assist.source_change, | ||
469 | }) | ||
470 | .collect() | ||
471 | }) | ||
469 | } | 472 | } |
470 | 473 | ||
471 | /// Computes the set of diagnostics for the given file. | 474 | /// Computes the set of diagnostics for the given file. |
@@ -490,7 +493,7 @@ impl Analysis { | |||
490 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 493 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
491 | self.with_db(|db| { | 494 | self.with_db(|db| { |
492 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 495 | let edits = ssr::parse_search_replace(query, parse_only, db)?; |
493 | Ok(SourceChange::source_file_edits("ssr", edits)) | 496 | Ok(SourceChange::source_file_edits("Structural Search Replace", edits)) |
494 | }) | 497 | }) |
495 | } | 498 | } |
496 | 499 | ||