From 0c15deac760a654f03de3ae433e5260b5bdfb8c2 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sat, 23 Mar 2019 12:07:21 +0100 Subject: Move typing to ra_ide_api --- crates/ra_ide_api/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index a838c30da..c2ef61ae2 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -37,6 +37,7 @@ mod line_index; mod folding_ranges; mod line_index_utils; mod join_lines; +mod typing; #[cfg(test)] mod marks; @@ -295,7 +296,7 @@ impl Analysis { /// up minor stuff like continuing the comment. pub fn on_enter(&self, position: FilePosition) -> Option { let file = self.db.parse(position.file_id); - let edit = ra_ide_api_light::on_enter(&file, position.offset)?; + let edit = typing::on_enter(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } @@ -304,14 +305,14 @@ impl Analysis { // FIXME: use a snippet completion instead of this hack here. pub fn on_eq_typed(&self, position: FilePosition) -> Option { let file = self.db.parse(position.file_id); - let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?; + let edit = typing::on_eq_typed(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. pub fn on_dot_typed(&self, position: FilePosition) -> Option { let file = self.db.parse(position.file_id); - let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?; + let edit = typing::on_dot_typed(&file, position.offset)?; Some(SourceChange::from_local_edit(position.file_id, edit)) } -- cgit v1.2.3 From a656b891fba4b89775adbc93114a20c99afe5f36 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sat, 23 Mar 2019 16:55:47 +0100 Subject: Remove LocalEdit usage --- crates/ra_ide_api/src/lib.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') 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::{ folding_ranges::{Fold, FoldKind}, }; pub use ra_ide_api_light::{ - HighlightedRange, Severity, StructureNode, LocalEdit, + HighlightedRange, Severity, StructureNode, }; pub use ra_db::{ Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, @@ -295,9 +295,7 @@ impl Analysis { /// Returns an edit which should be applied when opening a new line, fixing /// up minor stuff like continuing the comment. pub fn on_enter(&self, position: FilePosition) -> Option { - let file = self.db.parse(position.file_id); - let edit = typing::on_enter(&file, position.offset)?; - Some(SourceChange::from_local_edit(position.file_id, edit)) + typing::on_enter(&self.db, position) } /// Returns an edit which should be applied after `=` was typed. Primarily, @@ -306,14 +304,17 @@ impl Analysis { pub fn on_eq_typed(&self, position: FilePosition) -> Option { let file = self.db.parse(position.file_id); let edit = typing::on_eq_typed(&file, position.offset)?; - Some(SourceChange::from_local_edit(position.file_id, edit)) + Some(SourceChange { + label: "add semicolon".to_string(), + source_file_edits: vec![SourceFileEdit { edit, file_id: position.file_id }], + file_system_edits: vec![], + cursor_position: None, + }) } /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. pub fn on_dot_typed(&self, position: FilePosition) -> Option { - let file = self.db.parse(position.file_id); - let edit = typing::on_dot_typed(&file, position.offset)?; - Some(SourceChange::from_local_edit(position.file_id, edit)) + typing::on_dot_typed(&self.db, position) } /// Returns a tree representation of symbols in the file. Useful to draw a @@ -435,18 +436,6 @@ impl Analysis { } } -impl SourceChange { - pub(crate) fn from_local_edit(file_id: FileId, edit: LocalEdit) -> SourceChange { - let file_edit = SourceFileEdit { file_id, edit: edit.edit }; - SourceChange { - label: edit.label, - source_file_edits: vec![file_edit], - file_system_edits: vec![], - cursor_position: edit.cursor_position.map(|offset| FilePosition { offset, file_id }), - } - } -} - #[test] fn analysis_is_send() { fn is_send() {} -- cgit v1.2.3 From a3711e08dc4e393957dff136218c47d8b77da14f Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sat, 23 Mar 2019 17:34:49 +0100 Subject: Move highlighting and matching_brace --- crates/ra_ide_api/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 0e7b47e3c..99f18b6b8 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -38,6 +38,7 @@ mod folding_ranges; mod line_index_utils; mod join_lines; mod typing; +mod matching_brace; #[cfg(test)] mod marks; @@ -70,10 +71,10 @@ pub use crate::{ line_index::{LineIndex, LineCol}, line_index_utils::translate_offset_with_edit, folding_ranges::{Fold, FoldKind}, + syntax_highlighting::HighlightedRange, + diagnostics::Severity, }; -pub use ra_ide_api_light::{ - HighlightedRange, Severity, StructureNode, -}; +pub use ra_ide_api_light::StructureNode; pub use ra_db::{ Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition @@ -267,7 +268,7 @@ impl Analysis { /// supported). pub fn matching_brace(&self, position: FilePosition) -> Option { let file = self.db.parse(position.file_id); - ra_ide_api_light::matching_brace(&file, position.offset) + matching_brace::matching_brace(&file, position.offset) } /// Returns a syntax tree represented as `String`, for debug purposes. -- cgit v1.2.3