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) {
1313 }
1414
1515 const selection = editor . document . getText ( editor . selection ) ;
16- const name = await vscode . window . showInputBox ( {
16+ let name = await vscode . window . showInputBox ( {
1717 prompt : "Enter the name of the snippet" ,
1818 } ) ;
1919 if ( ! name ) {
2020 return ;
2121 }
2222
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, "-" ) ;
2925
26+ // Create the snippet
3027 const snippet = {
3128 [ name ] : {
32- prefix,
29+ prefix : `/ ${ prefixName } ` ,
3330 body : [ selection ] ,
34- description : `Snippet for ${ name } ` ,
3531 } ,
3632 } ;
3733
34+ // Write the snippet to the workspace file
3835 const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] ;
3936 if ( ! workspaceFolder ) {
4037 vscode . window . showErrorMessage ( "No workspace folder found." ) ;
@@ -63,7 +60,7 @@ export function activate(context: vscode.ExtensionContext) {
6360 JSON . stringify ( snippetFileContent , null , 2 )
6461 ) ;
6562 vscode . window . showInformationMessage (
66- `Snippet "${ name } " created successfully.`
63+ `Snippet "${ name } " created successfully. You can now use it by typing "/ ${ prefixName } " in a file. `
6764 ) ;
6865 } catch ( error ) {
6966 vscode . window . showErrorMessage (
You can’t perform that action at this time.
0 commit comments