@jefuriiij/synthra 0.1.10 → 0.1.12

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.
@@ -485,7 +485,7 @@ function extractKeywords(content, _ext) {
485
485
  }
486
486
 
487
487
  // src/scanner/extract.ts
488
- var RESOLVE_EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".svelte", ".vue"];
488
+ var RESOLVE_EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".svelte", ".vue", ".dart"];
489
489
  var INDEX_FILES = ["index.ts", "index.tsx", "index.js", "index.jsx", "__init__.py"];
490
490
  function fileId(relPath) {
491
491
  return `file:${relPath}`;
@@ -625,9 +625,10 @@ function buildSymbolIndex(graph) {
625
625
  // src/scanner/parser.ts
626
626
  import { readFile as readFile3 } from "fs/promises";
627
627
  import { createRequire } from "module";
628
- import Parser from "web-tree-sitter";
628
+ import { Language, Parser } from "web-tree-sitter";
629
629
 
630
630
  // src/scanner/parsers/_generic.ts
631
+ import { Query } from "web-tree-sitter";
631
632
  function firstLine(text, max = 200) {
632
633
  const line = text.split(/\r?\n/, 1)[0] ?? "";
633
634
  return line.length > max ? line.slice(0, max) + "\u2026" : line;
@@ -642,7 +643,7 @@ async function runGenericParser(config, f, source) {
642
643
  const { parser, language } = await createParser(config.grammar);
643
644
  const tree = parser.parse(source);
644
645
  if (!tree) return { file: f, source, symbols, imports, calls: [] };
645
- const query = language.query(config.query);
646
+ const query = new Query(language, config.query);
646
647
  const matches = query.matches(tree.rootNode);
647
648
  for (const match of matches) {
648
649
  const byName = /* @__PURE__ */ new Map();
@@ -773,27 +774,95 @@ async function parseCSharp(f, source) {
773
774
  }
774
775
 
775
776
  // src/scanner/parsers/dart.ts
777
+ import { Query as Query2 } from "web-tree-sitter";
776
778
  var QUERY4 = `
777
- (class_definition (identifier) @class.name) @class
778
- (mixin_declaration (identifier) @class.name) @mixin
779
- (extension_declaration (identifier) @class.name) @ext
780
- (function_signature (identifier) @function.name) @function
779
+ (class_definition name: (identifier) @class.name) @class
780
+ (mixin_declaration (identifier) @mixin.name) @mixin
781
+ (extension_declaration name: (identifier) @ext.name) @ext
782
+ (enum_declaration name: (identifier) @enum.name) @enum
783
+ (type_alias (type_identifier) @typedef.name) @typedef
784
+
785
+ (program (function_signature name: (identifier) @function.name) @function)
786
+
787
+ (method_signature (function_signature name: (identifier) @method.name)) @method
788
+ (method_signature (getter_signature name: (identifier) @getter.name)) @getter
789
+ (method_signature (setter_signature name: (identifier) @setter.name)) @setter
790
+ (constructor_signature name: (identifier) @ctor.name) @ctor
791
+
792
+ (import_or_export (library_import (import_specification (configurable_uri (uri (string_literal) @import)))))
781
793
  `;
794
+ var DECLS = [
795
+ { declCap: "class", nameCap: "class.name", kind: "class" },
796
+ { declCap: "mixin", nameCap: "mixin.name", kind: "class" },
797
+ { declCap: "ext", nameCap: "ext.name", kind: "class" },
798
+ { declCap: "enum", nameCap: "enum.name", kind: "enum" },
799
+ { declCap: "typedef", nameCap: "typedef.name", kind: "type" },
800
+ { declCap: "function", nameCap: "function.name", kind: "function" },
801
+ { declCap: "method", nameCap: "method.name", kind: "method" },
802
+ { declCap: "getter", nameCap: "getter.name", kind: "method" },
803
+ { declCap: "setter", nameCap: "setter.name", kind: "method" },
804
+ { declCap: "ctor", nameCap: "ctor.name", kind: "method" }
805
+ ];
806
+ function firstLine2(text, max = 200) {
807
+ const line = text.split(/\r?\n/, 1)[0] ?? "";
808
+ return line.length > max ? line.slice(0, max) + "\u2026" : line;
809
+ }
810
+ function normalizeDartImport(raw) {
811
+ const stripped = raw.replace(/^['"]|['"]$/g, "");
812
+ if (!stripped) return null;
813
+ if (stripped.startsWith("package:")) return null;
814
+ if (stripped.startsWith("dart:")) return null;
815
+ if (stripped.startsWith(".") || stripped.startsWith("/")) return stripped;
816
+ return `./${stripped}`;
817
+ }
782
818
  async function parseDart(f, source) {
783
- return runGenericParser(
784
- {
785
- grammar: "dart",
786
- query: QUERY4,
787
- decls: [
788
- { declCapture: "class", nameCapture: "class.name", kind: "class" },
789
- { declCapture: "mixin", nameCapture: "class.name", kind: "class" },
790
- { declCapture: "ext", nameCapture: "class.name", kind: "class" },
791
- { declCapture: "function", nameCapture: "function.name", kind: "function" }
792
- ]
793
- },
794
- f,
795
- source
796
- );
819
+ let symbols = [];
820
+ let imports = [];
821
+ try {
822
+ const { parser, language } = await createParser("dart");
823
+ const tree = parser.parse(source);
824
+ if (!tree) return { file: f, source, symbols, imports, calls: [] };
825
+ const query = new Query2(language, QUERY4);
826
+ const matches = query.matches(tree.rootNode);
827
+ for (const match of matches) {
828
+ const byName = /* @__PURE__ */ new Map();
829
+ for (const cap of match.captures) byName.set(cap.name, cap.node);
830
+ let matched = null;
831
+ for (const d of DECLS) {
832
+ if (byName.has(d.declCap) && byName.has(d.nameCap)) {
833
+ matched = d;
834
+ break;
835
+ }
836
+ }
837
+ if (matched) {
838
+ const declNode = byName.get(matched.declCap);
839
+ const nameNode = byName.get(matched.nameCap);
840
+ symbols.push({
841
+ name: nameNode.text,
842
+ kind: matched.kind,
843
+ startLine: declNode.startPosition.row + 1,
844
+ endLine: declNode.endPosition.row + 1,
845
+ signature: firstLine2(declNode.text)
846
+ });
847
+ continue;
848
+ }
849
+ const importNode = byName.get("import");
850
+ if (importNode) {
851
+ const norm = normalizeDartImport(importNode.text);
852
+ if (norm) imports.push(norm);
853
+ }
854
+ }
855
+ const seen = /* @__PURE__ */ new Set();
856
+ symbols = symbols.filter((s) => {
857
+ const k = `${s.name}:${s.startLine}`;
858
+ if (seen.has(k)) return false;
859
+ seen.add(k);
860
+ return true;
861
+ });
862
+ imports = Array.from(new Set(imports));
863
+ } catch {
864
+ }
865
+ return { file: f, source, symbols, imports, calls: [] };
797
866
  }
798
867
 
799
868
  // src/scanner/parsers/go.ts
@@ -897,6 +966,7 @@ async function parsePhp(f, source) {
897
966
  }
898
967
 
899
968
  // src/scanner/parsers/python.ts
969
+ import { Query as Query3 } from "web-tree-sitter";
900
970
  var QUERY9 = `
901
971
  (function_definition name: (identifier) @function.name) @function
902
972
  (class_definition name: (identifier) @class.name) @class
@@ -904,7 +974,7 @@ var QUERY9 = `
904
974
  (import_from_statement module_name: (dotted_name) @import.from)
905
975
  (import_from_statement module_name: (relative_import) @import.from)
906
976
  `;
907
- function firstLine2(text, max = 200) {
977
+ function firstLine3(text, max = 200) {
908
978
  const line = text.split(/\r?\n/, 1)[0] ?? "";
909
979
  return line.length > max ? line.slice(0, max) + "\u2026" : line;
910
980
  }
@@ -915,7 +985,7 @@ async function parsePython(f, source) {
915
985
  const { parser, language } = await createParser("python");
916
986
  const tree = parser.parse(source);
917
987
  if (!tree) return { file: f, source, symbols, imports, calls: [] };
918
- const query = language.query(QUERY9);
988
+ const query = new Query3(language, QUERY9);
919
989
  const matches = query.matches(tree.rootNode);
920
990
  for (const match of matches) {
921
991
  const byName = /* @__PURE__ */ new Map();
@@ -930,7 +1000,7 @@ async function parsePython(f, source) {
930
1000
  kind: isMethod ? "method" : "function",
931
1001
  startLine: funcDecl.startPosition.row + 1,
932
1002
  endLine: funcDecl.endPosition.row + 1,
933
- signature: firstLine2(funcDecl.text)
1003
+ signature: firstLine3(funcDecl.text)
934
1004
  });
935
1005
  continue;
936
1006
  }
@@ -942,7 +1012,7 @@ async function parsePython(f, source) {
942
1012
  kind: "class",
943
1013
  startLine: classDecl.startPosition.row + 1,
944
1014
  endLine: classDecl.endPosition.row + 1,
945
- signature: firstLine2(classDecl.text)
1015
+ signature: firstLine3(classDecl.text)
946
1016
  });
947
1017
  continue;
948
1018
  }
@@ -1013,6 +1083,7 @@ async function parseRust(f, source) {
1013
1083
  }
1014
1084
 
1015
1085
  // src/scanner/parsers/typescript.ts
1086
+ import { Query as Query4 } from "web-tree-sitter";
1016
1087
  var TS_QUERY = `
1017
1088
  (function_declaration name: (identifier) @function.name) @function
1018
1089
  (class_declaration name: (type_identifier) @class.name) @class
@@ -1042,7 +1113,7 @@ function queryFor(grammar) {
1042
1113
  function unquote(s) {
1043
1114
  return s.replace(/^["'`]|["'`]$/g, "");
1044
1115
  }
1045
- function firstLine3(text, max = 200) {
1116
+ function firstLine4(text, max = 200) {
1046
1117
  const line = text.split(/\r?\n/, 1)[0] ?? "";
1047
1118
  return line.length > max ? line.slice(0, max) + "\u2026" : line;
1048
1119
  }
@@ -1062,7 +1133,7 @@ async function parseTypeScript(f, source) {
1062
1133
  const { parser, language } = await createParser(grammar);
1063
1134
  const tree = parser.parse(source);
1064
1135
  if (!tree) return { file: f, source, symbols, imports, calls: [] };
1065
- const query = language.query(queryFor(grammar));
1136
+ const query = new Query4(language, queryFor(grammar));
1066
1137
  const matches = query.matches(tree.rootNode);
1067
1138
  for (const match of matches) {
1068
1139
  const byName = /* @__PURE__ */ new Map();
@@ -1074,7 +1145,7 @@ async function parseTypeScript(f, source) {
1074
1145
  kind: shape.kind,
1075
1146
  startLine: shape.decl.startPosition.row + 1,
1076
1147
  endLine: shape.decl.endPosition.row + 1,
1077
- signature: firstLine3(shape.decl.text)
1148
+ signature: firstLine4(shape.decl.text)
1078
1149
  });
1079
1150
  continue;
1080
1151
  }
@@ -1219,7 +1290,7 @@ async function loadGrammar(name) {
1219
1290
  const cached = languageCache.get(name);
1220
1291
  if (cached) return cached;
1221
1292
  const wasmPath = require2.resolve(GRAMMAR_FILES[name]);
1222
- const lang = await Parser.Language.load(wasmPath);
1293
+ const lang = await Language.load(wasmPath);
1223
1294
  languageCache.set(name, lang);
1224
1295
  return lang;
1225
1296
  }