'use strict' ; import * as vscode from 'vscode' ; import * as fs from 'fs' ; import * as path from 'path' ; import PostgreSQLLanguageClient from './language/client' ; import { PostgreSQLTreeDataProvider } from './tree/treeProvider' ; import { Global } from './common/global' ; import { EditorState } from './common/editorState' ; import { ConfigFS } from './common/configFileSystem' ; import { ResultsManager } from './resultsview/resultsManager' ; import { IConnection } from './common/IConnection' ; import { Constants } from './common/constants' ; export async function activate ( context ) { console . log ( `Congratulations, your extension "${ context . extension . id }" is now active!` ) ; let languageClient = new PostgreSQLLanguageClient ( context ) ; let treeProvider = PostgreSQLTreeDataProvider . getInstance ( context ) ; Global . context = context ; EditorState . getInstance ( languageClient ) ; try { let commandPath = context . asAbsolutePath ( path . join ( 'out' , 'commands' ) ) ; let files = fs . readdirSync ( commandPath ) ; for ( const file of files ) { if ( path . extname ( file ) === '.map' ) continue ; let baseName = path . basename ( file , '.js' ) ; let className = baseName + 'Command' ; let commandClass = require ( `./commands/${ baseName }` ) ; new commandClass [ className ] ( context ) ; } } catch ( err ) { console . error ( 'Command loading error:' , err ) ; } Global . ResultManager = new ResultsManager ( ) ; context . subscriptions . push ( Global . ResultManager ) ; vscode . workspace . onDidOpenTextDocument ( async ( e ) => { await EditorState . setNonActiveConnection ( e , null ) ; } ) ; const configFS = new ConfigFS ( ) ; context . subscriptions . push ( vscode . workspace . registerFileSystemProvider ( 'postgres-config' , configFS , { isCaseSensitive : true } ) ) ; const migratedPassword = context . globalState . get < boolean | undefined > ( 'postgresql.connections.pwd-migrated' ) ; if ( ! migratedPassword ) { const connections = context . globalState . get < { [ key ] : IConnection ; } > ( Constants . GlobalStateKey ) ; if ( connections ) { for ( const id of Object . keys ( connections ) ) { let connection = Object . assign ( { } , connections [ id ] ) ; if ( connection . hasPassword || ! connection . hasOwnProperty ( 'hasPassword' ) ) { let pwd = await Global . keytar . getPassword ( Constants . ExtensionId , id ) ; if ( typeof pwd !== 'undefined' && pwd !== null ) { await context . secrets . store ( id , pwd ) ; await Global . keytar . deletePassword ( Constants . ExtensionId , id ) ; } } } } await context . globalState . update ( 'postgresql.connections.pwd-migrated' , true ) ; } } export function deactivate ( ) { }