From 762eacef74e76d41c7aa5bd714926ce2ad6c50bf Mon Sep 17 00:00:00 2001 From: DropDemBits Date: Sun, 26 Mar 2023 18:08:10 -0400 Subject: [PATCH] factor out adding a snippet --- crates/ide-db/src/source_change.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/ide-db/src/source_change.rs b/crates/ide-db/src/source_change.rs index 1cc7be68138..04e62a8e916 100644 --- a/crates/ide-db/src/source_change.rs +++ b/crates/ide-db/src/source_change.rs @@ -237,27 +237,24 @@ pub fn trigger_signature_help(&mut self) { /// Adds a tabstop snippet to place the cursor before `node` pub fn add_tabstop_before(&mut self, _cap: SnippetCap, node: impl AstNode) { assert!(node.syntax().parent().is_some()); - - let snippet_builder = self.snippet_builder.get_or_insert(SnippetBuilder { places: vec![] }); - snippet_builder.places.push(PlaceSnippet::Before(node.syntax().clone())); - self.source_change.is_snippet = true; + self.add_snippet(PlaceSnippet::Before(node.syntax().clone())); } /// Adds a tabstop snippet to place the cursor after `node` pub fn add_tabstop_after(&mut self, _cap: SnippetCap, node: impl AstNode) { assert!(node.syntax().parent().is_some()); - - let snippet_builder = self.snippet_builder.get_or_insert(SnippetBuilder { places: vec![] }); - snippet_builder.places.push(PlaceSnippet::After(node.syntax().clone())); - self.source_change.is_snippet = true; + self.add_snippet(PlaceSnippet::After(node.syntax().clone())); } /// Adds a snippet to move the cursor selected over `node` pub fn add_placeholder_snippet(&mut self, _cap: SnippetCap, node: impl AstNode) { assert!(node.syntax().parent().is_some()); + self.add_snippet(PlaceSnippet::Over(node.syntax().clone())) + } + fn add_snippet(&mut self, snippet: PlaceSnippet) { let snippet_builder = self.snippet_builder.get_or_insert(SnippetBuilder { places: vec![] }); - snippet_builder.places.push(PlaceSnippet::Over(node.syntax().clone())); + snippet_builder.places.push(snippet); self.source_change.is_snippet = true; }