MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / tomlPathList

Function tomlPathList

src/resolution/import-resolver.ts:958–998  ·  view source on GitHub ↗

* The strings of the TOML value of `key` in a table body: the items of an * array, which may run over lines with comments and a trailing comma, or, * where `splitString` says a plain string is a space-separated list (pytest's * `ini_options`, kept in the form of the INI file they replace), its wo

(body: string, key: 'pythonpath' | 'extraPaths', splitString: boolean)

Source from the content-addressed store, hash-verified

956 * `ini_options`, kept in the form of the INI file they replace), its words.
957 */
958function tomlPathList(body: string, key: 'pythonpath' | 'extraPaths', splitString: boolean): string[] {
959 const at = TOML_PATH_KEYS[key].exec(body);
960 if (!at) return [];
961 let i = at.index + at[0].length;
962 /** The string that starts at `i`, leaving `i` past it; null where there is none on that line. */
963 const string = (): string | null => {
964 const quote = body[i];
965 if ((quote !== '"' && quote !== "'") || body.startsWith(quote.repeat(3), i)) return null;
966 let value = '';
967 for (i++; i < body.length; i++) {
968 const ch = body[i]!;
969 if (ch === quote) {
970 i++;
971 return value;
972 }
973 if (ch === '\n' || ch === '\r') return null;
974 // A basic string escapes a backslash or a quote; a literal one escapes nothing.
975 value += ch === '\\' && quote === '"' ? body[++i] ?? '' : ch;
976 }
977 return null;
978 };
979 if (body[i] !== '[') {
980 const one = splitString ? string() : null;
981 return one === null ? [] : one.split(/\s+/).filter(Boolean);
982 }
983 const out: string[] = [];
984 for (i++; i < body.length && body[i] !== ']'; ) {
985 const ch = body[i]!;
986 if (ch === '#') {
987 while (i < body.length && body[i] !== '\n') i++;
988 } else if (ch === ',' || ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
989 i++;
990 } else {
991 const item = string();
992 // Anything else is no path list: keep what was read.
993 if (item === null) break;
994 out.push(item);
995 }
996 }
997 return out;
998}
999
1000/**
1001 * The paths of the INI value of `pythonpath` in a section body, as pytest

Callers 2

tomlFunction · 0.85
pyrightExtraPathsFunction · 0.85

Calls 3

stringFunction · 0.85
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected