@@ -20,10 +20,33 @@ import typescriptSnippets, {
2020 TypescriptSnippet ,
2121} from '../sourceSnippets/typescript' ;
2222
23+ import { window } from 'vscode' ;
24+
2325import extensionConfig from './extensionConfig' ;
2426import parseSnippetToBody from './parseSnippetToBody' ;
2527import { 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+
2750export type SnippetKeys =
2851 | OthersSnippet [ 'key' ]
2952 | HooksSnippet [ 'key' ]
@@ -53,7 +76,8 @@ export type Snippets = {
5376} ;
5477
5578const 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