Skip to content

Commit be8b0e9

Browse files
committed
create prefix from name
1 parent 06a65f6 commit be8b0e9

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/extension.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff 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-zA-Z0-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(

0 commit comments

Comments
 (0)