@@ -7,7 +7,7 @@ import { Snippet, readSnippetFile, writeSnippetFile } from "./snippet";
7
7
* If the `prefixSymbol` configuration setting is set, replaces all non-alphanumeric characters in the prefix with it.
8
8
* @returns void
9
9
*/
10
- function updatePrefixSymbol ( ) {
10
+ async function updatePrefixSymbol ( ) {
11
11
const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] ;
12
12
if ( ! workspaceFolder ) {
13
13
vscode . window . showErrorMessage ( "No workspace folder found." ) ;
@@ -19,31 +19,30 @@ function updatePrefixSymbol() {
19
19
"workspace.code-snippets"
20
20
) ;
21
21
22
- readSnippetFile ( snippetFilePath ) . then ( ( snippetFileContent ) => {
23
- const specialCharRegex = / [ ^ a - z A - Z 0 - 9 ] / g;
24
- const hasSpecialChar = Object . keys ( snippetFileContent ) . some ( ( key ) =>
25
- specialCharRegex . test ( snippetFileContent [ key ] . prefix )
26
- ) ;
22
+ const snippetFileContent = await readSnippetFile ( snippetFilePath ) ;
23
+ const specialCharRegex = / [ ^ a - z A - Z 0 - 9 ] / g;
24
+ const hasSpecialChar = Object . keys ( snippetFileContent ) . some ( ( key ) =>
25
+ specialCharRegex . test ( snippetFileContent [ key ] . prefix )
26
+ ) ;
27
27
28
- const newSnippetFileContent : Snippet = { } ;
29
- Object . keys ( snippetFileContent ) . forEach ( ( key ) => {
30
- const snippet = snippetFileContent [ key ] ;
31
- let newPrefix = snippet . prefix ;
32
- if ( hasSpecialChar ) {
33
- const prefixSymbol = vscode . workspace
34
- . getConfiguration ( )
35
- . get ( "prefixSymbol" ) as string ;
36
- newPrefix = newPrefix . replace ( specialCharRegex , prefixSymbol ) ;
37
- }
38
- const newSnippet = {
39
- ...snippet ,
40
- prefix : newPrefix ,
41
- } ;
42
- newSnippetFileContent [ key ] = newSnippet ;
43
- } ) ;
28
+ const newSnippetFileContent : Snippet = { } ;
29
+ for ( const key of Object . keys ( snippetFileContent ) ) {
30
+ const snippet = snippetFileContent [ key ] ;
31
+ let newPrefix = snippet . prefix ;
32
+ if ( hasSpecialChar ) {
33
+ const prefixSymbol = vscode . workspace
34
+ . getConfiguration ( )
35
+ . get ( "prefixSymbol" ) as string ;
36
+ newPrefix = newPrefix . replace ( specialCharRegex , prefixSymbol ) ;
37
+ }
38
+ const newSnippet = {
39
+ ...snippet ,
40
+ prefix : newPrefix ,
41
+ } ;
42
+ newSnippetFileContent [ key ] = newSnippet ;
43
+ }
44
44
45
- writeSnippetFile ( snippetFilePath , newSnippetFileContent ) ;
46
- } ) ;
45
+ await writeSnippetFile ( snippetFilePath , newSnippetFileContent ) ;
47
46
}
48
47
49
48
export { updatePrefixSymbol } ;
0 commit comments