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

Method injectSpans

src/ide.ts:902–949  ·  view source on GitHub ↗
(packed:any[], attributes:{[id:string]: any|undefined})

Source from the content-addressed store, hash-verified

900
901 // This is an update to an existing document, so we need to figure out what got added and removed.
902 injectSpans(packed:any[], attributes:{[id:string]: any|undefined}) {
903 if(packed.length % 4 !== 0) throw new Error("Invalid span packing, unable to load.");
904
905 this.cm.operation(() => {
906 this.reloading = true;
907 let doc = this.cm.getDoc();
908
909 let controlledOffsets = {};
910 let touchedIds = {};
911 for(let i = 0; i < packed.length; i += 4) {
912 if(isEditorControlled(packed[i + 2]))
913 console.info(packed[i + 2], debugTokenWithContext(doc.getValue(), packed[i], packed[i + 1]));
914
915 let start = packed[i];
916 let type = packed[i + 2];
917 if(isEditorControlled(type)) {
918 throw new Error(`The parser may not inject editor controlled spans of type '${type}'`);
919 } else {
920 let from = doc.posFromIndex(packed[i]);
921 let to = doc.posFromIndex(packed[i + 1]);
922 let type = packed[i + 2];
923 let id = packed[i + 3];
924
925 let source = attributes[id] || {};
926 source.type = type;
927 source.id = id;
928
929 let spans = this.findSpansAt(from, type);
930 let unchanged = false;
931 for(let span of spans) {
932 let loc = span.find();
933 if(loc && samePosition(to, loc.to) && span.sourceEquals(source)) {
934 span.source = source;
935 if(span.refresh) span.refresh();
936 unchanged = true;
937 break;
938 }
939 }
940
941 if(!unchanged) {
942 let span = this.markSpan(from, to, source);
943 }
944 }
945 }
946 });
947
948 this.reloading = false;
949 }
950
951 toMarkdown() {
952 if(this._md) return this._md;

Callers

nothing calls this directly

Calls 12

findSpansAtMethod · 0.95
markSpanMethod · 0.95
isEditorControlledFunction · 0.90
samePositionFunction · 0.90
debugTokenWithContextFunction · 0.85
operationMethod · 0.80
getDocMethod · 0.80
posFromIndexMethod · 0.80
sourceEqualsMethod · 0.80
getValueMethod · 0.65
findMethod · 0.65
refreshMethod · 0.65

Tested by

no test coverage detected