Discover how the codebase feature transforms your repository into a searchable, context-aware knowledge base to boost developer productivity and ease onboarding.
Discover how the codebase feature transforms your repository into a searchable, context-aware knowledge base. By querying your entire project structure, you can quickly locate configuration blocks, data-processing routines, and CLI commands—boosting developer productivity and easing onboarding.
Below is a sample Flask application (app.py) that we’ll use to demonstrate codebase queries:
Copy
# app.pyimport csvimport sqlite3import osimport hashlibimport loggingfrom datetime import datetimefrom flask import Flask, render_template, request, redirect, url_for, flash, session, g# Initialize Flask appapp = Flask(__name__)app.config['SECRET_KEY'] = 'dev' # Change this to a random secret key in productionapp.config['DATABASE'] = os.path.join(app.instance_path, 'task_manager.sqlite')# Ensure the instance folder existstry: os.makedirs(app.instance_path)except OSError: passdef read_csv(file_path): """Read rows from a CSV file and print them.""" with open(file_path, 'r') as f: csvreader = csv.reader(f) for row in csvreader: print(row)# Database connection functionsdef get_db(): """Return a database connection, creating it if necessary.""" if 'db' not in g: g.db = sqlite3.connect( app.config['DATABASE'], detect_types=sqlite3.PARSE_DECLTYPES ) g.db.row_factory = sqlite3.Row return g.dbdef close_db(e=None): """Close the database connection at teardown.""" db = g.pop('db', None) if db is not None: db.close()app.teardown_appcontext(close_db)# Initialize the database using a schema filedef init_db(): db = get_db() with app.open_resource('schema.sql') as f: db.executescript(f.read().decode('utf8')) print('Initialized the database.')@app.cli.command('init-db')def init_db_command(): """Clear existing data and create new tables.""" init_db() print('Initialized the database.')
Be sure to replace app.config['SECRET_KEY'] with a secure, random value before deploying to production.
Ask: “Show me all the code used to connect to the database.”
Copy
def get_db(): """Return a database connection, creating it if necessary.""" if 'db' not in g: g.db = sqlite3.connect( app.config['DATABASE'], detect_types=sqlite3.PARSE_DECLTYPES ) g.db.row_factory = sqlite3.Row return g.db
Ask: “Which parts of the code deal with CSV files?”
Copy
def read_csv(file_path): """Read rows from a CSV file and print them.""" with open(file_path, 'r') as f: csvreader = csv.reader(f) for row in csvreader: print(row)
Simplify refactoring by searching specific patterns
Combine multiple filters and search terms to focus on specific modules or code patterns across your project.
Whether you’re migrating from SQLite to PostgreSQL, integrating an ORM like SQLAlchemy, or diving into an unfamiliar codebase, the codebase feature provides instant, context-aware insights into your entire repository.