aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/lib.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 762731268..fbe1421a4 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -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 }
429
402 pub fn goto_definition( 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_definition::goto_definition(&*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(