Enhances code extraction and project indexing
Adds support for Dart and Liquid languages with tree-sitter parsing. Improves accuracy of code symbol extraction for existing languages. Indexes project files to enhance code navigation features. Migrates build system to facilitate code contributions. Removes git hook functionality. Integrates Sentry for error tracking and reporting. Enhances project initialization and configuration loading.
This commit is contained in:
+49
-7
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Directory Management
|
||||
*
|
||||
* Manages the .codegraph/ directory structure.
|
||||
* Manages the .codegraph/ directory structure for CodeGraph data.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
@@ -21,28 +21,69 @@ export function getCodeGraphDir(projectRoot: string): string {
|
||||
|
||||
/**
|
||||
* Check if a project has been initialized with CodeGraph
|
||||
* Requires both .codegraph/ directory AND codegraph.db to exist
|
||||
*/
|
||||
export function isInitialized(projectRoot: string): boolean {
|
||||
const codegraphDir = getCodeGraphDir(projectRoot);
|
||||
return fs.existsSync(codegraphDir) && fs.statSync(codegraphDir).isDirectory();
|
||||
if (!fs.existsSync(codegraphDir) || !fs.statSync(codegraphDir).isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
// Must have codegraph.db, not just .codegraph folder
|
||||
const dbPath = path.join(codegraphDir, 'codegraph.db');
|
||||
return fs.existsSync(dbPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the nearest parent directory containing .codegraph/
|
||||
*
|
||||
* Walks up from the given path to find a CodeGraph-initialized project,
|
||||
* similar to how git finds .git/ directories.
|
||||
*
|
||||
* @param startPath - Directory to start searching from
|
||||
* @returns The project root containing .codegraph/, or null if not found
|
||||
*/
|
||||
export function findNearestCodeGraphRoot(startPath: string): string | null {
|
||||
let current = path.resolve(startPath);
|
||||
const root = path.parse(current).root;
|
||||
|
||||
while (current !== root) {
|
||||
if (isInitialized(current)) {
|
||||
return current;
|
||||
}
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) break; // Reached filesystem root
|
||||
current = parent;
|
||||
}
|
||||
|
||||
// Check root as well
|
||||
if (isInitialized(current)) {
|
||||
return current;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the .codegraph directory structure
|
||||
* Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
|
||||
*/
|
||||
export function createDirectory(projectRoot: string): void {
|
||||
const codegraphDir = getCodeGraphDir(projectRoot);
|
||||
const dbPath = path.join(codegraphDir, 'codegraph.db');
|
||||
|
||||
if (fs.existsSync(codegraphDir)) {
|
||||
// Only throw if CodeGraph is actually initialized (db exists)
|
||||
// .codegraph/ folder alone is fine
|
||||
if (fs.existsSync(dbPath)) {
|
||||
throw new Error(`CodeGraph already initialized in ${projectRoot}`);
|
||||
}
|
||||
|
||||
// Create main directory
|
||||
// Create main directory (if it doesn't exist)
|
||||
fs.mkdirSync(codegraphDir, { recursive: true });
|
||||
|
||||
// Create .gitignore inside .codegraph
|
||||
// Create .gitignore inside .codegraph (if it doesn't exist)
|
||||
const gitignorePath = path.join(codegraphDir, '.gitignore');
|
||||
const gitignoreContent = `# CodeGraph data files
|
||||
if (!fs.existsSync(gitignorePath)) {
|
||||
const gitignoreContent = `# CodeGraph data files
|
||||
# These are local to each machine and should not be committed
|
||||
|
||||
# Database
|
||||
@@ -57,7 +98,8 @@ cache/
|
||||
*.log
|
||||
`;
|
||||
|
||||
fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
|
||||
fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user