import * as path from 'path' ; import * as vscode from 'vscode' ; import { channelService } from '../channel' ; import { nls } from '../messages' ; const EXTENSION_NAME = 'salesforce.salesforcedx-vscode-lwc' ; export class MetaSupport { private static instance : MetaSupport ; public static initializeSupport ( ) { if ( ! MetaSupport . instance ) { MetaSupport . instance = new MetaSupport ( ) ; } return MetaSupport . instance ; } param targetFileName returns private getLocalFilePath ( targetFileNames ) { const thisExtPath = vscode . extensions . getExtension ( EXTENSION_NAME ) ! . extensionPath ; const listOfPaths = [ ] ; targetFileNames . forEach ( targetFileName => { listOfPaths . push ( path . join ( thisExtPath , 'resources' , 'static' , targetFileName ) ) ; } ) ; return listOfPaths ; } param inputCatalogs param inputFileAssociations returns private async setupRedhatXml ( inputCatalogs , inputFileAssociations ) { const redHatExtension = vscode . extensions . getExtension ( 'redhat.vscode-xml' ) ; try { const extensionApi = await redHatExtension ! . activate ( ) ; extensionApi . addXMLCatalogs ( inputCatalogs ) ; extensionApi . addXMLFileAssociations ( inputFileAssociations ) ; } catch ( error ) { channelService . appendLine ( nls . localize ( 'force_lightning_lwc_fail_redhat_extension' ) ) ; const errorMsg = error . message ? error . message : error ; channelService . appendLine ( errorMsg ) ; } } /**
     * This function checks the enviornment and passes relevant settings
     * to set up RedHat XML
     */ public async getMetaSupport ( ) { const redHatExtension = vscode . extensions . getExtension ( 'redhat.vscode-xml' ) ; if ( redHatExtension === undefined ) { channelService . appendLine ( nls . localize ( 'force_lightning_lwc_no_redhat_extension_found' ) ) ; } else if ( redHatExtension ) { const pluginVersionNumber = redHatExtension ! . packageJSON [ 'version' ] ; const major = parseInt ( pluginVersionNumber . split ( '.' ) [ 0 ] , 10 ) ; const minor = parseInt ( pluginVersionNumber . split ( '.' ) [ 1 ] , 10 ) ; if ( major >= 1 || minor === 14 || minor >= 16 ) { const catalogs = this . getLocalFilePath ( [ 'js-meta-home.xml' ] ) ; const fileAssociations = [ { systemId : this . getLocalFilePath ( [ 'js-meta.xsd' ] ) [ 0 ] , pattern : '**/*js-meta.xml' } ] ; await this . setupRedhatXml ( catalogs , fileAssociations ) ; } else if ( minor === 15 ) { channelService . appendLine ( nls . localize ( 'force_lightning_lwc_redhat_extension_regression' ) ) ; } else { channelService . appendLine ( nls . localize ( 'force_lightning_lwc_deprecated_redhat_extension' ) ) ; } } } }