aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-02 16:20:56 +0000
committerAleksey Kladov <[email protected]>2019-01-02 16:20:56 +0000
commit08d1537468933910f22aa1cd517cae6b9f97d3ff (patch)
tree41d53c8c47531be6b35550d1cbded9437bd9376e /crates/ra_analysis/src
parente9b47dbb36d36b8fd7500e06581fd0ef687cc582 (diff)
get rid of AnalysisImpl
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/imp.rs118
-rw-r--r--crates/ra_analysis/src/lib.rs63
2 files changed, 80 insertions, 101 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index d9a3f97e9..0faf8b85d 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -1,9 +1,6 @@
1use std::{ 1use std::sync::Arc;
2 fmt,
3 sync::Arc,
4};
5 2
6use salsa::{Database, ParallelDatabase}; 3use salsa::Database;
7 4
8use hir::{ 5use hir::{
9 self, FnSignatureInfo, Problem, source_binder, 6 self, FnSignatureInfo, Problem, source_binder,
@@ -21,18 +18,12 @@ use ra_syntax::{
21use crate::{ 18use crate::{
22 AnalysisChange, 19 AnalysisChange,
23 Cancelable, NavigationTarget, 20 Cancelable, NavigationTarget,
24 completion::{CompletionItem, completions},
25 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, 21 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
26 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, 22 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
27 symbol_index::{LibrarySymbolsQuery, FileSymbol}, 23 symbol_index::{LibrarySymbolsQuery, FileSymbol},
28}; 24};
29 25
30impl db::RootDatabase { 26impl db::RootDatabase {
31 pub(crate) fn analysis(&self) -> AnalysisImpl {
32 AnalysisImpl {
33 db: self.snapshot(),
34 }
35 }
36 pub(crate) fn apply_change(&mut self, change: AnalysisChange) { 27 pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
37 log::info!("apply_change {:?}", change); 28 log::info!("apply_change {:?}", change);
38 // self.gc_syntax_trees(); 29 // self.gc_syntax_trees();
@@ -108,20 +99,9 @@ impl db::RootDatabase {
108 } 99 }
109} 100}
110 101
111pub(crate) struct AnalysisImpl { 102impl db::RootDatabase {
112 pub(crate) db: salsa::Snapshot<db::RootDatabase>,
113}
114
115impl fmt::Debug for AnalysisImpl {
116 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
117 let db: &db::RootDatabase = &self.db;
118 fmt.debug_struct("AnalysisImpl").field("db", db).finish()
119 }
120}
121
122impl AnalysisImpl {
123 pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { 103 pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> {
124 let descr = match source_binder::module_from_position(&*self.db, position)? { 104 let descr = match source_binder::module_from_position(self, position)? {
125 None => return Ok(None), 105 None => return Ok(None),
126 Some(it) => it, 106 Some(it) => it,
127 }; 107 };
@@ -143,12 +123,15 @@ impl AnalysisImpl {
143 123
144 /// This returns `Vec` because a module may be included from several places. We 124 /// This returns `Vec` because a module may be included from several places. We
145 /// don't handle this case yet though, so the Vec has length at most one. 125 /// don't handle this case yet though, so the Vec has length at most one.
146 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 126 pub(crate) fn parent_module(
147 let descr = match source_binder::module_from_position(&*self.db, position)? { 127 &self,
128 position: FilePosition,
129 ) -> Cancelable<Vec<NavigationTarget>> {
130 let descr = match source_binder::module_from_position(self, position)? {
148 None => return Ok(Vec::new()), 131 None => return Ok(Vec::new()),
149 Some(it) => it, 132 Some(it) => it,
150 }; 133 };
151 let (file_id, decl) = match descr.parent_link_source(&*self.db) { 134 let (file_id, decl) = match descr.parent_link_source(self) {
152 None => return Ok(Vec::new()), 135 None => return Ok(Vec::new()),
153 Some(it) => it, 136 Some(it) => it,
154 }; 137 };
@@ -162,39 +145,33 @@ impl AnalysisImpl {
162 Ok(vec![NavigationTarget { file_id, symbol }]) 145 Ok(vec![NavigationTarget { file_id, symbol }])
163 } 146 }
164 /// Returns `Vec` for the same reason as `parent_module` 147 /// Returns `Vec` for the same reason as `parent_module`
165 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 148 pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
166 let descr = match source_binder::module_from_file_id(&*self.db, file_id)? { 149 let descr = match source_binder::module_from_file_id(self, file_id)? {
167 None => return Ok(Vec::new()), 150 None => return Ok(Vec::new()),
168 Some(it) => it, 151 Some(it) => it,
169 }; 152 };
170 let root = descr.crate_root(); 153 let root = descr.crate_root();
171 let file_id = root.file_id(); 154 let file_id = root.file_id();
172 155
173 let crate_graph = self.db.crate_graph(); 156 let crate_graph = self.crate_graph();
174 let crate_id = crate_graph.crate_id_for_crate_root(file_id); 157 let crate_id = crate_graph.crate_id_for_crate_root(file_id);
175 Ok(crate_id.into_iter().collect()) 158 Ok(crate_id.into_iter().collect())
176 } 159 }
177 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 160 pub(crate) fn crate_root(&self, crate_id: CrateId) -> FileId {
178 self.db.crate_graph().crate_root(crate_id) 161 self.crate_graph().crate_root(crate_id)
179 }
180 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
181 let completions = completions(&self.db, position)?;
182 Ok(completions.map(|it| it.into()))
183 } 162 }
184 pub fn approximately_resolve_symbol( 163 pub(crate) fn approximately_resolve_symbol(
185 &self, 164 &self,
186 position: FilePosition, 165 position: FilePosition,
187 ) -> Cancelable<Option<ReferenceResolution>> { 166 ) -> Cancelable<Option<ReferenceResolution>> {
188 let file = self.db.source_file(position.file_id); 167 let file = self.source_file(position.file_id);
189 let syntax = file.syntax(); 168 let syntax = file.syntax();
190 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { 169 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
191 let mut rr = ReferenceResolution::new(name_ref.syntax().range()); 170 let mut rr = ReferenceResolution::new(name_ref.syntax().range());
192 if let Some(fn_descr) = source_binder::function_from_child_node( 171 if let Some(fn_descr) =
193 &*self.db, 172 source_binder::function_from_child_node(self, position.file_id, name_ref.syntax())?
194 position.file_id, 173 {
195 name_ref.syntax(), 174 let scope = fn_descr.scopes(self);
196 )? {
197 let scope = fn_descr.scopes(&*self.db);
198 // First try to resolve the symbol locally 175 // First try to resolve the symbol locally
199 if let Some(entry) = scope.resolve_local_name(name_ref) { 176 if let Some(entry) = scope.resolve_local_name(name_ref) {
200 rr.add_resolution( 177 rr.add_resolution(
@@ -219,7 +196,7 @@ impl AnalysisImpl {
219 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 196 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
220 if module.has_semi() { 197 if module.has_semi() {
221 if let Some(child_module) = 198 if let Some(child_module) =
222 source_binder::module_from_declaration(&*self.db, position.file_id, module)? 199 source_binder::module_from_declaration(self, position.file_id, module)?
223 { 200 {
224 let file_id = child_module.file_id(); 201 let file_id = child_module.file_id();
225 let name = match child_module.name() { 202 let name = match child_module.name() {
@@ -240,10 +217,13 @@ impl AnalysisImpl {
240 Ok(None) 217 Ok(None)
241 } 218 }
242 219
243 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 220 pub(crate) fn find_all_refs(
244 let file = self.db.source_file(position.file_id); 221 &self,
222 position: FilePosition,
223 ) -> Cancelable<Vec<(FileId, TextRange)>> {
224 let file = self.source_file(position.file_id);
245 // Find the binding associated with the offset 225 // Find the binding associated with the offset
246 let (binding, descr) = match find_binding(&self.db, &file, position)? { 226 let (binding, descr) = match find_binding(self, &file, position)? {
247 None => return Ok(Vec::new()), 227 None => return Ok(Vec::new()),
248 Some(it) => it, 228 Some(it) => it,
249 }; 229 };
@@ -255,7 +235,7 @@ impl AnalysisImpl {
255 .collect::<Vec<_>>(); 235 .collect::<Vec<_>>();
256 ret.extend( 236 ret.extend(
257 descr 237 descr
258 .scopes(&*self.db) 238 .scopes(self)
259 .find_all_refs(binding) 239 .find_all_refs(binding)
260 .into_iter() 240 .into_iter()
261 .map(|ref_desc| (position.file_id, ref_desc.range)), 241 .map(|ref_desc| (position.file_id, ref_desc.range)),
@@ -293,8 +273,8 @@ impl AnalysisImpl {
293 Ok(Some((binding, descr))) 273 Ok(Some((binding, descr)))
294 } 274 }
295 } 275 }
296 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { 276 pub(crate) fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
297 let file = self.db.source_file(nav.file_id); 277 let file = self.source_file(nav.file_id);
298 let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) { 278 let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) {
299 (Some(desc), Some(docs)) => { 279 (Some(desc), Some(docs)) => {
300 Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs) 280 Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs)
@@ -307,8 +287,8 @@ impl AnalysisImpl {
307 Ok(result) 287 Ok(result)
308 } 288 }
309 289
310 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 290 pub(crate) fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
311 let syntax = self.db.source_file(file_id); 291 let syntax = self.source_file(file_id);
312 292
313 let mut res = ra_editor::diagnostics(&syntax) 293 let mut res = ra_editor::diagnostics(&syntax)
314 .into_iter() 294 .into_iter()
@@ -319,9 +299,9 @@ impl AnalysisImpl {
319 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)), 299 fix: d.fix.map(|fix| SourceChange::from_local_edit(file_id, fix)),
320 }) 300 })
321 .collect::<Vec<_>>(); 301 .collect::<Vec<_>>();
322 if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? { 302 if let Some(m) = source_binder::module_from_file_id(self, file_id)? {
323 for (name_node, problem) in m.problems(&*self.db) { 303 for (name_node, problem) in m.problems(self) {
324 let source_root = self.db.file_source_root(file_id); 304 let source_root = self.file_source_root(file_id);
325 let diag = match problem { 305 let diag = match problem {
326 Problem::UnresolvedModule { candidate } => { 306 Problem::UnresolvedModule { candidate } => {
327 let create_file = FileSystemEdit::CreateFile { 307 let create_file = FileSystemEdit::CreateFile {
@@ -371,8 +351,8 @@ impl AnalysisImpl {
371 Ok(res) 351 Ok(res)
372 } 352 }
373 353
374 pub fn assists(&self, frange: FileRange) -> Vec<SourceChange> { 354 pub(crate) fn assists(&self, frange: FileRange) -> Vec<SourceChange> {
375 let file = self.db.source_file(frange.file_id); 355 let file = self.source_file(frange.file_id);
376 let offset = frange.range.start(); 356 let offset = frange.range.start();
377 let actions = vec![ 357 let actions = vec![
378 ra_editor::flip_comma(&file, offset).map(|f| f()), 358 ra_editor::flip_comma(&file, offset).map(|f| f()),
@@ -389,11 +369,11 @@ impl AnalysisImpl {
389 .collect() 369 .collect()
390 } 370 }
391 371
392 pub fn resolve_callable( 372 pub(crate) fn resolve_callable(
393 &self, 373 &self,
394 position: FilePosition, 374 position: FilePosition,
395 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { 375 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
396 let file = self.db.source_file(position.file_id); 376 let file = self.source_file(position.file_id);
397 let syntax = file.syntax(); 377 let syntax = file.syntax();
398 378
399 // Find the calling expression and it's NameRef 379 // Find the calling expression and it's NameRef
@@ -404,12 +384,12 @@ impl AnalysisImpl {
404 let file_symbols = self.index_resolve(name_ref)?; 384 let file_symbols = self.index_resolve(name_ref)?;
405 for (fn_file_id, fs) in file_symbols { 385 for (fn_file_id, fs) in file_symbols {
406 if fs.kind == FN_DEF { 386 if fs.kind == FN_DEF {
407 let fn_file = self.db.source_file(fn_file_id); 387 let fn_file = self.source_file(fn_file_id);
408 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { 388 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
409 let descr = ctry!(source_binder::function_from_source( 389 let descr = ctry!(source_binder::function_from_source(
410 &*self.db, fn_file_id, fn_def 390 self, fn_file_id, fn_def
411 )?); 391 )?);
412 if let Some(descriptor) = descr.signature_info(&*self.db) { 392 if let Some(descriptor) = descr.signature_info(self) {
413 // If we have a calling expression let's find which argument we are on 393 // If we have a calling expression let's find which argument we are on
414 let mut current_parameter = None; 394 let mut current_parameter = None;
415 395
@@ -456,20 +436,20 @@ impl AnalysisImpl {
456 Ok(None) 436 Ok(None)
457 } 437 }
458 438
459 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 439 pub(crate) fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
460 let file = self.db.source_file(frange.file_id); 440 let file = self.source_file(frange.file_id);
461 let syntax = file.syntax(); 441 let syntax = file.syntax();
462 let node = find_covering_node(syntax, frange.range); 442 let node = find_covering_node(syntax, frange.range);
463 let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); 443 let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast));
464 let function = ctry!(source_binder::function_from_source( 444 let function = ctry!(source_binder::function_from_source(
465 &*self.db, 445 self,
466 frange.file_id, 446 frange.file_id,
467 parent_fn 447 parent_fn
468 )?); 448 )?);
469 let infer = function.infer(&*self.db)?; 449 let infer = function.infer(self)?;
470 Ok(infer.type_of_node(node).map(|t| t.to_string())) 450 Ok(infer.type_of_node(node).map(|t| t.to_string()))
471 } 451 }
472 pub fn rename( 452 pub(crate) fn rename(
473 &self, 453 &self,
474 position: FilePosition, 454 position: FilePosition,
475 new_name: &str, 455 new_name: &str,
@@ -493,7 +473,7 @@ impl AnalysisImpl {
493 let mut query = Query::new(name.to_string()); 473 let mut query = Query::new(name.to_string());
494 query.exact(); 474 query.exact();
495 query.limit(4); 475 query.limit(4);
496 crate::symbol_index::world_symbols(&*self.db, query) 476 crate::symbol_index::world_symbols(self, query)
497 } 477 }
498} 478}
499 479
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 03994b7c4..efb483103 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -27,11 +27,9 @@ use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind};
27use ra_text_edit::TextEdit; 27use ra_text_edit::TextEdit;
28use rayon::prelude::*; 28use rayon::prelude::*;
29use relative_path::RelativePathBuf; 29use relative_path::RelativePathBuf;
30use salsa::ParallelDatabase;
30 31
31use crate::{ 32use crate::symbol_index::{SymbolIndex, FileSymbol};
32 imp::AnalysisImpl,
33 symbol_index::{SymbolIndex, FileSymbol},
34};
35 33
36pub use crate::{ 34pub use crate::{
37 completion::{CompletionItem, CompletionItemKind, InsertText}, 35 completion::{CompletionItem, CompletionItemKind, InsertText},
@@ -161,7 +159,7 @@ impl AnalysisHost {
161 /// semantic information. 159 /// semantic information.
162 pub fn analysis(&self) -> Analysis { 160 pub fn analysis(&self) -> Analysis {
163 Analysis { 161 Analysis {
164 imp: self.db.analysis(), 162 db: self.db.snapshot(),
165 } 163 }
166 } 164 }
167 /// Applies changes to the current state of the world. If there are 165 /// Applies changes to the current state of the world. If there are
@@ -293,56 +291,56 @@ impl ReferenceResolution {
293/// `Analysis` are canceled (most method return `Err(Canceled)`). 291/// `Analysis` are canceled (most method return `Err(Canceled)`).
294#[derive(Debug)] 292#[derive(Debug)]
295pub struct Analysis { 293pub struct Analysis {
296 pub(crate) imp: AnalysisImpl, 294 db: salsa::Snapshot<db::RootDatabase>,
297} 295}
298 296
299impl Analysis { 297impl Analysis {
300 pub fn file_text(&self, file_id: FileId) -> Arc<String> { 298 pub fn file_text(&self, file_id: FileId) -> Arc<String> {
301 self.imp.db.file_text(file_id) 299 self.db.file_text(file_id)
302 } 300 }
303 pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { 301 pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
304 self.imp.db.source_file(file_id).clone() 302 self.db.source_file(file_id).clone()
305 } 303 }
306 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 304 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
307 self.imp.db.file_lines(file_id) 305 self.db.file_lines(file_id)
308 } 306 }
309 pub fn extend_selection(&self, frange: FileRange) -> TextRange { 307 pub fn extend_selection(&self, frange: FileRange) -> TextRange {
310 extend_selection::extend_selection(&self.imp.db, frange) 308 extend_selection::extend_selection(&self.db, frange)
311 } 309 }
312 pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { 310 pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
313 ra_editor::matching_brace(file, offset) 311 ra_editor::matching_brace(file, offset)
314 } 312 }
315 pub fn syntax_tree(&self, file_id: FileId) -> String { 313 pub fn syntax_tree(&self, file_id: FileId) -> String {
316 let file = self.imp.db.source_file(file_id); 314 let file = self.db.source_file(file_id);
317 ra_editor::syntax_tree(&file) 315 ra_editor::syntax_tree(&file)
318 } 316 }
319 pub fn join_lines(&self, frange: FileRange) -> SourceChange { 317 pub fn join_lines(&self, frange: FileRange) -> SourceChange {
320 let file = self.imp.db.source_file(frange.file_id); 318 let file = self.db.source_file(frange.file_id);
321 SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range)) 319 SourceChange::from_local_edit(frange.file_id, ra_editor::join_lines(&file, frange.range))
322 } 320 }
323 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { 321 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
324 let file = self.imp.db.source_file(position.file_id); 322 let file = self.db.source_file(position.file_id);
325 let edit = ra_editor::on_enter(&file, position.offset)?; 323 let edit = ra_editor::on_enter(&file, position.offset)?;
326 let res = SourceChange::from_local_edit(position.file_id, edit); 324 let res = SourceChange::from_local_edit(position.file_id, edit);
327 Some(res) 325 Some(res)
328 } 326 }
329 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { 327 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
330 let file = self.imp.db.source_file(position.file_id); 328 let file = self.db.source_file(position.file_id);
331 Some(SourceChange::from_local_edit( 329 Some(SourceChange::from_local_edit(
332 position.file_id, 330 position.file_id,
333 ra_editor::on_eq_typed(&file, position.offset)?, 331 ra_editor::on_eq_typed(&file, position.offset)?,
334 )) 332 ))
335 } 333 }
336 pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { 334 pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> {
337 let file = self.imp.db.source_file(file_id); 335 let file = self.db.source_file(file_id);
338 ra_editor::file_structure(&file) 336 ra_editor::file_structure(&file)
339 } 337 }
340 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { 338 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
341 let file = self.imp.db.source_file(file_id); 339 let file = self.db.source_file(file_id);
342 ra_editor::folding_ranges(&file) 340 ra_editor::folding_ranges(&file)
343 } 341 }
344 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { 342 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
345 let res = symbol_index::world_symbols(&*self.imp.db, query)? 343 let res = symbol_index::world_symbols(&*self.db, query)?
346 .into_iter() 344 .into_iter()
347 .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) 345 .map(|(file_id, symbol)| NavigationTarget { file_id, symbol })
348 .collect(); 346 .collect();
@@ -352,57 +350,58 @@ impl Analysis {
352 &self, 350 &self,
353 position: FilePosition, 351 position: FilePosition,
354 ) -> Cancelable<Option<ReferenceResolution>> { 352 ) -> Cancelable<Option<ReferenceResolution>> {
355 self.imp.approximately_resolve_symbol(position) 353 self.db.approximately_resolve_symbol(position)
356 } 354 }
357 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 355 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
358 self.imp.find_all_refs(position) 356 self.db.find_all_refs(position)
359 } 357 }
360 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { 358 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
361 self.imp.doc_text_for(nav) 359 self.db.doc_text_for(nav)
362 } 360 }
363 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 361 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
364 self.imp.parent_module(position) 362 self.db.parent_module(position)
365 } 363 }
366 pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { 364 pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> {
367 self.imp.module_path(position) 365 self.db.module_path(position)
368 } 366 }
369 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 367 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
370 self.imp.crate_for(file_id) 368 self.db.crate_for(file_id)
371 } 369 }
372 pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { 370 pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> {
373 Ok(self.imp.crate_root(crate_id)) 371 Ok(self.db.crate_root(crate_id))
374 } 372 }
375 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { 373 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
376 let file = self.imp.db.source_file(file_id); 374 let file = self.db.source_file(file_id);
377 Ok(runnables::runnables(self, &file, file_id)) 375 Ok(runnables::runnables(self, &file, file_id))
378 } 376 }
379 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 377 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
380 syntax_highlighting::highlight(&*self.imp.db, file_id) 378 syntax_highlighting::highlight(&*self.db, file_id)
381 } 379 }
382 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { 380 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
383 self.imp.completions(position) 381 let completions = completion::completions(&self.db, position)?;
382 Ok(completions.map(|it| it.into()))
384 } 383 }
385 pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { 384 pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> {
386 Ok(self.imp.assists(frange)) 385 Ok(self.db.assists(frange))
387 } 386 }
388 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 387 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
389 self.imp.diagnostics(file_id) 388 self.db.diagnostics(file_id)
390 } 389 }
391 pub fn resolve_callable( 390 pub fn resolve_callable(
392 &self, 391 &self,
393 position: FilePosition, 392 position: FilePosition,
394 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { 393 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
395 self.imp.resolve_callable(position) 394 self.db.resolve_callable(position)
396 } 395 }
397 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 396 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
398 self.imp.type_of(frange) 397 self.db.type_of(frange)
399 } 398 }
400 pub fn rename( 399 pub fn rename(
401 &self, 400 &self,
402 position: FilePosition, 401 position: FilePosition,
403 new_name: &str, 402 new_name: &str,
404 ) -> Cancelable<Vec<SourceFileEdit>> { 403 ) -> Cancelable<Vec<SourceFileEdit>> {
405 self.imp.rename(position, new_name) 404 self.db.rename(position, new_name)
406 } 405 }
407} 406}
408 407