'use strict' ; import * as DebuggerExtension from './Debugger/extension' ; import * as LanguageServer from './LanguageServer/extension' ; import * as os from 'os' ; import * as path from 'path' ; import * as Telemetry from './telemetry' ; import * as util from './common' ; import * as vscode from 'vscode' ; import { CppToolsApi , CppToolsExtension } from 'vscode-cpptools' ; import { PlatformInformation } from './platform' ; import { CppTools1 } from './cppTools1' ; import { CppSettings } from './LanguageServer/settings' ; import { PersistentState } from './LanguageServer/persistentState' ; const cppTools = new CppTools1 ( ) ; let languageServiceDisabled = false ; let reloadMessageShown = false ; const disposables = [ ] ; export async function activate ( context ) { util . setExtensionContext ( context ) ; Telemetry . activate ( ) ; util . setProgress ( 0 ) ; class SchemaProvider implements vscode . TextDocumentContentProvider { public async provideTextDocumentContent ( uri ) { console . assert ( uri . path [ 0 ] === '/' , "A preceeding slash is expected on schema uri path" ) ; const fileName = uri . path . substr ( 1 ) ; const locale = util . getLocaleId ( ) ; let localizedFilePath = util . getExtensionFilePath ( path . join ( "dist/schema/" , locale , fileName ) ) ; const fileExists = await util . checkFileExists ( localizedFilePath ) ; if ( ! fileExists ) { localizedFilePath = util . getExtensionFilePath ( fileName ) ; } return util . readFileText ( localizedFilePath ) ; } } vscode . workspace . registerTextDocumentContentProvider ( 'cpptools-schema' , new SchemaProvider ( ) ) ; DebuggerExtension . initialize ( context ) ; const info = await PlatformInformation . GetPlatformInformation ( ) ; sendTelemetry ( info ) ; await makeBinariesExecutable ( ) ; util . checkDistro ( info ) ; const settings = new CppSettings ( ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) ? vscode . workspace . workspaceFolders [ 0 ] ?. uri : undefined ) ; if ( settings . intelliSenseEngine === "Disabled" ) { languageServiceDisabled = true ; disposables . push ( vscode . workspace . onDidChangeConfiguration ( ( ) => { if ( ! reloadMessageShown && settings . intelliSenseEngine !== "Disabled" ) { reloadMessageShown = true ; util . promptForReloadWindowDueToSettingsChange ( ) ; } } ) ) ; } else { disposables . push ( vscode . workspace . onDidChangeConfiguration ( ( ) => { if ( ! reloadMessageShown && settings . intelliSenseEngine === "Disabled" ) { reloadMessageShown = true ; util . promptForReloadWindowDueToSettingsChange ( ) ; } } ) ) ; } LanguageServer . activate ( ) ; UpdateInsidersAccess ( ) ; return cppTools ; } export function deactivate ( ) { DebuggerExtension . dispose ( ) ; Telemetry . deactivate ( ) ; disposables . forEach ( d => d . dispose ( ) ) ; if ( languageServiceDisabled ) { return Promise . resolve ( ) ; } return LanguageServer . deactivate ( ) ; } async function makeBinariesExecutable ( ) { const promises = [ ] ; if ( process . platform !== 'win32' ) { const commonBinaries = [ "./bin/cpptools" , "./bin/cpptools-srv" , "./LLVM/bin/clang-format" , "./LLVM/bin/clang-tidy" , "./debugAdapters/bin/OpenDebugAD7" ] ; commonBinaries . forEach ( binary => promises . push ( util . allowExecution ( util . getExtensionFilePath ( binary ) ) ) ) ; if ( process . platform === "darwin" ) { const macBinaries = [ "./debugAdapters/lldb-mi/bin/lldb-mi" , "./debugAdapters/lldb/bin/debugserver" , "./debugAdapters/lldb/bin/lldb-mi" , "./debugAdapters/lldb/bin/lldb-argdumper" , "./debugAdapters/lldb/bin/lldb-launcher" ] ; macBinaries . forEach ( binary => promises . push ( util . allowExecution ( util . getExtensionFilePath ( binary ) ) ) ) ; } } await Promise . all ( promises ) ; } function sendTelemetry ( info ) { const telemetryProperties = { } ; if ( info . distribution ) { telemetryProperties [ 'linuxDistroName' ] = info . distribution . name ; telemetryProperties [ 'linuxDistroVersion' ] = info . distribution . version ; } telemetryProperties [ 'osArchitecture' ] = os . arch ( ) ; telemetryProperties [ 'infoArchitecture' ] = info . architecture ; Telemetry . logDebuggerEvent ( "acquisition" , telemetryProperties ) ; } export function UpdateInsidersAccess ( ) { const settings = new CppSettings ( ) ; const migratedInsiders = new PersistentState < boolean > ( "CPP.migratedInsiders" , false ) ; if ( settings . updateChannel === "Insiders" ) { if ( ! migratedInsiders . Value && vscode . workspace . getConfiguration ( "extensions" , null ) . get < boolean > ( "autoUpdate" ) ) { migratedInsiders . Value = true ; vscode . commands . executeCommand ( "workbench.extensions.installExtension" , "ms-vscode.cpptools" , { installPreReleaseVersion : true } ) ; } } else { if ( migratedInsiders . Value ) { migratedInsiders . Value = false ; } } }