File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -13,28 +13,25 @@ export function activate(context: vscode.ExtensionContext) {
13
13
}
14
14
15
15
const selection = editor . document . getText ( editor . selection ) ;
16
- const name = await vscode . window . showInputBox ( {
16
+ let name = await vscode . window . showInputBox ( {
17
17
prompt : "Enter the name of the snippet" ,
18
18
} ) ;
19
19
if ( ! name ) {
20
20
return ;
21
21
}
22
22
23
- const prefix = await vscode . window . showInputBox ( {
24
- prompt : "Enter the prefix of the snippet" ,
25
- } ) ;
26
- if ( ! prefix ) {
27
- return ;
28
- }
23
+ // Sanitize the name for the prefix
24
+ const prefixName = name . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, "-" ) ;
29
25
26
+ // Create the snippet
30
27
const snippet = {
31
28
[ name ] : {
32
- prefix,
29
+ prefix : `/ ${ prefixName } ` ,
33
30
body : [ selection ] ,
34
- description : `Snippet for ${ name } ` ,
35
31
} ,
36
32
} ;
37
33
34
+ // Write the snippet to the workspace file
38
35
const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] ;
39
36
if ( ! workspaceFolder ) {
40
37
vscode . window . showErrorMessage ( "No workspace folder found." ) ;
@@ -63,7 +60,7 @@ export function activate(context: vscode.ExtensionContext) {
63
60
JSON . stringify ( snippetFileContent , null , 2 )
64
61
) ;
65
62
vscode . window . showInformationMessage (
66
- `Snippet "${ name } " created successfully.`
63
+ `Snippet "${ name } " created successfully. You can now use it by typing "/ ${ prefixName } " in a file. `
67
64
) ;
68
65
} catch ( error ) {
69
66
vscode . window . showErrorMessage (
You can’t perform that action at this time.
0 commit comments