diff options
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 12d5716e8..5d1f64e19 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -17,6 +17,7 @@ macro_rules! eprintln { | |||
17 | 17 | ||
18 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
19 | 19 | ||
20 | mod markup; | ||
20 | mod prime_caches; | 21 | mod prime_caches; |
21 | mod status; | 22 | mod status; |
22 | mod completion; | 23 | mod completion; |
@@ -47,7 +48,7 @@ use std::sync::Arc; | |||
47 | use ra_cfg::CfgOptions; | 48 | use ra_cfg::CfgOptions; |
48 | use ra_db::{ | 49 | use ra_db::{ |
49 | salsa::{self, ParallelDatabase}, | 50 | salsa::{self, ParallelDatabase}, |
50 | CheckCanceled, Env, FileLoader, SourceDatabase, | 51 | CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, |
51 | }; | 52 | }; |
52 | use ra_ide_db::{ | 53 | use ra_ide_db::{ |
53 | symbol_index::{self, FileSymbol}, | 54 | symbol_index::{self, FileSymbol}, |
@@ -59,6 +60,7 @@ use crate::display::ToNav; | |||
59 | 60 | ||
60 | pub use crate::{ | 61 | pub use crate::{ |
61 | call_hierarchy::CallItem, | 62 | call_hierarchy::CallItem, |
63 | call_info::CallInfo, | ||
62 | completion::{ | 64 | completion::{ |
63 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 65 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
64 | }, | 66 | }, |
@@ -66,29 +68,31 @@ pub use crate::{ | |||
66 | display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, | 68 | display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, |
67 | expand_macro::ExpandedMacro, | 69 | expand_macro::ExpandedMacro, |
68 | folding_ranges::{Fold, FoldKind}, | 70 | folding_ranges::{Fold, FoldKind}, |
69 | hover::HoverResult, | 71 | hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, |
70 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 72 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
73 | markup::Markup, | ||
71 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, | 74 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, |
72 | runnables::{Runnable, RunnableKind, TestId}, | 75 | runnables::{Runnable, RunnableKind, TestId}, |
73 | ssr::SsrError, | ||
74 | syntax_highlighting::{ | 76 | syntax_highlighting::{ |
75 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 77 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, |
76 | }, | 78 | }, |
77 | }; | 79 | }; |
78 | 80 | ||
79 | pub use hir::Documentation; | 81 | pub use hir::{Documentation, Semantics}; |
80 | pub use ra_assists::{AssistConfig, AssistId}; | 82 | pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; |
81 | pub use ra_db::{ | 83 | pub use ra_db::{ |
82 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, | 84 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, |
85 | SourceRootId, | ||
83 | }; | 86 | }; |
84 | pub use ra_ide_db::{ | 87 | pub use ra_ide_db::{ |
85 | change::{AnalysisChange, LibraryData}, | 88 | change::AnalysisChange, |
86 | line_index::{LineCol, LineIndex}, | 89 | line_index::{LineCol, LineIndex}, |
87 | search::SearchScope, | 90 | search::SearchScope, |
88 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | 91 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, |
89 | symbol_index::Query, | 92 | symbol_index::Query, |
90 | RootDatabase, | 93 | RootDatabase, |
91 | }; | 94 | }; |
95 | pub use ra_ssr::SsrError; | ||
92 | pub use ra_text_edit::{Indel, TextEdit}; | 96 | pub use ra_text_edit::{Indel, TextEdit}; |
93 | 97 | ||
94 | pub type Cancelable<T> = Result<T, Canceled>; | 98 | pub type Cancelable<T> = Result<T, Canceled>; |
@@ -128,28 +132,12 @@ impl<T> RangeInfo<T> { | |||
128 | } | 132 | } |
129 | } | 133 | } |
130 | 134 | ||
131 | /// Contains information about a call site. Specifically the | ||
132 | /// `FunctionSignature`and current parameter. | ||
133 | #[derive(Debug)] | ||
134 | pub struct CallInfo { | ||
135 | pub signature: FunctionSignature, | ||
136 | pub active_parameter: Option<usize>, | ||
137 | } | ||
138 | |||
139 | /// `AnalysisHost` stores the current state of the world. | 135 | /// `AnalysisHost` stores the current state of the world. |
140 | #[derive(Debug)] | 136 | #[derive(Debug)] |
141 | pub struct AnalysisHost { | 137 | pub struct AnalysisHost { |
142 | db: RootDatabase, | 138 | db: RootDatabase, |
143 | } | 139 | } |
144 | 140 | ||
145 | #[derive(Debug)] | ||
146 | pub struct Assist { | ||
147 | pub id: AssistId, | ||
148 | pub label: String, | ||
149 | pub group_label: Option<String>, | ||
150 | pub source_change: SourceChange, | ||
151 | } | ||
152 | |||
153 | impl AnalysisHost { | 141 | impl AnalysisHost { |
154 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 142 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { |
155 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 143 | AnalysisHost { db: RootDatabase::new(lru_capacity) } |
@@ -220,11 +208,14 @@ impl Analysis { | |||
220 | // `AnalysisHost` for creating a fully-featured analysis. | 208 | // `AnalysisHost` for creating a fully-featured analysis. |
221 | pub fn from_single_file(text: String) -> (Analysis, FileId) { | 209 | pub fn from_single_file(text: String) -> (Analysis, FileId) { |
222 | let mut host = AnalysisHost::default(); | 210 | let mut host = AnalysisHost::default(); |
223 | let source_root = SourceRootId(0); | 211 | let file_id = FileId(0); |
212 | let mut file_set = FileSet::default(); | ||
213 | file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string())); | ||
214 | let source_root = SourceRoot::new_local(file_set); | ||
215 | |||
224 | let mut change = AnalysisChange::new(); | 216 | let mut change = AnalysisChange::new(); |
225 | change.add_root(source_root, true); | 217 | change.set_roots(vec![source_root]); |
226 | let mut crate_graph = CrateGraph::default(); | 218 | let mut crate_graph = CrateGraph::default(); |
227 | let file_id = FileId(0); | ||
228 | // FIXME: cfg options | 219 | // FIXME: cfg options |
229 | // Default to enable test for single file. | 220 | // Default to enable test for single file. |
230 | let mut cfg_options = CfgOptions::default(); | 221 | let mut cfg_options = CfgOptions::default(); |
@@ -236,9 +227,8 @@ impl Analysis { | |||
236 | cfg_options, | 227 | cfg_options, |
237 | Env::default(), | 228 | Env::default(), |
238 | Default::default(), | 229 | Default::default(), |
239 | Default::default(), | ||
240 | ); | 230 | ); |
241 | change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); | 231 | change.change_file(file_id, Some(Arc::new(text))); |
242 | change.set_crate_graph(crate_graph); | 232 | change.set_crate_graph(crate_graph); |
243 | host.apply_change(change); | 233 | host.apply_change(change); |
244 | (host.analysis(), file_id) | 234 | (host.analysis(), file_id) |
@@ -390,7 +380,9 @@ impl Analysis { | |||
390 | position: FilePosition, | 380 | position: FilePosition, |
391 | search_scope: Option<SearchScope>, | 381 | search_scope: Option<SearchScope>, |
392 | ) -> Cancelable<Option<ReferenceSearchResult>> { | 382 | ) -> Cancelable<Option<ReferenceSearchResult>> { |
393 | self.with_db(|db| references::find_all_refs(db, position, search_scope).map(|it| it.info)) | 383 | self.with_db(|db| { |
384 | references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info) | ||
385 | }) | ||
394 | } | 386 | } |
395 | 387 | ||
396 | /// Returns a short text describing element at position. | 388 | /// Returns a short text describing element at position. |
@@ -448,12 +440,14 @@ impl Analysis { | |||
448 | 440 | ||
449 | /// Computes syntax highlighting for the given file | 441 | /// Computes syntax highlighting for the given file |
450 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 442 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
451 | self.with_db(|db| syntax_highlighting::highlight(db, file_id, None)) | 443 | self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false)) |
452 | } | 444 | } |
453 | 445 | ||
454 | /// Computes syntax highlighting for the given file range. | 446 | /// Computes syntax highlighting for the given file range. |
455 | pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> { | 447 | pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> { |
456 | self.with_db(|db| syntax_highlighting::highlight(db, frange.file_id, Some(frange.range))) | 448 | self.with_db(|db| { |
449 | syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false) | ||
450 | }) | ||
457 | } | 451 | } |
458 | 452 | ||
459 | /// Computes syntax highlighting for the given file. | 453 | /// Computes syntax highlighting for the given file. |
@@ -470,20 +464,23 @@ impl Analysis { | |||
470 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) | 464 | self.with_db(|db| completion::completions(db, config, position).map(Into::into)) |
471 | } | 465 | } |
472 | 466 | ||
473 | /// Computes assists (aka code actions aka intentions) for the given | 467 | /// Computes resolved assists with source changes for the given position. |
468 | pub fn resolved_assists( | ||
469 | &self, | ||
470 | config: &AssistConfig, | ||
471 | frange: FileRange, | ||
472 | ) -> Cancelable<Vec<ResolvedAssist>> { | ||
473 | self.with_db(|db| ra_assists::Assist::resolved(db, config, frange)) | ||
474 | } | ||
475 | |||
476 | /// Computes unresolved assists (aka code actions aka intentions) for the given | ||
474 | /// position. | 477 | /// position. |
475 | pub fn assists(&self, config: &AssistConfig, frange: FileRange) -> Cancelable<Vec<Assist>> { | 478 | pub fn unresolved_assists( |
476 | self.with_db(|db| { | 479 | &self, |
477 | ra_assists::Assist::resolved(db, config, frange) | 480 | config: &AssistConfig, |
478 | .into_iter() | 481 | frange: FileRange, |
479 | .map(|assist| Assist { | 482 | ) -> Cancelable<Vec<Assist>> { |
480 | id: assist.assist.id, | 483 | self.with_db(|db| Assist::unresolved(db, config, frange)) |
481 | label: assist.assist.label, | ||
482 | group_label: assist.assist.group.map(|it| it.0), | ||
483 | source_change: assist.source_change, | ||
484 | }) | ||
485 | .collect() | ||
486 | }) | ||
487 | } | 484 | } |
488 | 485 | ||
489 | /// Computes the set of diagnostics for the given file. | 486 | /// Computes the set of diagnostics for the given file. |
@@ -508,7 +505,7 @@ impl Analysis { | |||
508 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 505 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
509 | self.with_db(|db| { | 506 | self.with_db(|db| { |
510 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 507 | let edits = ssr::parse_search_replace(query, parse_only, db)?; |
511 | Ok(SourceChange::source_file_edits(edits)) | 508 | Ok(SourceChange::from(edits)) |
512 | }) | 509 | }) |
513 | } | 510 | } |
514 | 511 | ||