@@ -3,7 +3,11 @@ import * as vscode from 'vscode';
33import { TFolder } from 'custom_typings' ;
44import crypto from 'crypto' ;
55import fileSystem from 'fs' ;
6- import { imgExtensions } from './img_extensions' ;
6+
7+ export let packageJSON : any ; // global variable
8+ export function readPackageJSON ( context : vscode . ExtensionContext ) {
9+ packageJSON = context . extension . packageJSON ;
10+ }
711
812export function getCwd ( ) {
913 if ( ! vscode . workspace . workspaceFolders ) {
@@ -25,8 +29,17 @@ function getNonce() {
2529}
2630export const nonce = getNonce ( ) ;
2731
32+ function getImageExtensions ( ) {
33+ const pattern = packageJSON . contributes . customEditors [ 0 ] . selector [ 0 ] . filenamePattern ;
34+ const regex = / (?< = \{ ) ( .* ?) (? = \} ) / g;
35+ const match = pattern . match ( regex ) [ 0 ] ;
36+ const imageExtensions : string [ ] = match . split ( ',' ) ;
37+ return imageExtensions ;
38+ }
39+
2840export function getGlob ( ) {
29- let upperCaseImg = imgExtensions . map ( ext => ext . toUpperCase ( ) ) ;
41+ const imgExtensions = getImageExtensions ( ) ;
42+ const upperCaseImg = imgExtensions . map ( ext => ext . toUpperCase ( ) ) ;
3043 const globPattern = `**/*.{${ [ ...imgExtensions , ...upperCaseImg ] . join ( ',' ) } }` ;
3144 return globPattern ;
3245}
0 commit comments