import * as vscode from "vscode" ; import * as fs from "fs" ; export class WorkbenchExtension { private static extension : vscode . Extension < any > | undefined ; static getExtension ( context ) { if ( ! WorkbenchExtension . extension ) { const extensionId = WorkbenchExtension . getExtensionId ( context ) ; WorkbenchExtension . extension = vscode . extensions . getExtension ( extensionId ) ; } return WorkbenchExtension . extension ; } private static getExtensionId ( context ) { const packageJsonPath = context . asAbsolutePath ( "./package.json" ) ; const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf8" ) ) ; const extensionId = packageJson . publisher + "." + packageJson . name ; return extensionId ; } }