diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 819827b95..74c248a96 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -7,7 +7,7 @@ use std::{ | |||
7 | use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; | 7 | use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; |
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | ast::{self, ArgListOwner, Expr, NameOwner}, | 9 | ast::{self, ArgListOwner, Expr, NameOwner}, |
10 | AstNode, File, SmolStr, | 10 | AstNode, SourceFileNode, SmolStr, |
11 | SyntaxKind::*, | 11 | SyntaxKind::*, |
12 | SyntaxNodeRef, TextRange, TextUnit, | 12 | SyntaxNodeRef, TextRange, TextUnit, |
13 | }; | 13 | }; |
@@ -17,7 +17,7 @@ use rustc_hash::FxHashSet; | |||
17 | use salsa::{Database, ParallelDatabase}; | 17 | use salsa::{Database, ParallelDatabase}; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | completion::{resolve_based_completion, scope_completion, CompletionItem}, | 20 | completion::{completions, CompletionItem}, |
21 | db::{self, FileSyntaxQuery, SyntaxDatabase}, | 21 | db::{self, FileSyntaxQuery, SyntaxDatabase}, |
22 | descriptors::{ | 22 | descriptors::{ |
23 | function::{FnDescriptor, FnId}, | 23 | function::{FnDescriptor, FnId}, |
@@ -27,7 +27,7 @@ use crate::{ | |||
27 | input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, | 27 | input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, |
28 | symbol_index::SymbolIndex, | 28 | symbol_index::SymbolIndex, |
29 | AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, | 29 | AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, |
30 | FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit, | 30 | FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | #[derive(Clone, Debug)] | 33 | #[derive(Clone, Debug)] |
@@ -180,7 +180,7 @@ impl fmt::Debug for AnalysisImpl { | |||
180 | } | 180 | } |
181 | 181 | ||
182 | impl AnalysisImpl { | 182 | impl AnalysisImpl { |
183 | pub fn file_syntax(&self, file_id: FileId) -> File { | 183 | pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { |
184 | self.db.file_syntax(file_id) | 184 | self.db.file_syntax(file_id) |
185 | } | 185 | } |
186 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 186 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
@@ -226,7 +226,7 @@ impl AnalysisImpl { | |||
226 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) | 226 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) |
227 | { | 227 | { |
228 | Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), | 228 | Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), |
229 | _ => ModuleSource::File(position.file_id), | 229 | _ => ModuleSource::SourceFile(position.file_id), |
230 | }; | 230 | }; |
231 | 231 | ||
232 | let res = module_tree | 232 | let res = module_tree |
@@ -254,7 +254,7 @@ impl AnalysisImpl { | |||
254 | let module_tree = self.module_tree(file_id)?; | 254 | let module_tree = self.module_tree(file_id)?; |
255 | let crate_graph = self.db.crate_graph(); | 255 | let crate_graph = self.db.crate_graph(); |
256 | let res = module_tree | 256 | let res = module_tree |
257 | .modules_for_source(ModuleSource::File(file_id)) | 257 | .modules_for_source(ModuleSource::SourceFile(file_id)) |
258 | .into_iter() | 258 | .into_iter() |
259 | .map(|it| it.root(&module_tree)) | 259 | .map(|it| it.root(&module_tree)) |
260 | .filter_map(|it| it.source(&module_tree).as_file()) | 260 | .filter_map(|it| it.source(&module_tree).as_file()) |
@@ -267,18 +267,7 @@ impl AnalysisImpl { | |||
267 | self.db.crate_graph().crate_roots[&crate_id] | 267 | self.db.crate_graph().crate_roots[&crate_id] |
268 | } | 268 | } |
269 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 269 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
270 | let mut res = Vec::new(); | 270 | completions(&self.db, position) |
271 | let mut has_completions = false; | ||
272 | if let Some(scope_based) = scope_completion(&self.db, position) { | ||
273 | res.extend(scope_based); | ||
274 | has_completions = true; | ||
275 | } | ||
276 | if let Some(scope_based) = resolve_based_completion(&self.db, position)? { | ||
277 | res.extend(scope_based); | ||
278 | has_completions = true; | ||
279 | } | ||
280 | let res = if has_completions { Some(res) } else { None }; | ||
281 | Ok(res) | ||
282 | } | 271 | } |
283 | pub fn approximately_resolve_symbol( | 272 | pub fn approximately_resolve_symbol( |
284 | &self, | 273 | &self, |
@@ -364,6 +353,16 @@ impl AnalysisImpl { | |||
364 | ret | 353 | ret |
365 | } | 354 | } |
366 | 355 | ||
356 | pub fn doc_comment_for( | ||
357 | &self, | ||
358 | file_id: FileId, | ||
359 | symbol: FileSymbol, | ||
360 | ) -> Cancelable<Option<String>> { | ||
361 | let file = self.db.file_syntax(file_id); | ||
362 | |||
363 | Ok(symbol.docs(&file)) | ||
364 | } | ||
365 | |||
367 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 366 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
368 | let module_tree = self.module_tree(file_id)?; | 367 | let module_tree = self.module_tree(file_id)?; |
369 | let syntax = self.db.file_syntax(file_id); | 368 | let syntax = self.db.file_syntax(file_id); |
@@ -376,7 +375,7 @@ impl AnalysisImpl { | |||
376 | fix: None, | 375 | fix: None, |
377 | }) | 376 | }) |
378 | .collect::<Vec<_>>(); | 377 | .collect::<Vec<_>>(); |
379 | if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { | 378 | if let Some(m) = module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { |
380 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { | 379 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { |
381 | let diag = match problem { | 380 | let diag = match problem { |
382 | Problem::UnresolvedModule { candidate } => { | 381 | Problem::UnresolvedModule { candidate } => { |
@@ -538,7 +537,7 @@ impl AnalysisImpl { | |||
538 | Some(name) => name.text(), | 537 | Some(name) => name.text(), |
539 | None => return Vec::new(), | 538 | None => return Vec::new(), |
540 | }; | 539 | }; |
541 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { | 540 | let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { |
542 | Some(id) => id, | 541 | Some(id) => id, |
543 | None => return Vec::new(), | 542 | None => return Vec::new(), |
544 | }; | 543 | }; |
@@ -552,7 +551,7 @@ impl AnalysisImpl { | |||
552 | 551 | ||
553 | impl SourceChange { | 552 | impl SourceChange { |
554 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { | 553 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { |
555 | let file_edit = SourceFileEdit { | 554 | let file_edit = SourceFileNodeEdit { |
556 | file_id, | 555 | file_id, |
557 | edits: edit.edit.into_atoms(), | 556 | edits: edit.edit.into_atoms(), |
558 | }; | 557 | }; |