Add WASM fallbacks for tree-sitter and SQLite, fix installer
Replace native tree-sitter with web-tree-sitter + tree-sitter-wasms for universal cross-platform support. Add node-sqlite3-wasm as a fallback when better-sqlite3 native bindings aren't available. Move better-sqlite3 and sqlite-vss to optionalDependencies so installs never fail. Fix installer to use npx fallback when global npm install fails, so MCP config, hooks, and quick-start instructions all work without the bare codegraph command in PATH. Fix tests: update schema version expectation, fix db test paths and method names, extract MAX_OUTPUT_LENGTH as module constant, normalize Windows path separators in import resolver.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Handles parsing source code and extracting structural information.
|
||||
*/
|
||||
|
||||
import { SyntaxNode, Tree } from 'tree-sitter';
|
||||
import { Node as SyntaxNode, Tree } from 'web-tree-sitter';
|
||||
import * as crypto from 'crypto';
|
||||
import * as path from 'path';
|
||||
import {
|
||||
@@ -875,7 +875,10 @@ export class TreeSitterExtractor {
|
||||
}
|
||||
|
||||
try {
|
||||
this.tree = parser.parse(this.source);
|
||||
this.tree = parser.parse(this.source) ?? null;
|
||||
if (!this.tree) {
|
||||
throw new Error('Parser returned null tree');
|
||||
}
|
||||
|
||||
// Create file node representing the source file
|
||||
const fileNode: Node = {
|
||||
@@ -1710,9 +1713,15 @@ export class TreeSitterExtractor {
|
||||
if (namespacePrefix && useGroup) {
|
||||
// Grouped import - create one import per item
|
||||
const prefix = getNodeText(namespacePrefix, this.source);
|
||||
const useClauses = useGroup.namedChildren.filter((c: SyntaxNode) => c.type === 'namespace_use_clause');
|
||||
const useClauses = useGroup.namedChildren.filter((c: SyntaxNode) =>
|
||||
c.type === 'namespace_use_group_clause' || c.type === 'namespace_use_clause'
|
||||
);
|
||||
for (const clause of useClauses) {
|
||||
const name = clause.namedChildren.find((c: SyntaxNode) => c.type === 'name');
|
||||
// WASM grammar wraps names in namespace_name; native uses name directly
|
||||
const nsName = clause.namedChildren.find((c: SyntaxNode) => c.type === 'namespace_name');
|
||||
const name = nsName
|
||||
? nsName.namedChildren.find((c: SyntaxNode) => c.type === 'name')
|
||||
: clause.namedChildren.find((c: SyntaxNode) => c.type === 'name');
|
||||
if (name) {
|
||||
const fullPath = `${prefix}\\${getNodeText(name, this.source)}`;
|
||||
this.createNode('import', fullPath, node, {
|
||||
|
||||
Reference in New Issue
Block a user