import ace from 'brace' ; import { XJsonHighlightRules } from '../index' ; import { workerModule } from './worker' ; const { WorkerClient } = ace . acequire ( 'ace/worker/worker_client' ) ; const oop = ace . acequire ( 'ace/lib/oop' ) ; const { Mode : JSONMode } = ace . acequire ( 'ace/mode/json' ) ; const { Tokenizer : AceTokenizer } = ace . acequire ( 'ace/tokenizer' ) ; const { MatchingBraceOutdent } = ace . acequire ( 'ace/mode/matching_brace_outdent' ) ; const { CstyleBehaviour } = ace . acequire ( 'ace/mode/behaviour/cstyle' ) ; const { FoldMode : CStyleFoldMode } = ace . acequire ( 'ace/mode/folding/cstyle' ) ; const XJsonMode = function XJsonMode ( this ) { const ruleset = new ( XJsonHighlightRules as any ) ( ) ; ruleset . normalizeRules ( ) ; this . $tokenizer = new AceTokenizer ( ruleset . getRules ( ) ) ; this . $outdent = new MatchingBraceOutdent ( ) ; this . $behaviour = new CstyleBehaviour ( ) ; this . foldingRules = new CStyleFoldMode ( ) ; } ; oop . inherits ( XJsonMode , JSONMode ) ; ( XJsonMode . prototype as any ) . createWorker = function ( session ) { const xJsonWorker = new WorkerClient ( [ 'ace' ] , workerModule , 'JsonWorker' ) ; xJsonWorker . attachToDocument ( session . getDocument ( ) ) ; xJsonWorker . on ( 'annotate' , function ( e ) { session . setAnnotations ( e . data ) ; } ) ; xJsonWorker . on ( 'terminate' , function ( ) { session . clearAnnotations ( ) ; } ) ; return xJsonWorker ; } ; export { XJsonMode } ; export function installXJsonMode ( editor ) { const session = editor . getSession ( ) ; session . setMode ( new XJsonMode ( ) ) ; }