diff options
author | Aleksey Kladov <[email protected]> | 2019-10-25 09:19:26 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-25 09:30:46 +0100 |
commit | 8d2fd59cfb00211573419b0a59cf91d92d636f5a (patch) | |
tree | feafe88a932c70aa9e25a6b87323094e2b40b750 /crates/ra_ide_api/src/lib.rs | |
parent | 518f99e16b993e3414a81181c8bad7a89e590ece (diff) |
make typing infra slightly more extensible
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 0832229fd..b2a1d185b 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -407,24 +407,16 @@ impl Analysis { | |||
407 | self.with_db(|db| typing::on_enter(&db, position)) | 407 | self.with_db(|db| typing::on_enter(&db, position)) |
408 | } | 408 | } |
409 | 409 | ||
410 | /// Returns an edit which should be applied after `=` was typed. Primarily, | 410 | /// Returns an edit which should be applied after a character was typed. |
411 | /// this works when adding `let =`. | 411 | /// |
412 | // FIXME: use a snippet completion instead of this hack here. | 412 | /// This is useful for some on-the-fly fixups, like adding `;` to `let =` |
413 | pub fn on_eq_typed(&self, position: FilePosition) -> Cancelable<Option<SourceChange>> { | 413 | /// automatically. |
414 | self.with_db(|db| { | 414 | pub fn on_char_typed( |
415 | let parse = db.parse(position.file_id); | 415 | &self, |
416 | let file = parse.tree(); | 416 | position: FilePosition, |
417 | let edit = typing::on_eq_typed(&file, position.offset)?; | 417 | char_typed: char, |
418 | Some(SourceChange::source_file_edit( | 418 | ) -> Cancelable<Option<SourceChange>> { |
419 | "add semicolon", | 419 | self.with_db(|db| typing::on_char_typed(&db, position, char_typed)) |
420 | SourceFileEdit { edit, file_id: position.file_id }, | ||
421 | )) | ||
422 | }) | ||
423 | } | ||
424 | |||
425 | /// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. | ||
426 | pub fn on_dot_typed(&self, position: FilePosition) -> Cancelable<Option<SourceChange>> { | ||
427 | self.with_db(|db| typing::on_dot_typed(&db, position)) | ||
428 | } | 420 | } |
429 | 421 | ||
430 | /// Returns a tree representation of symbols in the file. Useful to draw a | 422 | /// Returns a tree representation of symbols in the file. Useful to draw a |