MCPcopy
hub / github.com/witheve/Eve / initIDE

Function initIDE

src/client.ts:456–498  ·  view source on GitHub ↗
(client:EveClient)

Source from the content-addressed store, hash-verified

454export let client = new EveClient();
455
456function initIDE(client:EveClient) {
457 let ide = client.ide;
458 ide.onChange = (ide:IDE) => {
459 let generation = ide.generation;
460 let md = ide.editor.toMarkdown();
461 console.groupCollapsed(`SENT ${generation}`);
462 console.info(md);
463 console.groupEnd();
464 client.send({scope: "root", type: "parse", generation, code: md, documentId: ide.documentId});
465 }
466 ide.onEval = (ide:IDE, persist) => {
467 client.send({type: "eval", persist, documentId: ide.documentId});
468 }
469 ide.onLoadFile = (ide, documentId, code) => {
470 client.send({type: "close"});
471 client.send({scope: "root", type: "parse", code, documentId: ide.documentId})
472 client.send({type: "eval", persist: false, documentId: ide.documentId});
473
474 let url = `${location.pathname}#${documentId}`;
475 let currentHashChunks = location.hash.split("#").slice(1);
476 let curId = currentHashChunks[0];
477 if(curId && curId[curId.length - 1] === "/") curId = curId.slice(0, -1);
478 if(curId === documentId && currentHashChunks[1]) {
479 url += "/#" + currentHashChunks[1];
480 }
481
482 history.pushState({}, "", url + location.search);
483 analyticsEvent("load-document", documentId);
484 }
485
486 ide.onSaveDocument = (ide, documentId, code) => {
487 client.save(documentId, code);
488 }
489
490 ide.onTokenInfo = (ide, tokenId) => {
491 client.send({type: "tokenInfo", tokenId});
492 }
493
494 let cache = window["_workspaceCache"];
495 for(let workspace in cache || {}) {
496 ide.loadWorkspace(workspace, cache[workspace]);
497 }
498}
499
500function changeDocument() {
501 if(!client.showIDE) return;

Callers 1

_initProgramMethod · 0.85

Calls 5

analyticsEventFunction · 0.85
toMarkdownMethod · 0.80
sendMethod · 0.65
saveMethod · 0.65
loadWorkspaceMethod · 0.45

Tested by

no test coverage detected