Skip to content

Commit a3d125d

Browse files
committed
Update vsc config string, add setScope config
1 parent ad656a0 commit a3d125d

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
"type": "object",
4343
"title": "Workspace Code Snippets",
4444
"properties": {
45-
"prefixSymbol": {
45+
"workspaceCodeSnippets.prefixSymbol": {
4646
"type": "string",
4747
"default": "/"
48+
},
49+
"workspaceCodeSnippets.setScope": {
50+
"type": "boolean",
51+
"default": true
4852
}
4953
}
5054
}

src/createCodeSnippet.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ async function createCodeSnippet() {
2929
}
3030

3131
let prefixName = sanitizeName(name);
32-
const prefixSymbol = vscode.workspace.getConfiguration().get("prefixSymbol");
32+
const prefixSymbol = vscode.workspace
33+
.getConfiguration()
34+
.get("workspaceCodeSnippets.prefixSymbol");
3335

3436
if (prefixSymbol) {
3537
prefixName = `${prefixSymbol}${prefixName}`;
3638
}
37-
const snippet = createSnippet(
38-
name,
39-
prefixName,
40-
editor.document.languageId,
41-
selection
42-
);
39+
40+
const setScope = vscode.workspace
41+
.getConfiguration("workspaceCodeSnippets")
42+
.get("setScope");
43+
44+
let langScope = "";
45+
setScope && (langScope = editor.document.languageId);
46+
47+
const snippet = createSnippet(name, prefixName, langScope, selection);
4348

4449
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
4550
if (!workspaceFolder) {

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function activate(context: vscode.ExtensionContext) {
1616

1717
// Update prefix symbol when configuration changes
1818
vscode.workspace.onDidChangeConfiguration((event) => {
19-
if (event.affectsConfiguration("prefixSymbol")) {
19+
if (event.affectsConfiguration("workspaceCodeSnippets.prefixSymbol")) {
2020
updatePrefixSymbol();
2121
}
2222
});

src/updatePrefixSymbol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function updatePrefixSymbol() {
3232
if (hasSpecialChar) {
3333
const prefixSymbol = vscode.workspace
3434
.getConfiguration()
35-
.get("prefixSymbol") as string;
35+
.get("workspaceCodeSnippets.prefixSymbol") as string;
3636
newPrefix = newPrefix.replace(specialCharRegex, prefixSymbol);
3737
}
3838
const newSnippet = {

0 commit comments

Comments
 (0)