veoflow 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/veoflow.mjs +1 -1
- package/dist/checkers.mjs +230 -2
- package/dist/veo.mjs +1413 -110
- package/native/binding.cjs +2 -0
- package/native/veo-extract.darwin-arm64.node +0 -0
- package/native/veo-extract.darwin-x64.node +0 -0
- package/native/veo-extract.linux-arm64-gnu.node +0 -0
- package/native/veo-extract.linux-x64-gnu.node +0 -0
- package/native/veo-extract.win32-x64-msvc.node +0 -0
- package/package.json +3 -2
- package/web/assets/{index-DLPLxvCf.js → index-C934gP-c.js} +11 -10
- package/web/assets/index-Dy4imygE.css +1 -0
- package/web/index.html +2 -2
- package/web/assets/index-Dsixf95A.css +0 -1
package/bin/veoflow.mjs
CHANGED
|
@@ -17,7 +17,7 @@ const here = dirname(fileURLToPath(import.meta.url));
|
|
|
17
17
|
process.env.VEO_CHECKERS_MODULE ??= pathToFileURL(join(here, "../dist/checkers.mjs")).href;
|
|
18
18
|
process.env.VEO_NATIVE_DIR ??= join(here, "../native");
|
|
19
19
|
process.env.VEO_WEB_ROOT ??= join(here, "../web");
|
|
20
|
-
process.env.VEO_VERSION = "0.
|
|
20
|
+
process.env.VEO_VERSION = "0.6.0";
|
|
21
21
|
const { main } = await import("../dist/veo.mjs");
|
|
22
22
|
const code = await main(process.argv.slice(2), {
|
|
23
23
|
out: (line) => process.stdout.write(line + "\n"),
|
package/dist/checkers.mjs
CHANGED
|
@@ -359,12 +359,30 @@ function adapterDef(files, call) {
|
|
|
359
359
|
if (callee.exact)
|
|
360
360
|
return defs.find((d) => d.span.start.line === callee.at.line && d.span.start.column === callee.at.column) ?? null;
|
|
361
361
|
if (callee.kind === "class" || call.form === "new") {
|
|
362
|
-
const names = call.form === "jsx" ? [`${callee.name}.render`, `${callee.name}.constructor`] :
|
|
362
|
+
const names = call.form === "jsx" ? [`${callee.name}.render`, `${callee.name}.constructor`] : (
|
|
363
|
+
// Python's constructor is `__init__` (#417).
|
|
364
|
+
[`${callee.name}.constructor`, `${callee.name}.__init__`]
|
|
365
|
+
);
|
|
363
366
|
for (const n of names) {
|
|
364
367
|
const d = defs.find((x) => x.qualifiedName === n || x.qualifiedName.endsWith(`.${n}`));
|
|
365
368
|
if (d) return d;
|
|
366
369
|
}
|
|
367
|
-
if (callee.kind === "class")
|
|
370
|
+
if (callee.kind === "class") {
|
|
371
|
+
const types = files.get(callee.file)?.types ?? [];
|
|
372
|
+
const seen = /* @__PURE__ */ new Set();
|
|
373
|
+
const up = (name) => {
|
|
374
|
+
if (seen.has(name)) return null;
|
|
375
|
+
seen.add(name);
|
|
376
|
+
for (const base of types.find((t) => t.name === name)?.bases ?? []) {
|
|
377
|
+
const d = defs.find((x) => x.qualifiedName === `${base.name}.__init__` && !x.implicit);
|
|
378
|
+
if (d) return d;
|
|
379
|
+
const further = up(base.name);
|
|
380
|
+
if (further) return further;
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
};
|
|
384
|
+
return up(callee.name);
|
|
385
|
+
}
|
|
368
386
|
}
|
|
369
387
|
const named = defs.filter((d) => d.name === callee.name);
|
|
370
388
|
const next = named.filter((d) => before(callee.at, d.span)).sort((a, b) => a.span.start.offset - b.span.start.offset)[0] ?? null;
|
|
@@ -571,6 +589,214 @@ function workspacePackages(root, manifests) {
|
|
|
571
589
|
}
|
|
572
590
|
return out;
|
|
573
591
|
}
|
|
592
|
+
|
|
593
|
+
// packages/checkers/src/python.ts
|
|
594
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
595
|
+
import { cpSync as cpSync2, existsSync as existsSync3, mkdirSync as mkdirSync2, mkdtempSync as mkdtempSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
596
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
597
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
598
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
599
|
+
var require3 = createRequire2(import.meta.url);
|
|
600
|
+
var CONFIG2 = ["pyproject.toml", "setup.cfg", "pyrightconfig.json"];
|
|
601
|
+
function indexPython(root, files) {
|
|
602
|
+
const main = require3.resolve("@sourcegraph/scip-python/index.js");
|
|
603
|
+
const work = mkdtempSync2(join3(tmpdir2(), "veo-scip-py-"));
|
|
604
|
+
try {
|
|
605
|
+
const copy = join3(work, "src");
|
|
606
|
+
for (const f of [...files, ...CONFIG2.filter((c) => existsSync3(join3(root, c)))]) {
|
|
607
|
+
mkdirSync2(dirname3(join3(copy, f)), { recursive: true });
|
|
608
|
+
cpSync2(join3(root, f), join3(copy, f));
|
|
609
|
+
}
|
|
610
|
+
writeFileSync2(join3(work, "env.json"), "[]");
|
|
611
|
+
const out = join3(work, "index.scip");
|
|
612
|
+
const r = spawnSync2(
|
|
613
|
+
process.execPath,
|
|
614
|
+
[
|
|
615
|
+
main,
|
|
616
|
+
"index",
|
|
617
|
+
"--project-name",
|
|
618
|
+
"veoflow-check",
|
|
619
|
+
"--project-version",
|
|
620
|
+
"0",
|
|
621
|
+
"--environment",
|
|
622
|
+
join3(work, "env.json"),
|
|
623
|
+
"--output",
|
|
624
|
+
out,
|
|
625
|
+
"src"
|
|
626
|
+
],
|
|
627
|
+
{
|
|
628
|
+
cwd: work,
|
|
629
|
+
encoding: "utf8",
|
|
630
|
+
maxBuffer: 1 << 26,
|
|
631
|
+
timeout: 30 * 60 * 1e3,
|
|
632
|
+
env: { PATH: dirname3(process.execPath), PYTHONSAFEPATH: "1", HOME: work }
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
if (r.status !== 0 || !existsSync3(out)) {
|
|
636
|
+
const lines = `${r.stderr ?? ""}
|
|
637
|
+
${r.stdout ?? ""}`.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
638
|
+
const error = lines.find((l) => /error|failure/i.test(l) && !l.startsWith("at ")) ?? lines.at(-1) ?? "";
|
|
639
|
+
throw new Error(`scip-python failed${r.error ? ` (${r.error.message})` : ""}: ${error}`);
|
|
640
|
+
}
|
|
641
|
+
return readIndex(out).map((d) => ({ ...d, path: d.path.replace(/^src\//, "") }));
|
|
642
|
+
} finally {
|
|
643
|
+
rmSync2(work, { recursive: true, force: true });
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
var Lines = class {
|
|
647
|
+
constructor(text) {
|
|
648
|
+
this.text = text;
|
|
649
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10) this.starts.push(i + 1);
|
|
650
|
+
}
|
|
651
|
+
text;
|
|
652
|
+
starts = [0];
|
|
653
|
+
/** A position from a 0-based line and UTF-16 column, as the adapter reports it (columns in characters). */
|
|
654
|
+
position(line0, char0) {
|
|
655
|
+
const start = this.starts[line0] ?? this.text.length;
|
|
656
|
+
return { line: line0 + 1, column: [...this.text.slice(start, start + char0)].length + 1 };
|
|
657
|
+
}
|
|
658
|
+
/** The 0-based line and UTF-16 column of a UTF-16 index. */
|
|
659
|
+
at(index) {
|
|
660
|
+
let lo = 0;
|
|
661
|
+
let hi = this.starts.length - 1;
|
|
662
|
+
while (lo < hi) {
|
|
663
|
+
const mid = lo + hi + 1 >> 1;
|
|
664
|
+
if (this.starts[mid] <= index) lo = mid;
|
|
665
|
+
else hi = mid - 1;
|
|
666
|
+
}
|
|
667
|
+
return { line: lo, char: index - this.starts[lo] };
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
var NAME = /([\p{L}_][\p{L}\p{N}_]*)\s*$/u;
|
|
671
|
+
function calleeName2(siteText, expression) {
|
|
672
|
+
let callee;
|
|
673
|
+
if (siteText.startsWith("@")) callee = siteText.slice(1);
|
|
674
|
+
else if (expression !== null && siteText.startsWith(expression)) callee = expression;
|
|
675
|
+
else {
|
|
676
|
+
let depth = 0;
|
|
677
|
+
let open = -1;
|
|
678
|
+
for (let i = 0; i < siteText.length; i++) {
|
|
679
|
+
const c = siteText[i];
|
|
680
|
+
if (c === "#") {
|
|
681
|
+
const nl = siteText.indexOf("\n", i);
|
|
682
|
+
i = nl < 0 ? siteText.length : nl;
|
|
683
|
+
} else if (c === "'" || c === '"') {
|
|
684
|
+
const triple = siteText.startsWith(c.repeat(3), i);
|
|
685
|
+
const q = triple ? c.repeat(3) : c;
|
|
686
|
+
let j = i + q.length;
|
|
687
|
+
while (j < siteText.length && !siteText.startsWith(q, j)) j += siteText[j] === "\\" ? 2 : 1;
|
|
688
|
+
i = j + q.length - 1;
|
|
689
|
+
} else if (c === "(" || c === "[" || c === "{") {
|
|
690
|
+
if (c === "(" && depth === 0) open = i;
|
|
691
|
+
depth++;
|
|
692
|
+
} else if (c === ")" || c === "]" || c === "}") depth--;
|
|
693
|
+
}
|
|
694
|
+
if (open < 0) return null;
|
|
695
|
+
callee = siteText.slice(0, open);
|
|
696
|
+
}
|
|
697
|
+
const m = NAME.exec(callee);
|
|
698
|
+
if (!m) return null;
|
|
699
|
+
const at = siteText.startsWith("@") ? 1 + m.index : m.index;
|
|
700
|
+
return { offset: at, name: m[1] };
|
|
701
|
+
}
|
|
702
|
+
function lastDescriptor(symbol) {
|
|
703
|
+
const m = /(?:`([^`]+)`|([\p{L}_][\p{L}\p{N}_]*))(#|\(\)\.)$/u.exec(symbol);
|
|
704
|
+
if (!m) return null;
|
|
705
|
+
return { name: m[1] ?? m[2], kind: m[3] === "#" ? "class" : "function" };
|
|
706
|
+
}
|
|
707
|
+
function translatePython(docs, adapter, texts) {
|
|
708
|
+
const byPath = new Map(docs.map((d) => [d.path, d]));
|
|
709
|
+
const lines = /* @__PURE__ */ new Map();
|
|
710
|
+
const linesOf = (path) => {
|
|
711
|
+
let l = lines.get(path);
|
|
712
|
+
if (!l) lines.set(path, l = new Lines(texts.get(path) ?? ""));
|
|
713
|
+
return l;
|
|
714
|
+
};
|
|
715
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
716
|
+
const keyOf = (path, symbol) => symbol.startsWith("local ") ? `${path}\0${symbol}` : symbol;
|
|
717
|
+
for (const d of docs) {
|
|
718
|
+
if (!texts.has(d.path)) continue;
|
|
719
|
+
for (const o of d.occurrences) {
|
|
720
|
+
const key = keyOf(d.path, o.symbol);
|
|
721
|
+
if (o.roles & DEFINITION && !definitions.has(key))
|
|
722
|
+
definitions.set(key, {
|
|
723
|
+
file: d.path,
|
|
724
|
+
at: linesOf(d.path).position(o.range[0], o.range[1]),
|
|
725
|
+
line0: o.range[0],
|
|
726
|
+
char0: o.range[1]
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const out = [];
|
|
731
|
+
for (const f of adapter) {
|
|
732
|
+
if (f.language !== "python") continue;
|
|
733
|
+
const text = texts.get(f.path);
|
|
734
|
+
const doc = byPath.get(f.path);
|
|
735
|
+
if (text === void 0 || !doc) continue;
|
|
736
|
+
const bytes = Buffer.from(text, "utf8");
|
|
737
|
+
const fileLines = linesOf(f.path);
|
|
738
|
+
let starts = null;
|
|
739
|
+
const indexOf = (offset) => {
|
|
740
|
+
if (bytes.length === text.length) return offset;
|
|
741
|
+
if (!starts) {
|
|
742
|
+
starts = [];
|
|
743
|
+
let b = 0;
|
|
744
|
+
for (let i = 0; i < text.length; i++) {
|
|
745
|
+
starts.push(b);
|
|
746
|
+
const c = text.charCodeAt(i);
|
|
747
|
+
b += c < 128 ? 1 : c < 2048 ? 2 : c >= 55296 && c <= 56319 ? 4 : c >= 56320 && c <= 57343 ? 0 : 3;
|
|
748
|
+
}
|
|
749
|
+
starts.push(b);
|
|
750
|
+
}
|
|
751
|
+
let lo = 0;
|
|
752
|
+
let hi = starts.length - 1;
|
|
753
|
+
while (lo < hi) {
|
|
754
|
+
const mid = lo + hi >> 1;
|
|
755
|
+
if (starts[mid] < offset) lo = mid + 1;
|
|
756
|
+
else hi = mid;
|
|
757
|
+
}
|
|
758
|
+
return lo;
|
|
759
|
+
};
|
|
760
|
+
const at = /* @__PURE__ */ new Map();
|
|
761
|
+
for (const o of doc.occurrences)
|
|
762
|
+
if (!(o.roles & DEFINITION)) at.set(`${o.range[0]}:${o.range[1]}`, o.symbol);
|
|
763
|
+
const sites = [
|
|
764
|
+
...f.calls.map((c) => ({
|
|
765
|
+
site: c.site,
|
|
766
|
+
expression: null,
|
|
767
|
+
form: c.form === "new" ? "new" : c.form === "super" ? "super" : c.form === "decorator" ? "decorator" : "call"
|
|
768
|
+
})),
|
|
769
|
+
...f.unresolved.map((u) => ({ site: u.site, expression: u.expression, form: "call" }))
|
|
770
|
+
];
|
|
771
|
+
for (const s of sites) {
|
|
772
|
+
const siteText = bytes.subarray(s.site.start.offset, s.site.end.offset).toString("utf8");
|
|
773
|
+
const name = calleeName2(siteText, s.expression);
|
|
774
|
+
if (!name) continue;
|
|
775
|
+
const before2 = indexOf(s.site.start.offset);
|
|
776
|
+
const { line, char } = fileLines.at(before2 + name.offset);
|
|
777
|
+
const symbol = at.get(`${line}:${char}`);
|
|
778
|
+
if (symbol === void 0) continue;
|
|
779
|
+
const def = definitions.get(keyOf(f.path, symbol));
|
|
780
|
+
const descriptor = lastDescriptor(symbol);
|
|
781
|
+
const lambda = symbol.startsWith("local ") && def !== void 0 && /^[\p{L}_][\p{L}\p{N}_]*\s*=\s*lambda\b/u.test(
|
|
782
|
+
(texts.get(def.file) ?? "").slice(linesOf(def.file).starts[def.line0] + def.char0)
|
|
783
|
+
);
|
|
784
|
+
out.push({
|
|
785
|
+
file: f.path,
|
|
786
|
+
site: s.site,
|
|
787
|
+
form: s.form,
|
|
788
|
+
callee: def && (descriptor || lambda) ? {
|
|
789
|
+
file: def.file,
|
|
790
|
+
name: descriptor?.name ?? name.name,
|
|
791
|
+
at: def.at,
|
|
792
|
+
kind: descriptor?.kind ?? "function"
|
|
793
|
+
} : null,
|
|
794
|
+
symbol
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return out;
|
|
799
|
+
}
|
|
574
800
|
export {
|
|
575
801
|
DEFINITION,
|
|
576
802
|
DISAGREEMENTS,
|
|
@@ -581,8 +807,10 @@ export {
|
|
|
581
807
|
compareImports,
|
|
582
808
|
formatReport,
|
|
583
809
|
indexFolder,
|
|
810
|
+
indexPython,
|
|
584
811
|
readIndex,
|
|
585
812
|
resolveWithCompiler,
|
|
586
813
|
translate,
|
|
814
|
+
translatePython,
|
|
587
815
|
workspacePackages
|
|
588
816
|
};
|