import { shared as lspCommon } from '@salesforce/lightning-lsp-common' ; import { TelemetryService } from '@salesforce/salesforcedx-utils-vscode/out/src' ; import * as path from 'path' ; import { ExtensionContext , ProgressLocation , Uri , window , workspace } from 'vscode' ; import { LanguageClient , LanguageClientOptions , ServerOptions , TransportKind } from 'vscode-languageclient' ; import { nls } from './messages' ; const EXTENSION_NAME = 'salesforcedx-vscode-lightning' ; export function code2ProtocolConverter ( value ) { if ( /^win32/ . test ( process . platform ) ) { return value . toString ( ) . replace ( '%3A' , ':' ) ; } else { return value . toString ( ) ; } } function protocol2CodeConverter ( value ) { return Uri . parse ( value ) ; } function getActivationMode ( ) { const config = workspace . getConfiguration ( 'salesforcedx-vscode-lightning' ) ; return config . get ( 'activationMode' ) || 'autodetect' ; } export async function activate ( context ) { const extensionHRStart = process . hrtime ( ) ; console . log ( 'Activation Mode: ' + getActivationMode ( ) ) ; if ( getActivationMode ( ) === 'off' ) { console . log ( 'Aura Language Server activationMode set to off, exiting...' ) ; return ; } if ( ! workspace . workspaceFolders ) { console . log ( 'No workspace, exiting extension' ) ; return ; } const workspaceUris = [ ] ; workspace . workspaceFolders . forEach ( folder => { workspaceUris . push ( folder . uri . fsPath ) ; } ) ; const workspaceType = lspCommon . detectWorkspaceType ( workspaceUris ) ; if ( getActivationMode ( ) === 'autodetect' && ! lspCommon . isLWC ( workspaceType ) ) { console . log ( 'Aura LSP - autodetect did not find a valid project structure, exiting....' ) ; console . log ( 'WorkspaceType detected: ' + workspaceType ) ; return ; } console . log ( 'Aura Components Extension Activated' ) ; console . log ( 'WorkspaceType detected: ' + workspaceType ) ; const extensionPackage = require ( context . asAbsolutePath ( './package.json' ) ) ; await TelemetryService . getInstance ( ) . initializeService ( context , EXTENSION_NAME , extensionPackage . aiKey , extensionPackage . version ) ; const serverModule = context . asAbsolutePath ( path . join ( 'node_modules' , '@salesforce' , 'aura-language-server' , 'lib' , 'server.js' ) ) ; const debugOptions = { execArgv : [ '--nolazy' , '--inspect=6020' ] } ; const serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; const clientOptions = { outputChannelName : nls . localize ( 'channel_name' ) , documentSelector : [ { language : 'html' , scheme : 'file' } , { language : 'html' , scheme : 'untitled' } , { language : 'javascript' , scheme : 'file' } , { language : 'javascript' , scheme : 'untitled' } ] , synchronize : { fileEvents : [ workspace . createFileSystemWatcher ( '**/*.resource' ) , workspace . createFileSystemWatcher ( '**/labels/CustomLabels.labels-meta.xml' ) , workspace . createFileSystemWatcher ( '**/aura/*/*.{cmp,app,intf,evt,js}' ) , workspace . createFileSystemWatcher ( '**/components/*/*/*.{cmp,app,intf,evt,lib,js}' ) , workspace . createFileSystemWatcher ( '**/' , true , true , false ) , workspace . createFileSystemWatcher ( '**/staticresources/*.resource-meta.xml' ) , workspace . createFileSystemWatcher ( '**/contentassets/*.asset-meta.xml' ) , workspace . createFileSystemWatcher ( '**/lwc/*/*.js' ) , workspace . createFileSystemWatcher ( '**/modules/*/*/*.js' ) ] } , uriConverters : { code2Protocol : code2ProtocolConverter , protocol2Code : protocol2CodeConverter } } ; const client = new LanguageClient ( 'auraLanguageServer' , nls . localize ( 'client_name' ) , serverOptions , clientOptions ) ; client . onReady ( ) . then ( ( ) => { client . onNotification ( 'salesforce/indexingStarted' , startIndexing ) ; client . onNotification ( 'salesforce/indexingEnded' , endIndexing ) ; } ) . catch ( ) ; const disp = client . start ( ) ; context . subscriptions . push ( disp ) ; TelemetryService . getInstance ( ) . sendExtensionActivationEvent ( extensionHRStart ) ; } let indexingResolve ; function startIndexing ( ) { const indexingPromise = new Promise ( resolve => { indexingResolve = resolve ; } ) ; reportIndexing ( indexingPromise ) ; } function endIndexing ( ) { indexingResolve ( undefined ) ; } function reportIndexing ( indexingPromise ) { window . withProgress ( { location : ProgressLocation . Window , title : nls . localize ( 'index_components_text' ) , cancellable : true } , ( ) => { return indexingPromise ; } ) ; } export function deactivate ( ) { console . log ( 'Aura Components Extension Deactivated' ) ; TelemetryService . getInstance ( ) . sendExtensionDeactivationEvent ( ) ; }