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.rs29
1 files changed, 9 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index c2ef61ae2..0e7b47e3c 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -72,7 +72,7 @@ pub use crate::{
72 folding_ranges::{Fold, FoldKind}, 72 folding_ranges::{Fold, FoldKind},
73}; 73};
74pub use ra_ide_api_light::{ 74pub use ra_ide_api_light::{
75 HighlightedRange, Severity, StructureNode, LocalEdit, 75 HighlightedRange, Severity, StructureNode,
76}; 76};
77pub use ra_db::{ 77pub use ra_db::{
78 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, 78 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId,
@@ -295,9 +295,7 @@ impl Analysis {
295 /// Returns an edit which should be applied when opening a new line, fixing 295 /// Returns an edit which should be applied when opening a new line, fixing
296 /// up minor stuff like continuing the comment. 296 /// up minor stuff like continuing the comment.
297 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> { 297 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
298 let file = self.db.parse(position.file_id); 298 typing::on_enter(&self.db, position)
299 let edit = typing::on_enter(&file, position.offset)?;
300 Some(SourceChange::from_local_edit(position.file_id, edit))
301 } 299 }
302 300
303 /// Returns an edit which should be applied after `=` was typed. Primarily, 301 /// Returns an edit which should be applied after `=` was typed. Primarily,
@@ -306,14 +304,17 @@ impl Analysis {
306 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> { 304 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
307 let file = self.db.parse(position.file_id); 305 let file = self.db.parse(position.file_id);
308 let edit = typing::on_eq_typed(&file, position.offset)?; 306 let edit = typing::on_eq_typed(&file, position.offset)?;
309 Some(SourceChange::from_local_edit(position.file_id, edit)) 307 Some(SourceChange {
308 label: "add semicolon".to_string(),
309 source_file_edits: vec![SourceFileEdit { edit, file_id: position.file_id }],
310 file_system_edits: vec![],
311 cursor_position: None,
312 })
310 } 313 }
311 314
312 /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. 315 /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
313 pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> { 316 pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> {
314 let file = self.db.parse(position.file_id); 317 typing::on_dot_typed(&self.db, position)
315 let edit = typing::on_dot_typed(&file, position.offset)?;
316 Some(SourceChange::from_local_edit(position.file_id, edit))
317 } 318 }
318 319
319 /// Returns a tree representation of symbols in the file. Useful to draw a 320 /// Returns a tree representation of symbols in the file. Useful to draw a
@@ -435,18 +436,6 @@ impl Analysis {
435 } 436 }
436} 437}
437 438
438impl SourceChange {
439 pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange {
440 let file_edit = SourceFileEdit { file_id, edit: edit.edit };
441 SourceChange {
442 label: edit.label,
443 source_file_edits: vec![file_edit],
444 file_system_edits: vec![],
445 cursor_position: edit.cursor_position.map(|offset| FilePosition { offset, file_id }),
446 }
447 }
448}
449
450#[test] 439#[test]
451fn analysis_is_send() { 440fn analysis_is_send() {
452 fn is_send<T: Send>() {} 441 fn is_send<T: Send>() {}