aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r--crates/ra_ide_api/src/lib.rs39
1 files changed, 15 insertions, 24 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index a838c30da..99f18b6b8 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -37,6 +37,8 @@ mod line_index;
37mod folding_ranges; 37mod folding_ranges;
38mod line_index_utils; 38mod line_index_utils;
39mod join_lines; 39mod join_lines;
40mod typing;
41mod matching_brace;
40 42
41#[cfg(test)] 43#[cfg(test)]
42mod marks; 44mod marks;
@@ -69,10 +71,10 @@ pub use crate::{
69 line_index::{LineIndex, LineCol}, 71 line_index::{LineIndex, LineCol},
70 line_index_utils::translate_offset_with_edit, 72 line_index_utils::translate_offset_with_edit,
71 folding_ranges::{Fold, FoldKind}, 73 folding_ranges::{Fold, FoldKind},
74 syntax_highlighting::HighlightedRange,
75 diagnostics::Severity,
72}; 76};
73pub use ra_ide_api_light::{ 77pub use ra_ide_api_light::StructureNode;
74 HighlightedRange, Severity, StructureNode, LocalEdit,
75};
76pub use ra_db::{ 78pub use ra_db::{
77 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, 79 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId,
78 Edition 80 Edition
@@ -266,7 +268,7 @@ impl Analysis {
266 /// supported). 268 /// supported).
267 pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> { 269 pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> {
268 let file = self.db.parse(position.file_id); 270 let file = self.db.parse(position.file_id);
269 ra_ide_api_light::matching_brace(&file, position.offset) 271 matching_brace::matching_brace(&file, position.offset)
270 } 272 }
271 273
272 /// Returns a syntax tree represented as `String`, for debug purposes. 274 /// Returns a syntax tree represented as `String`, for debug purposes.
@@ -294,9 +296,7 @@ impl Analysis {
294 /// Returns an edit which should be applied when opening a new line, fixing 296 /// Returns an edit which should be applied when opening a new line, fixing
295 /// up minor stuff like continuing the comment. 297 /// up minor stuff like continuing the comment.
296 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { 298 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
297 let file = self.db.parse(position.file_id); 299 typing::on_enter(&self.db, position)
298 let edit = ra_ide_api_light::on_enter(&file, position.offset)?;
299 Some(SourceChange::from_local_edit(position.file_id, edit))
300 } 300 }
301 301
302 /// Returns an edit which should be applied after `=` was typed. Primarily, 302 /// Returns an edit which should be applied after `=` was typed. Primarily,
@@ -304,15 +304,18 @@ impl Analysis {
304 // FIXME: use a snippet completion instead of this hack here. 304 // FIXME: use a snippet completion instead of this hack here.
305 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { 305 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
306 let file = self.db.parse(position.file_id); 306 let file = self.db.parse(position.file_id);
307 let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?; 307 let edit = typing::on_eq_typed(&file, position.offset)?;
308 Some(SourceChange::from_local_edit(position.file_id, edit)) 308 Some(SourceChange {
309 label: "add semicolon".to_string(),
310 source_file_edits: vec![SourceFileEdit { edit, file_id: position.file_id }],
311 file_system_edits: vec![],
312 cursor_position: None,
313 })
309 } 314 }
310 315
311 /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. 316 /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
312 pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> { 317 pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> {
313 let file = self.db.parse(position.file_id); 318 typing::on_dot_typed(&self.db, position)
314 let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?;
315 Some(SourceChange::from_local_edit(position.file_id, edit))
316 } 319 }
317 320
318 /// Returns a tree representation of symbols in the file. Useful to draw a 321 /// Returns a tree representation of symbols in the file. Useful to draw a
@@ -434,18 +437,6 @@ impl Analysis {
434 } 437 }
435} 438}
436 439
437impl SourceChange {
438 pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange {
439 let file_edit = SourceFileEdit { file_id, edit: edit.edit };
440 SourceChange {
441 label: edit.label,
442 source_file_edits: vec![file_edit],
443 file_system_edits: vec![],
444 cursor_position: edit.cursor_position.map(|offset| FilePosition { offset, file_id }),
445 }
446 }
447}
448
449#[test] 440#[test]
450fn analysis_is_send() { 441fn analysis_is_send() {
451 fn is_send<T: Send>() {} 442 fn is_send<T: Send>() {}