'use strict' ; import * as path from 'path' ; import { Color , ColorInformation , ColorPresentation , ExtensionContext , extensions , IndentAction , languages , Position , Range , TextDocument } from 'vscode' ; import { BaseLanguageClient , LanguageClient , LanguageClientOptions , RequestType , ServerOptions , TextDocumentPositionParams , TransportKind } from 'vscode-languageclient' ; import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared' ; import { activateTagClosing } from './tagClosing' ; import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration' ; import { ColorPresentationParams , ColorPresentationRequest , DocumentColorParams , DocumentColorRequest } from 'vscode-languageserver-protocol' ; import { telemetryService } from './telemetry' ; namespace TagCloseRequest { export const type = new RequestType ( 'html/tag' ) ; } export async function activate ( context ) { const extensionHRStart = process . hrtime ( ) ; const toDispose = context . subscriptions ; const serverModule = context . asAbsolutePath ( path . join ( 'node_modules' , '@salesforce' , 'salesforcedx-visualforce-language-server' , 'out' , 'src' , 'visualforceServer.js' ) ) ; const debugOptions = { execArgv : [ '--nolazy' , '--inspect=6004' ] } ; const serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; const documentSelector = [ { language : 'visualforce' , scheme : 'file' } ] ; const embeddedLanguages = { css : true , javascript : true } ; const clientOptions = { documentSelector , synchronize : { configurationSection : [ 'visualforce' , 'css' , 'javascript' ] } , initializationOptions : { embeddedLanguages } } ; const client = new LanguageClient ( 'visualforce' , 'Visualforce Language Server' , serverOptions , clientOptions ) ; client . registerFeature ( new ConfigurationFeature ( client ) ) ; let disposable = client . start ( ) ; toDispose . push ( disposable ) ; client . onReady ( ) . then ( ( ) => { disposable = languages . registerColorProvider ( documentSelector , { provideDocumentColors ( document ) { const params = { textDocument : client . code2ProtocolConverter . asTextDocumentIdentifier ( document ) } ; return client . sendRequest ( DocumentColorRequest . type , params ) . then ( symbols => { return symbols . map ( symbol => { const range = client . protocol2CodeConverter . asRange ( symbol . range ) ; const color = new Color ( symbol . color . red , symbol . color . green , symbol . color . blue , symbol . color . alpha ) ; return new ColorInformation ( range , color ) ; } ) ; } ) ; } , provideColorPresentations ( color , colorContext ) { const params = { textDocument : client . code2ProtocolConverter . asTextDocumentIdentifier ( colorContext . document ) , range : client . code2ProtocolConverter . asRange ( colorContext . range ) , color } ; return client . sendRequest ( ColorPresentationRequest . type , params ) . then ( presentations => { return presentations . map ( p => { const presentation = new ColorPresentation ( p . label ) ; presentation . textEdit = p . textEdit && client . protocol2CodeConverter . asTextEdit ( p . textEdit ) ; presentation . additionalTextEdits = p . additionalTextEdits && client . protocol2CodeConverter . asTextEdits ( p . additionalTextEdits ) ; return presentation ; } ) ; } ) ; } } ) ; toDispose . push ( disposable ) ; const tagRequestor = ( document , position ) => { const param = client . code2ProtocolConverter . asTextDocumentPositionParams ( document , position ) ; return client . sendRequest ( TagCloseRequest . type , param ) ; } ; disposable = activateTagClosing ( tagRequestor , { visualforce : true } , 'visualforce.autoClosingTags' ) ; toDispose . push ( disposable ) ; } ) . catch ( err => { telemetryService . sendExtensionActivationEvent ( err ) ; } ) ; languages . setLanguageConfiguration ( 'visualforce' , { indentationRules : { increaseIndentPattern : /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/ , decreaseIndentPattern : /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/ } , wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g , onEnterRules : [ { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , afterText : /^<\/([_:\w][_:\w-.\d]*)\s*>$/i , action : { indentAction : IndentAction . IndentOutdent } } , { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , action : { indentAction : IndentAction . Indent } } ] } ) ; languages . setLanguageConfiguration ( 'handlebars' , { wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g , onEnterRules : [ { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , afterText : /^<\/([_:\w][_:\w-.\d]*)\s*>$/i , action : { indentAction : IndentAction . IndentOutdent } } , { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , action : { indentAction : IndentAction . Indent } } ] } ) ; languages . setLanguageConfiguration ( 'razor' , { wordPattern : /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g , onEnterRules : [ { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , afterText : /^<\/([_:\w][_:\w-.\d]*)\s*>$/i , action : { indentAction : IndentAction . IndentOutdent } } , { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , action : { indentAction : IndentAction . Indent } } ] } ) ; const sfdxCoreExtension = extensions . getExtension ( 'salesforce.salesforcedx-vscode-core' ) ; if ( sfdxCoreExtension && sfdxCoreExtension . exports ) { telemetryService . initializeService ( sfdxCoreExtension . exports . telemetryService . getReporter ( ) , sfdxCoreExtension . exports . telemetryService . isTelemetryEnabled ( ) ) ; } telemetryService . sendExtensionActivationEvent ( extensionHRStart ) ; } export function deactivate ( ) { console . log ( 'SFDX Visualforce Extension Deactivated' ) ; telemetryService . sendExtensionDeactivationEvent ( ) ; }