import * as path from 'path' ; import * as vscode from 'vscode' ; import * as html from 'vscode-html-languageservice' ; import * as lst from 'vscode-languageserver-types' ; import * as nls from 'vscode-nls' ; import { EdgeFormattingEditProvider } from './providers/EdgeFormattingEditProvider' ; import { LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , RequestType , TextDocumentPositionParams } from 'vscode-languageclient' ; const service = html . getLanguageService ( ) ; const localize = nls . loadMessageBundle ( ) ; class DocumentHighlight implements vscode . DocumentHighlightProvider { provideDocumentHighlights ( document , position , token ) { let doc = lst . TextDocument . create ( document . uri . fsPath , 'html' , 1 , document . getText ( ) ) ; return ( service . findDocumentHighlights ( doc , position , service . parseHTMLDocument ( doc ) ) as any ) ; } } export function activate ( context ) { let documentSelector = { language : 'edge' , scheme : 'file' } ; context . subscriptions . push ( vscode . languages . registerDocumentHighlightProvider ( documentSelector , new DocumentHighlight ) ) ; let edgeFormatCfg = vscode . workspace . getConfiguration ( 'edge.format' ) ; if ( edgeFormatCfg . get < boolean > ( 'enable' ) ) { context . subscriptions . push ( vscode . languages . registerDocumentFormattingEditProvider ( documentSelector , new EdgeFormattingEditProvider ) ) ; context . subscriptions . push ( vscode . languages . registerDocumentRangeFormattingEditProvider ( documentSelector , new EdgeFormattingEditProvider ) ) ; } const EMPTY_ELEMENTS = [ 'area' , 'base' , 'br' , 'col' , 'embed' , 'hr' , 'img' , 'input' , 'keygen' , 'link' , 'menuitem' , 'meta' , 'param' , 'source' , 'track' , 'wbr' ] ; vscode . languages . setLanguageConfiguration ( 'edge' , { 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 : vscode . IndentAction . IndentOutdent } } , { beforeText : new RegExp ( `<(?!(?:${ EMPTY_ELEMENTS . join ( '|' ) }))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$` , 'i' ) , action : { indentAction : vscode . IndentAction . Indent } } ] , } ) ; let serverModule = context . asAbsolutePath ( path . join ( 'server' , 'out' , 'htmlServerMain.js' ) ) ; let debugOptions = { execArgv : [ '--nolazy' , '--inspect=6045' ] } ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; let embeddedLanguages = { css : true , javascript : true } ; let clientOptions = { documentSelector : [ { language : 'edge' , scheme : 'file' } ] , synchronize : { configurationSection : [ 'edge' , 'css' , 'javascript' , 'emmet' ] , } , initializationOptions : { embeddedLanguages } } ; let client = new LanguageClient ( 'edge' , localize ( 'edgeserver.name' , 'EDGE Language Server' ) , serverOptions , clientOptions ) ; client . registerProposedFeatures ( ) ; context . subscriptions . push ( client . start ( ) ) ; } export function deactivate ( ) { }