'use strict' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import { window , commands , workspace , Disposable , ExtensionContext , StatusBarItem , StatusBarAlignment } from 'vscode' ; import { LanguageClient , LanguageClientOptions , SettingMonitor , ServerOptions , TransportKind } from 'vscode-languageclient' ; import { ComPortAutoCompleteProvider } from './features/ComPortAutoCompleteProvider' ; import { DeviceInfoContentProvider } from './features/DeviceInfoContentProvider' ; import { NodeMcuCommands } from './features/nodeMcuCommands' ; /**
 *
 */ function showNodeMCUToolbox ( ) { vscode . commands . executeCommand ( 'vscode.previewHtml' , DeviceInfoContentProvider . uri , vscode . ViewColumn . One , 'NodeMCU Toolbox' ) . then ( ( success ) => { } , ( reason ) => { vscode . window . showErrorMessage ( reason ) ; } ) ; } /**
 *
 */ export function activate ( context ) { let serverModule = context . asAbsolutePath ( path . join ( 'server' , 'server.js' ) ) ; let debugOptions = { execArgv : [ "--nolazy" , "--debug=6004" ] } ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; let clientOptions = { documentSelector : [ 'lua' ] , synchronize : { configurationSection : 'languageServerExample' , fileEvents : workspace . createFileSystemWatcher ( '**/.clientrc' ) } } ; let disposable = new LanguageClient ( 'Language Server Example' , serverOptions , clientOptions ) . start ( ) ; context . subscriptions . push ( disposable ) ; let sel = { language : 'json' , pattern : '**/launch.json' } ; context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( 'json' , new ComPortAutoCompleteProvider ( ) , ':' ) ) ; const provider = new DeviceInfoContentProvider ( ) ; context . subscriptions . push ( workspace . registerTextDocumentContentProvider ( DeviceInfoContentProvider . uri . scheme , provider ) ) ; context . subscriptions . push ( provider ) ; let mcuCommands = new NodeMcuCommands ( context ) ; let fsListVisible = false ; mcuCommands . onDidListFiles ( ( files ) => { fsListVisible = true ; provider . onFileList ( files ) ; } ) ; mcuCommands . onError ( ( error ) => { fsListVisible = false ; provider . onMessage ( error ) ; } ) ; mcuCommands . onProgressMessage ( ( message ) => { fsListVisible = false ; provider . onMessage ( message ) ; } ) ; mcuCommands . onDidLoadSystemInfo ( ( sysInfo ) => { fsListVisible = false ; provider . onSystemInfo ( sysInfo ) ; } ) ; mcuCommands . onDidReboot ( ( ) => { fsListVisible = false ; provider . onReboot ( ) ; } ) ; mcuCommands . onFSChanged ( ( ) => { if ( fsListVisible ) { vscode . commands . executeCommand ( 'nodemcu.listFiles' ) ; } } ) ; context . subscriptions . push ( commands . registerCommand ( 'nodemcu.showToolbox' , ( ) => { provider . onMessage ( "Select action from the menu above." ) ; showNodeMCUToolbox ( ) ; } ) ) ; }