Skip to content

Commit 9814f2d

Browse files
committed
fix: validate languageScopes setting and fix activationEvents casing
1 parent 7d0f39c commit 9814f2d

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
},
4141
"activationEvents": [
4242
"onLanguage:typescript",
43-
"onLanguage:typescriptReact",
43+
"onLanguage:typescriptreact",
4444
"onLanguage:javascript",
45-
"onLanguage:javascriptReact",
45+
"onLanguage:javascriptreact",
4646
"onCommand:reactSnippets.search",
4747
"onStartupFinished"
4848
],

src/helpers/generateSnippets.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,33 @@ import typescriptSnippets, {
2020
TypescriptSnippet,
2121
} from '../sourceSnippets/typescript';
2222

23+
import { window } from 'vscode';
24+
2325
import extensionConfig from './extensionConfig';
2426
import parseSnippetToBody from './parseSnippetToBody';
2527
import { replaceSnippetPlaceholders } from './snippetPlaceholders';
2628

29+
const VALID_LANGUAGE_SCOPES = [
30+
'typescript',
31+
'typescriptreact',
32+
'javascript',
33+
'javascriptreact',
34+
];
35+
36+
const validateLanguageScopes = (scopes: string) => {
37+
const requested = scopes.split(',').map((s) => s.trim()).filter(Boolean);
38+
const valid = requested.filter((s) => VALID_LANGUAGE_SCOPES.includes(s));
39+
const invalid = requested.filter((s) => !VALID_LANGUAGE_SCOPES.includes(s));
40+
41+
if (invalid.length > 0) {
42+
window.showWarningMessage(
43+
`React Snippets: Invalid language scopes ignored: ${invalid.join(', ')}. Valid values: ${VALID_LANGUAGE_SCOPES.join(', ')}`,
44+
);
45+
}
46+
47+
return valid.length > 0 ? valid.join(',') : VALID_LANGUAGE_SCOPES.join(',');
48+
};
49+
2750
export type SnippetKeys =
2851
| OthersSnippet['key']
2952
| HooksSnippet['key']
@@ -53,7 +76,8 @@ export type Snippets = {
5376
};
5477

5578
const getSnippets = () => {
56-
const { typescript, languageScopes } = extensionConfig();
79+
const { typescript, languageScopes: rawScopes } = extensionConfig();
80+
const languageScopes = validateLanguageScopes(rawScopes);
5781

5882
const snippets = [
5983
...(typescript ? typescriptSnippets : []),

0 commit comments

Comments
 (0)