MCPcopy Index your code
hub / github.com/pomber/code-surfer / parseSteps

Function parseSteps

packs/step-parser/src/step-parser.ts:7–109  ·  view source on GitHub ↗
(
  inputSteps: {
    code: string;
    focus?: string;
    lang?: string;
    title?: string;
    subtitle?: string;
    showNumbers?: boolean;
  }[]
)

Source from the content-addressed store, hash-verified

5import { applyPatch } from "diff";
6
7export function parseSteps(
8 inputSteps: {
9 code: string;
10 focus?: string;
11 lang?: string;
12 title?: string;
13 subtitle?: string;
14 showNumbers?: boolean;
15 }[]
16) {
17 if (inputSteps.length === 0) {
18 return {
19 tokens: [],
20 types: [],
21 steps: []
22 };
23 }
24
25 const { lang, showNumbers = false } = inputSteps[0];
26
27 if (!lang) {
28 throw new Error("Missing code language");
29 }
30
31 const codeList = getCodeList(inputSteps);
32
33 const { lineIds, steps } = linesDiff(codeList);
34 const allTokens: string[][] = [];
35 const allTypes: string[][] = [];
36 const allSteps: {
37 lines: number[];
38 focus: Record<number, true | number[]>;
39 focusCenter: number;
40 focusCount: number;
41 longestLineIndex: number;
42 title?: string;
43 subtitle?: string;
44 }[] = [];
45
46 steps.forEach((step, i) => {
47 const code = codeList[i];
48 const { tokens, types } = tokenize(code, lang);
49 const lineKeys: number[] = [];
50 step.forEach((lineId, lineIndex) => {
51 const lineKey = lineIds.indexOf(lineId);
52 allTokens[lineKey] = tokens[lineIndex];
53 allTypes[lineKey] = types[lineIndex];
54 lineKeys.push(lineKey);
55 });
56
57 const focusString = inputSteps[i].focus;
58 const prevLineKeys = allSteps[i - 1] ? allSteps[i - 1].lines : [];
59 const focus = focusString
60 ? parseFocus(focusString)
61 : getDefaultFocus(prevLineKeys, lineKeys);
62 const { focusCenter, focusCount } = getFocusSize(focus);
63 allSteps.push({
64 lines: lineKeys,

Callers 2

InnerCodeSurferFunction · 0.90

Calls 9

linesDiffFunction · 0.90
tokenizeFunction · 0.90
parseFocusFunction · 0.90
getFocusSizeFunction · 0.90
toEntriesFunction · 0.90
getCodeListFunction · 0.85
getDefaultFocusFunction · 0.85
getLongestLineIndexFunction · 0.85
splitIntoColumnsFunction · 0.85

Tested by

no test coverage detected