aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r--crates/ra_ide/src/lib.rs65
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
18pub mod mock_analysis; 18pub mod mock_analysis;
19mod source_change;
20 19
21mod prime_caches; 20mod prime_caches;
22mod status; 21mod status;
@@ -32,7 +31,6 @@ mod syntax_highlighting;
32mod parent_module; 31mod parent_module;
33mod references; 32mod references;
34mod impls; 33mod impls;
35mod assists;
36mod diagnostics; 34mod diagnostics;
37mod syntax_tree; 35mod syntax_tree;
38mod folding_ranges; 36mod folding_ranges;
@@ -44,11 +42,6 @@ mod inlay_hints;
44mod expand_macro; 42mod expand_macro;
45mod ssr; 43mod ssr;
46 44
47#[cfg(test)]
48mod marks;
49#[cfg(test)]
50mod test_utils;
51
52use std::sync::Arc; 45use std::sync::Arc;
53 46
54use ra_cfg::CfgOptions; 47use ra_cfg::CfgOptions;
@@ -65,7 +58,6 @@ use ra_syntax::{SourceFile, TextRange, TextSize};
65use crate::display::ToNav; 58use crate::display::ToNav;
66 59
67pub use crate::{ 60pub 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
88pub use hir::Documentation; 79pub use hir::Documentation;
80pub use ra_assists::{AssistConfig, AssistId};
89pub use ra_db::{ 81pub use ra_db::{
90 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, 82 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId,
91}; 83};
92pub use ra_ide_db::{ 84pub 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};
92pub use ra_text_edit::{Indel, TextEdit};
100 93
101pub type Cancelable<T> = Result<T, Canceled>; 94pub 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
138impl Default for AnalysisHost { 131#[derive(Debug)]
139 fn default() -> AnalysisHost { 132pub 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
144impl AnalysisHost { 139impl 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
182impl 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