@@ -7,10 +7,11 @@ import {
77 type TextEditor ,
88} from "@cursorless/common" ;
99import {
10- getHeaderSnippet ,
1110 parseSnippetFile ,
1211 serializeSnippetFile ,
13- type SnippetDocument ,
12+ type Snippet ,
13+ type SnippetFile ,
14+ type SnippetHeader ,
1415 type SnippetVariable ,
1516} from "talon-snippets" ;
1617import type { Snippets } from "../../core/Snippets" ;
@@ -129,36 +130,35 @@ export default class GenerateSnippetCommunity {
129130 const snippetLines = constructSnippetBody ( snippetBodyText , linePrefix ) ;
130131
131132 let editableEditor : EditableTextEditor ;
132- let snippetDocuments : SnippetDocument [ ] ;
133+ let snippetFile : SnippetFile = { snippets : [ ] } ;
133134
134135 if ( ide ( ) . runMode === "test" ) {
135136 // If we're testing, we just overwrite the current document
136137 editableEditor = ide ( ) . getEditableTextEditor ( editor ) ;
137- snippetDocuments = [ ] ;
138138 } else {
139139 // Otherwise, we create and open a new document for the snippet
140140 editableEditor = ide ( ) . getEditableTextEditor (
141141 await this . snippets . openNewSnippetFile ( snippetName , directory ) ,
142142 ) ;
143- snippetDocuments = parseSnippetFile ( editableEditor . document . getText ( ) ) ;
143+ snippetFile = parseSnippetFile ( editableEditor . document . getText ( ) ) ;
144144 }
145145
146146 await editableEditor . setSelections ( [
147147 editableEditor . document . range . toSelection ( false ) ,
148148 ] ) ;
149149
150- const headerSnippet = getHeaderSnippet ( snippetDocuments ) ;
151-
152150 /** The next placeholder index to use for the meta snippet */
153151 let currentPlaceholderIndex = 1 ;
154152
153+ const { header } = snippetFile ;
154+
155155 const phrases =
156- headerSnippet ?. phrases != null
156+ snippetFile . header ?. phrases != null
157157 ? undefined
158158 : [ `${ PLACEHOLDER } ${ currentPlaceholderIndex ++ } ` ] ;
159159
160160 const createVariable = ( variable : Variable ) : SnippetVariable => {
161- const hasPhrase = headerSnippet ?. variables ?. some (
161+ const hasPhrase = header ?. variables ?. some (
162162 ( v ) => v . name === variable . name && v . wrapperPhrases != null ,
163163 ) ;
164164 return {
@@ -169,22 +169,22 @@ export default class GenerateSnippetCommunity {
169169 } ;
170170 } ;
171171
172- const snippet : SnippetDocument = {
173- name : headerSnippet ?. name === snippetName ? undefined : snippetName ,
172+ const snippet : Snippet = {
173+ name : header ?. name === snippetName ? undefined : snippetName ,
174174 phrases,
175- languages : getSnippetLanguages ( editor , headerSnippet ) ,
175+ languages : getSnippetLanguages ( editor , header ) ,
176176 body : snippetLines ,
177177 variables : variables . map ( createVariable ) ,
178178 } ;
179179
180- snippetDocuments . push ( snippet ) ;
180+ snippetFile . snippets . push ( snippet ) ;
181181
182182 /**
183183 * This is the text of the meta-snippet in Textmate format that we will
184184 * insert into the new document where the user will fill out their snippet
185185 * definition
186186 */
187- const metaSnippetText = serializeSnippetFile ( snippetDocuments )
187+ const metaSnippetText = serializeSnippetFile ( snippetFile )
188188 // Escape dollar signs in the snippet text so that they don't get used as
189189 // placeholders in the meta snippet
190190 . replace ( / \$ / g, "\\$" )
@@ -205,7 +205,7 @@ export default class GenerateSnippetCommunity {
205205
206206function getSnippetLanguages (
207207 editor : TextEditor ,
208- header : SnippetDocument | undefined ,
208+ header : SnippetHeader | undefined ,
209209) : string [ ] | undefined {
210210 if ( header ?. languages ?. includes ( editor . document . languageId ) ) {
211211 return undefined ;
0 commit comments