diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs (renamed from crates/ra_ide_api/src/goto_defenition.rs) | 22 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 47 |
4 files changed, 57 insertions, 16 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index ee9052d3d..770a0fdf2 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -20,7 +20,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
20 | } | 20 | } |
21 | 21 | ||
22 | let module_scope = module.scope(ctx.db)?; | 22 | let module_scope = module.scope(ctx.db)?; |
23 | let (file_id, _) = module.defenition_source(ctx.db)?; | 23 | let (file_id, _) = module.definition_source(ctx.db)?; |
24 | module_scope | 24 | module_scope |
25 | .entries() | 25 | .entries() |
26 | .filter(|(_name, res)| { | 26 | .filter(|(_name, res)| { |
diff --git a/crates/ra_ide_api/src/goto_defenition.rs b/crates/ra_ide_api/src/goto_definition.rs index fcd8d315e..0d524b6f1 100644 --- a/crates/ra_ide_api/src/goto_defenition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -6,22 +6,22 @@ use ra_syntax::{ | |||
6 | 6 | ||
7 | use crate::{FilePosition, NavigationTarget, db::RootDatabase}; | 7 | use crate::{FilePosition, NavigationTarget, db::RootDatabase}; |
8 | 8 | ||
9 | pub(crate) fn goto_defenition( | 9 | pub(crate) fn goto_definition( |
10 | db: &RootDatabase, | 10 | db: &RootDatabase, |
11 | position: FilePosition, | 11 | position: FilePosition, |
12 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 12 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { |
13 | let file = db.source_file(position.file_id); | 13 | let file = db.source_file(position.file_id); |
14 | let syntax = file.syntax(); | 14 | let syntax = file.syntax(); |
15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
16 | return Ok(Some(reference_defenition(db, position.file_id, name_ref)?)); | 16 | return Ok(Some(reference_definition(db, position.file_id, name_ref)?)); |
17 | } | 17 | } |
18 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { | 18 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { |
19 | return name_defenition(db, position.file_id, name); | 19 | return name_definition(db, position.file_id, name); |
20 | } | 20 | } |
21 | Ok(None) | 21 | Ok(None) |
22 | } | 22 | } |
23 | 23 | ||
24 | pub(crate) fn reference_defenition( | 24 | pub(crate) fn reference_definition( |
25 | db: &RootDatabase, | 25 | db: &RootDatabase, |
26 | file_id: FileId, | 26 | file_id: FileId, |
27 | name_ref: &ast::NameRef, | 27 | name_ref: &ast::NameRef, |
@@ -51,7 +51,7 @@ pub(crate) fn reference_defenition( | |||
51 | Ok(navs) | 51 | Ok(navs) |
52 | } | 52 | } |
53 | 53 | ||
54 | fn name_defenition( | 54 | fn name_definition( |
55 | db: &RootDatabase, | 55 | db: &RootDatabase, |
56 | file_id: FileId, | 56 | file_id: FileId, |
57 | name: &ast::Name, | 57 | name: &ast::Name, |
@@ -61,7 +61,7 @@ fn name_defenition( | |||
61 | if let Some(child_module) = | 61 | if let Some(child_module) = |
62 | hir::source_binder::module_from_declaration(db, file_id, module)? | 62 | hir::source_binder::module_from_declaration(db, file_id, module)? |
63 | { | 63 | { |
64 | let (file_id, _) = child_module.defenition_source(db)?; | 64 | let (file_id, _) = child_module.definition_source(db)?; |
65 | let name = match child_module.name(db)? { | 65 | let name = match child_module.name(db)? { |
66 | Some(name) => name.to_string().into(), | 66 | Some(name) => name.to_string().into(), |
67 | None => "".into(), | 67 | None => "".into(), |
@@ -86,7 +86,7 @@ mod tests { | |||
86 | use crate::mock_analysis::analysis_and_position; | 86 | use crate::mock_analysis::analysis_and_position; |
87 | 87 | ||
88 | #[test] | 88 | #[test] |
89 | fn goto_defenition_works_in_items() { | 89 | fn goto_definition_works_in_items() { |
90 | let (analysis, pos) = analysis_and_position( | 90 | let (analysis, pos) = analysis_and_position( |
91 | " | 91 | " |
92 | //- /lib.rs | 92 | //- /lib.rs |
@@ -95,7 +95,7 @@ mod tests { | |||
95 | ", | 95 | ", |
96 | ); | 96 | ); |
97 | 97 | ||
98 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | 98 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); |
99 | assert_eq_dbg( | 99 | assert_eq_dbg( |
100 | r#"[NavigationTarget { file_id: FileId(1), name: "Foo", | 100 | r#"[NavigationTarget { file_id: FileId(1), name: "Foo", |
101 | kind: STRUCT_DEF, range: [0; 11), | 101 | kind: STRUCT_DEF, range: [0; 11), |
@@ -105,7 +105,7 @@ mod tests { | |||
105 | } | 105 | } |
106 | 106 | ||
107 | #[test] | 107 | #[test] |
108 | fn goto_defenition_works_for_module_declaration() { | 108 | fn goto_definition_works_for_module_declaration() { |
109 | let (analysis, pos) = analysis_and_position( | 109 | let (analysis, pos) = analysis_and_position( |
110 | " | 110 | " |
111 | //- /lib.rs | 111 | //- /lib.rs |
@@ -115,7 +115,7 @@ mod tests { | |||
115 | ", | 115 | ", |
116 | ); | 116 | ); |
117 | 117 | ||
118 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | 118 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); |
119 | assert_eq_dbg( | 119 | assert_eq_dbg( |
120 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | 120 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, |
121 | &symbols, | 121 | &symbols, |
@@ -130,7 +130,7 @@ mod tests { | |||
130 | ", | 130 | ", |
131 | ); | 131 | ); |
132 | 132 | ||
133 | let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); | 133 | let symbols = analysis.goto_definition(pos).unwrap().unwrap(); |
134 | assert_eq_dbg( | 134 | assert_eq_dbg( |
135 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, | 135 | r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, |
136 | &symbols, | 136 | &symbols, |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 475524ee1..41309e756 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn hover( | |||
16 | 16 | ||
17 | let mut range = None; | 17 | let mut range = None; |
18 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | 18 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
19 | let navs = crate::goto_defenition::reference_defenition(db, position.file_id, name_ref)?; | 19 | let navs = crate::goto_definition::reference_definition(db, position.file_id, name_ref)?; |
20 | for nav in navs { | 20 | for nav in navs { |
21 | res.extend(doc_text_for(db, nav)?) | 21 | res.extend(doc_text_for(db, nav)?) |
22 | } | 22 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 7e9ca2034..fbe1421a4 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -20,7 +20,7 @@ macro_rules! ctry { | |||
20 | 20 | ||
21 | mod completion; | 21 | mod completion; |
22 | mod db; | 22 | mod db; |
23 | mod goto_defenition; | 23 | mod goto_definition; |
24 | mod imp; | 24 | mod imp; |
25 | pub mod mock_analysis; | 25 | pub mod mock_analysis; |
26 | mod runnables; | 26 | mod runnables; |
@@ -121,9 +121,11 @@ impl AnalysisChange { | |||
121 | pub fn new() -> AnalysisChange { | 121 | pub fn new() -> AnalysisChange { |
122 | AnalysisChange::default() | 122 | AnalysisChange::default() |
123 | } | 123 | } |
124 | |||
124 | pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { | 125 | pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { |
125 | self.new_roots.push((root_id, is_local)); | 126 | self.new_roots.push((root_id, is_local)); |
126 | } | 127 | } |
128 | |||
127 | pub fn add_file( | 129 | pub fn add_file( |
128 | &mut self, | 130 | &mut self, |
129 | root_id: SourceRootId, | 131 | root_id: SourceRootId, |
@@ -142,9 +144,11 @@ impl AnalysisChange { | |||
142 | .added | 144 | .added |
143 | .push(file); | 145 | .push(file); |
144 | } | 146 | } |
147 | |||
145 | pub fn change_file(&mut self, file_id: FileId, new_text: Arc<String>) { | 148 | pub fn change_file(&mut self, file_id: FileId, new_text: Arc<String>) { |
146 | self.files_changed.push((file_id, new_text)) | 149 | self.files_changed.push((file_id, new_text)) |
147 | } | 150 | } |
151 | |||
148 | pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { | 152 | pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { |
149 | let file = RemoveFile { file_id, path }; | 153 | let file = RemoveFile { file_id, path }; |
150 | self.roots_changed | 154 | self.roots_changed |
@@ -153,9 +157,11 @@ impl AnalysisChange { | |||
153 | .removed | 157 | .removed |
154 | .push(file); | 158 | .push(file); |
155 | } | 159 | } |
160 | |||
156 | pub fn add_library(&mut self, data: LibraryData) { | 161 | pub fn add_library(&mut self, data: LibraryData) { |
157 | self.libraries_added.push(data) | 162 | self.libraries_added.push(data) |
158 | } | 163 | } |
164 | |||
159 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | 165 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { |
160 | self.crate_graph = Some(graph); | 166 | self.crate_graph = Some(graph); |
161 | } | 167 | } |
@@ -218,15 +224,19 @@ impl Query { | |||
218 | limit: usize::max_value(), | 224 | limit: usize::max_value(), |
219 | } | 225 | } |
220 | } | 226 | } |
227 | |||
221 | pub fn only_types(&mut self) { | 228 | pub fn only_types(&mut self) { |
222 | self.only_types = true; | 229 | self.only_types = true; |
223 | } | 230 | } |
231 | |||
224 | pub fn libs(&mut self) { | 232 | pub fn libs(&mut self) { |
225 | self.libs = true; | 233 | self.libs = true; |
226 | } | 234 | } |
235 | |||
227 | pub fn exact(&mut self) { | 236 | pub fn exact(&mut self) { |
228 | self.exact = true; | 237 | self.exact = true; |
229 | } | 238 | } |
239 | |||
230 | pub fn limit(&mut self, limit: usize) { | 240 | pub fn limit(&mut self, limit: usize) { |
231 | self.limit = limit | 241 | self.limit = limit |
232 | } | 242 | } |
@@ -257,15 +267,19 @@ impl NavigationTarget { | |||
257 | ptr: Some(symbol.ptr.clone()), | 267 | ptr: Some(symbol.ptr.clone()), |
258 | } | 268 | } |
259 | } | 269 | } |
270 | |||
260 | pub fn name(&self) -> &SmolStr { | 271 | pub fn name(&self) -> &SmolStr { |
261 | &self.name | 272 | &self.name |
262 | } | 273 | } |
274 | |||
263 | pub fn kind(&self) -> SyntaxKind { | 275 | pub fn kind(&self) -> SyntaxKind { |
264 | self.kind | 276 | self.kind |
265 | } | 277 | } |
278 | |||
266 | pub fn file_id(&self) -> FileId { | 279 | pub fn file_id(&self) -> FileId { |
267 | self.file_id | 280 | self.file_id |
268 | } | 281 | } |
282 | |||
269 | pub fn range(&self) -> TextRange { | 283 | pub fn range(&self) -> TextRange { |
270 | self.range | 284 | self.range |
271 | } | 285 | } |
@@ -305,6 +319,7 @@ impl AnalysisHost { | |||
305 | db: self.db.snapshot(), | 319 | db: self.db.snapshot(), |
306 | } | 320 | } |
307 | } | 321 | } |
322 | |||
308 | /// Applies changes to the current state of the world. If there are | 323 | /// Applies changes to the current state of the world. If there are |
309 | /// outstanding snapshots, they will be canceled. | 324 | /// outstanding snapshots, they will be canceled. |
310 | pub fn apply_change(&mut self, change: AnalysisChange) { | 325 | pub fn apply_change(&mut self, change: AnalysisChange) { |
@@ -326,30 +341,36 @@ impl Analysis { | |||
326 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { | 341 | pub fn file_text(&self, file_id: FileId) -> Arc<String> { |
327 | self.db.file_text(file_id) | 342 | self.db.file_text(file_id) |
328 | } | 343 | } |
344 | |||
329 | /// Gets the syntax tree of the file. | 345 | /// Gets the syntax tree of the file. |
330 | pub fn file_syntax(&self, file_id: FileId) -> TreePtr<SourceFile> { | 346 | pub fn file_syntax(&self, file_id: FileId) -> TreePtr<SourceFile> { |
331 | self.db.source_file(file_id).clone() | 347 | self.db.source_file(file_id).clone() |
332 | } | 348 | } |
349 | |||
333 | /// Gets the file's `LineIndex`: data structure to convert between absolute | 350 | /// Gets the file's `LineIndex`: data structure to convert between absolute |
334 | /// offsets and line/column representation. | 351 | /// offsets and line/column representation. |
335 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 352 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
336 | self.db.line_index(file_id) | 353 | self.db.line_index(file_id) |
337 | } | 354 | } |
355 | |||
338 | /// Selects the next syntactic nodes encopasing the range. | 356 | /// Selects the next syntactic nodes encopasing the range. |
339 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { | 357 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { |
340 | extend_selection::extend_selection(&self.db, frange) | 358 | extend_selection::extend_selection(&self.db, frange) |
341 | } | 359 | } |
360 | |||
342 | /// Returns position of the mathcing brace (all types of braces are | 361 | /// Returns position of the mathcing brace (all types of braces are |
343 | /// supported). | 362 | /// supported). |
344 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { | 363 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
345 | ra_ide_api_light::matching_brace(file, offset) | 364 | ra_ide_api_light::matching_brace(file, offset) |
346 | } | 365 | } |
366 | |||
347 | /// Returns a syntax tree represented as `String`, for debug purposes. | 367 | /// Returns a syntax tree represented as `String`, for debug purposes. |
348 | // FIXME: use a better name here. | 368 | // FIXME: use a better name here. |
349 | pub fn syntax_tree(&self, file_id: FileId) -> String { | 369 | pub fn syntax_tree(&self, file_id: FileId) -> String { |
350 | let file = self.db.source_file(file_id); | 370 | let file = self.db.source_file(file_id); |
351 | ra_ide_api_light::syntax_tree(&file) | 371 | ra_ide_api_light::syntax_tree(&file) |
352 | } | 372 | } |
373 | |||
353 | /// Returns an edit to remove all newlines in the range, cleaning up minor | 374 | /// Returns an edit to remove all newlines in the range, cleaning up minor |
354 | /// stuff like trailing commas. | 375 | /// stuff like trailing commas. |
355 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { | 376 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { |
@@ -359,6 +380,7 @@ impl Analysis { | |||
359 | ra_ide_api_light::join_lines(&file, frange.range), | 380 | ra_ide_api_light::join_lines(&file, frange.range), |
360 | ) | 381 | ) |
361 | } | 382 | } |
383 | |||
362 | /// Returns an edit which should be applied when opening a new line, fixing | 384 | /// Returns an edit which should be applied when opening a new line, fixing |
363 | /// up minor stuff like continuing the comment. | 385 | /// up minor stuff like continuing the comment. |
364 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { | 386 | pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { |
@@ -366,6 +388,7 @@ impl Analysis { | |||
366 | let edit = ra_ide_api_light::on_enter(&file, position.offset)?; | 388 | let edit = ra_ide_api_light::on_enter(&file, position.offset)?; |
367 | Some(SourceChange::from_local_edit(position.file_id, edit)) | 389 | Some(SourceChange::from_local_edit(position.file_id, edit)) |
368 | } | 390 | } |
391 | |||
369 | /// Returns an edit which should be applied after `=` was typed. Primarily, | 392 | /// Returns an edit which should be applied after `=` was typed. Primarily, |
370 | /// this works when adding `let =`. | 393 | /// this works when adding `let =`. |
371 | // FIXME: use a snippet completion instead of this hack here. | 394 | // FIXME: use a snippet completion instead of this hack here. |
@@ -374,23 +397,27 @@ impl Analysis { | |||
374 | let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?; | 397 | let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?; |
375 | Some(SourceChange::from_local_edit(position.file_id, edit)) | 398 | Some(SourceChange::from_local_edit(position.file_id, edit)) |
376 | } | 399 | } |
400 | |||
377 | /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. | 401 | /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. |
378 | pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> { | 402 | pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> { |
379 | let file = self.db.source_file(position.file_id); | 403 | let file = self.db.source_file(position.file_id); |
380 | let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?; | 404 | let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?; |
381 | Some(SourceChange::from_local_edit(position.file_id, edit)) | 405 | Some(SourceChange::from_local_edit(position.file_id, edit)) |
382 | } | 406 | } |
407 | |||
383 | /// Returns a tree representation of symbols in the file. Useful to draw a | 408 | /// Returns a tree representation of symbols in the file. Useful to draw a |
384 | /// file outline. | 409 | /// file outline. |
385 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | 410 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { |
386 | let file = self.db.source_file(file_id); | 411 | let file = self.db.source_file(file_id); |
387 | ra_ide_api_light::file_structure(&file) | 412 | ra_ide_api_light::file_structure(&file) |
388 | } | 413 | } |
414 | |||
389 | /// Returns the set of folding ranges. | 415 | /// Returns the set of folding ranges. |
390 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { | 416 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { |
391 | let file = self.db.source_file(file_id); | 417 | let file = self.db.source_file(file_id); |
392 | ra_ide_api_light::folding_ranges(&file) | 418 | ra_ide_api_light::folding_ranges(&file) |
393 | } | 419 | } |
420 | |||
394 | /// Fuzzy searches for a symbol. | 421 | /// Fuzzy searches for a symbol. |
395 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { | 422 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { |
396 | let res = symbol_index::world_symbols(&*self.db, query)? | 423 | let res = symbol_index::world_symbols(&*self.db, query)? |
@@ -399,62 +426,76 @@ impl Analysis { | |||
399 | .collect(); | 426 | .collect(); |
400 | Ok(res) | 427 | Ok(res) |
401 | } | 428 | } |
402 | pub fn goto_defenition( | 429 | |
430 | pub fn goto_definition( | ||
403 | &self, | 431 | &self, |
404 | position: FilePosition, | 432 | position: FilePosition, |
405 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 433 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { |
406 | goto_defenition::goto_defenition(&*self.db, position) | 434 | goto_definition::goto_definition(&*self.db, position) |
407 | } | 435 | } |
436 | |||
408 | /// Finds all usages of the reference at point. | 437 | /// Finds all usages of the reference at point. |
409 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 438 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
410 | self.db.find_all_refs(position) | 439 | self.db.find_all_refs(position) |
411 | } | 440 | } |
441 | |||
412 | /// Returns a short text descrbing element at position. | 442 | /// Returns a short text descrbing element at position. |
413 | pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { | 443 | pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { |
414 | hover::hover(&*self.db, position) | 444 | hover::hover(&*self.db, position) |
415 | } | 445 | } |
446 | |||
416 | /// Computes parameter information for the given call expression. | 447 | /// Computes parameter information for the given call expression. |
417 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 448 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
418 | call_info::call_info(&*self.db, position) | 449 | call_info::call_info(&*self.db, position) |
419 | } | 450 | } |
451 | |||
420 | /// Returns a `mod name;` declaration which created the current module. | 452 | /// Returns a `mod name;` declaration which created the current module. |
421 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { | 453 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
422 | self.db.parent_module(position) | 454 | self.db.parent_module(position) |
423 | } | 455 | } |
456 | |||
424 | /// Returns crates this file belongs too. | 457 | /// Returns crates this file belongs too. |
425 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 458 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
426 | self.db.crate_for(file_id) | 459 | self.db.crate_for(file_id) |
427 | } | 460 | } |
461 | |||
428 | /// Returns the root file of the given crate. | 462 | /// Returns the root file of the given crate. |
429 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 463 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
430 | Ok(self.db.crate_graph().crate_root(crate_id)) | 464 | Ok(self.db.crate_graph().crate_root(crate_id)) |
431 | } | 465 | } |
466 | |||
432 | /// Returns the set of possible targets to run for the current file. | 467 | /// Returns the set of possible targets to run for the current file. |
433 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 468 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
434 | runnables::runnables(&*self.db, file_id) | 469 | runnables::runnables(&*self.db, file_id) |
435 | } | 470 | } |
471 | |||
436 | /// Computes syntax highlighting for the given file. | 472 | /// Computes syntax highlighting for the given file. |
437 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 473 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
438 | syntax_highlighting::highlight(&*self.db, file_id) | 474 | syntax_highlighting::highlight(&*self.db, file_id) |
439 | } | 475 | } |
476 | |||
440 | /// Computes completions at the given position. | 477 | /// Computes completions at the given position. |
441 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 478 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
442 | let completions = completion::completions(&self.db, position)?; | 479 | let completions = completion::completions(&self.db, position)?; |
443 | Ok(completions.map(|it| it.into())) | 480 | Ok(completions.map(|it| it.into())) |
444 | } | 481 | } |
482 | |||
445 | /// Computes assists (aks code actons aka intentions) for the given | 483 | /// Computes assists (aks code actons aka intentions) for the given |
446 | /// position. | 484 | /// position. |
447 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { | 485 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { |
448 | Ok(self.db.assists(frange)) | 486 | Ok(self.db.assists(frange)) |
449 | } | 487 | } |
488 | |||
450 | /// Computes the set of diagnostics for the given file. | 489 | /// Computes the set of diagnostics for the given file. |
451 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 490 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
452 | self.db.diagnostics(file_id) | 491 | self.db.diagnostics(file_id) |
453 | } | 492 | } |
493 | |||
454 | /// Computes the type of the expression at the given position. | 494 | /// Computes the type of the expression at the given position. |
455 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | 495 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
456 | hover::type_of(&*self.db, frange) | 496 | hover::type_of(&*self.db, frange) |
457 | } | 497 | } |
498 | |||
458 | /// Returns the edit required to rename reference at the position to the new | 499 | /// Returns the edit required to rename reference at the position to the new |
459 | /// name. | 500 | /// name. |
460 | pub fn rename( | 501 | pub fn rename( |