import { SWATracker } from "@sap/swa-for-sapbas-vsx" ; import { InitializeParams } from "vscode-languageserver" ; import { getLogger } from "./logger" ; export type ISWATracker = Pick < SWATracker , "track" > ; const SWA_NOOP = { track ( eventType , custom_events ? ) { } , } ; Object . freeze ( SWA_NOOP ) ; let SWA_IMPL = SWA_NOOP ; /**
 * only to be used during tests
 */ export function $internalGetSWAImpl ( ) { return SWA_IMPL ; } export function setGlobalSWA ( newSWA ) { SWA_IMPL = newSWA ; } export function initSwa ( params ) { if ( params ?. initializationOptions ) { const { publisher , name } = params . initializationOptions ; if ( publisher !== undefined && name !== undefined ) { getLogger ( ) . info ( "SWA is being initialized" , { publisher , name } ) ; const swa = new SWATracker ( publisher , name , ( err ) => { getLogger ( ) . error ( "Failure during SWA tracking" , { error : err } ) ; } ) ; setGlobalSWA ( swa ) ; } } } export const TRACK_EVENTS = { MANIFEST_STABLE_ID : "manifest stable ID fix" , XML_UI5_DOC_HOVER : "XML UI5 Doc Hover" , } ; Object . freeze ( TRACK_EVENTS ) ; type TrackEventsKeys = keyof typeof TRACK_EVENTS ; export function track ( eventType , ... custom_events ) { try { SWA_IMPL . track ( TRACK_EVENTS [ eventType ] , custom_events ) ; } catch ( e ) { getLogger ( ) . error ( "Runtime Exception during swa.trace()" , { error : e } ) ; } }