namespace pxt . vs { export interface BlockDefiniton { commentAttr : pxtc . CommentAttrs ; fns ? : Map < string > ; } export interface MethodDef { sig : string ; snippet : string ; comment ? : string ; metaData ? : pxtc . CommentAttrs ; snippetOnly ? : boolean ; } export interface NameDefiniton { fns : { [ fn ] : MethodDef ; } ; vars ? : { [ index ] : string ; } ; metaData ? : pxtc . CommentAttrs ; builtin ? : boolean ; } export type DefinitionMap = { [ ns ] : NameDefiniton ; } ; export function syncModels ( mainPkg , libs , currFile , readOnly ) { if ( readOnly ) return ; let extraLibs = ( monaco . languages . typescript . typescriptDefaults as any ) . getExtraLibs ( ) ; let modelMap = { } ; mainPkg . sortedDeps ( ) . forEach ( pkg => { pkg . getFiles ( ) . forEach ( f => { let fp = pkg . id + "/" + f ; let proto = "pkg:" + fp ; if ( /\.(ts)$/ . test ( f ) && fp != currFile ) { if ( ! ( monaco . languages . typescript . typescriptDefaults as any ) . getExtraLibs ( ) [ fp ] ) { let content = pkg . readFile ( f ) || "\n" ; libs [ fp ] = monaco . languages . typescript . typescriptDefaults . addExtraLib ( content , fp ) ; } modelMap [ fp ] = "1" ; } } ) ; } ) ; Object . keys ( extraLibs ) . filter ( lib => /\.(ts)$/ . test ( lib ) && ! modelMap [ lib ] ) . forEach ( lib => { libs [ lib ] . dispose ( ) ; } ) ; } export function initMonacoAsync ( element ) { return new Promise < monaco . editor . IStandaloneCodeEditor > ( ( resolve , reject ) => { if ( typeof ( ( window as any ) . monaco ) === 'object' ) { resolve ( createEditor ( element ) ) ; return ; } let monacoPaths = ( window as any ) . MonacoPaths ; let onGotAmdLoader = ( ) => { let req = ( window as any ) . require ; req . config ( { paths : monacoPaths } ) ; req ( [ 'vs/editor/editor.main' ] , ( ) => { setupMonaco ( ) ; resolve ( createEditor ( element ) ) ; } ) ; } ; if ( ! ( < any > window ) . require ) { let loaderScript = document . createElement ( 'script' ) ; loaderScript . type = 'text/javascript' ; loaderScript . src = monacoPaths [ 'vs/loader' ] ; loaderScript . addEventListener ( 'load' , onGotAmdLoader ) ; document . body . appendChild ( loaderScript ) ; } else { onGotAmdLoader ( ) ; } } ) ; } function setupMonaco ( ) { initAsmMonarchLanguage ( ) ; initTypeScriptLanguageDefinition ( ) ; } export function createEditor ( element ) { const inverted = pxt . appTarget . appTheme . invertedMonaco ; const hasFieldEditors = ! ! ( pxt . appTarget . appTheme . monacoFieldEditors && pxt . appTarget . appTheme . monacoFieldEditors . length ) ; const isAndroid = pxt . BrowserUtils . isAndroid ( ) ; let editor = monaco . editor . create ( element , { model : null , ariaLabel : Util . lf ( "JavaScript editor" ) , fontFamily : "'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace'" , scrollBeyondLastLine : true , language : "typescript" , mouseWheelZoom : false , wordBasedSuggestions : true , lineNumbersMinChars : 3 , formatOnPaste : true , folding : hasFieldEditors , glyphMargin : hasFieldEditors || pxt . appTarget . appTheme . debugger , minimap : { enabled : false } , fixedOverflowWidgets : true , autoIndent : "full" , useTabStops : true , dragAndDrop : true , matchBrackets : "always" , occurrencesHighlight : false , quickSuggestionsDelay : 200 , theme : inverted ? 'vs-dark' : 'vs' , renderIndentGuides : true , accessibilityHelpUrl : "" , quickSuggestions : { "other" : ! isAndroid , "comments" : ! isAndroid , "strings" : ! isAndroid } , acceptSuggestionOnCommitCharacter : ! isAndroid , acceptSuggestionOnEnter : ! isAndroid ? "on" : "off" , accessibilitySupport : ! isAndroid ? "on" : "off" } ) ; editor . layout ( ) ; return editor ; } function initAsmMonarchLanguage ( ) { monaco . languages . register ( { id : 'asm' , extensions : [ '.asm' ] } ) ; monaco . languages . setMonarchTokensProvider ( 'asm' , < monaco . languages . IMonarchLanguage > { tokenPostfix : '' , keywords : [ 'movs' , 'mov' , 'adds' , 'add' , 'adcs' , 'adr' , 'subs' , 'sbcs' , 'sub' , 'rsbs' , 'muls' , 'cmp' , 'cmn' , 'ands' , 'eors' , 'orrs' , 'bics' , 'mvns' , 'tst' , 'lsls' , 'lsrs' , 'asrs' , 'rors' , 'ldr' , 'ldrh' , 'ldrb' , 'ldrsh' , 'ldrsb' , 'ldm' , 'str' , 'strh' , 'strb' , 'stm' , 'push' , 'pop' , 'cbz' , 'cbnz' , 'b' , 'bl' , 'bx' , 'blx' , 'sxth' , 'sxtb' , 'uxth' , 'uxtb' , 'rev' , 'rev16' , 'revsh' , 'svc' , 'cpsid' , 'cpsie' , 'setend' , 'bkpt' , 'nop' , 'sev' , 'wfe' , 'wfi' , 'yield' , 'beq' , 'bne' , 'bcs' , 'bhs' , 'bcc' , 'blo' , 'bmi' , 'bpl' , 'bvs' , 'bvc' , 'bhi' , 'bls' , 'bge' , 'blt' , 'bgt' , 'ble' , 'bal' , 'r0' , 'r1' , 'r2' , 'r3' , 'r4' , 'r5' , 'r6' , 'r7' , 'r8' , 'r9' , 'r10' , 'r11' , 'r12' , 'r13' , 'r14' , 'r15' , 'pc' , 'sp' , 'lr' ] , typeKeywords : [ '.startaddr' , '.hex' , '.short' , '.space' , '.section' , '.string' , '.byte' ] , operators : [ ] , symbols : /[:\*]+/ , escapes : /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/ , tokenizer : { root : [ [ /(\.)?[a-z_$\.][\w$]*/ , { cases : { '@typeKeywords' : 'keyword' , '@keywords' : 'keyword' , '@default' : 'identifier' } } ] , { include : '@whitespace' } , [ /[{}()\[\]]/ , '@brackets' ] , [ /[<>](?!@symbols)/ , '@brackets' ] , [ /@symbols/ , { cases : { '@operators' : 'operator' , '@default' : '' } } ] , [ /@\s*[a-zA-Z_\$][\w\$]*/ , { token : 'annotation' } ] , [ /(#|(0[xX]))?[0-9a-fA-F]+/ , 'number' ] , [ /[;,.]/ , 'delimiter' ] , [ /"([^"\\]|\\.)*$/ , 'string.invalid' ] , [ /"/ , { token : 'string.quote' , bracket : '@open' , next : '@string' } ] , [ /'[^\\']'/ , 'string' ] , [ /(')(@escapes)(')/ , [ 'string' , 'string.escape' , 'string' ] ] , [ /'/ , 'string.invalid' ] ] , comment : [ ] , string : [ [ /[^\\"]+/ , 'string' ] , [ /@escapes/ , 'string.escape' ] , [ /\\./ , 'string.escape.invalid' ] , [ /"/ , { token : 'string.quote' , bracket : '@close' , next : '@pop' } ] ] , whitespace : [ [ /[ \t\r\n]+/ , 'white' ] , [ /\/\*/ , 'comment' , '@comment' ] , [ /;.*$/ , 'comment' ] , ] , } } ) ; } function initTypeScriptLanguageDefinition ( ) { if ( ! monaco . languages . typescript ) { return ; } monaco . languages . typescript . typescriptDefaults . setDiagnosticsOptions ( { noSyntaxValidation : true , noSemanticValidation : true } ) ; monaco . languages . typescript . typescriptDefaults . setWorkerOptions ( { customWorkerPath : pxt . webConfig . typeScriptWorkerJs } ) ; monaco . languages . typescript . typescriptDefaults . setCompilerOptions ( { allowUnreachableCode : true , noImplicitAny : true , allowJs : false , allowUnusedLabels : true , target : monaco . languages . typescript . ScriptTarget . ES5 , outDir : "built" , rootDir : "." , noLib : true , mouseWheelZoom : false } ) ; } }