| Crates.io | code-search-cli |
| lib.rs | code-search-cli |
| version | 0.3.3 |
| created_at | 2025-11-30 05:34:49.642252+00 |
| updated_at | 2025-12-13 06:45:35.109248+00 |
| description | Intelligent code search tool for tracing text (UI text, function names, variables) to implementation code |
| homepage | |
| repository | https://github.com/weima/code-search |
| max_upload_size | |
| id | 1957905 |
| size | 3,825,494 |
Intelligent code search tool for tracing text to implementation code
Modern IDEs like JetBrains suite provide powerful code navigation features through context menus - find definition, find references, etc. However, these IDEs are resource-intensive and not always practical for quick searches or lightweight environments.
Developers frequently need to search for text in their codebase, whether it's:
processPayment call?"userId used?"For UI text specifically, the search is even more complex when i18n is involved:
rg 'add new' -Fen.yml)add_new: 'add new'invoice.labels.add_newrg 'invoice.labels.add_new' -Fcomponents/invoices.tsThis manual process is time-consuming, error-prone, and interrupts the development flow.
code-search (abbreviated as cs) is a lightweight CLI tool that automates code discovery workflows:
$ cs 'add new'
'add new'
|
|-> 'add_new: add new' at line 56 of en.yml
|
|-> 'invoice.labels.add_new' as the structure
|
|-> I18n.t('invoice.labels.add_new') at line 128 of components/invoices.ts
Trace function calls forward (what does this function call?) or backward (who calls this function?):
# Forward trace - what does bar() call?
$ cs 'bar' --trace
bar
|-> zoo1 (utils.ts:45)
|-> zoo2 (helpers.ts:23)
|-> zoo3 (api.ts:89)
# Backward trace - who calls bar()?
$ cs 'bar' --traceback
blah1 -> foo1 -> bar
blah2 -> foo2 -> bar
# Control trace depth (default: 3, max: 10)
$ cs 'bar' --trace --depth 5
t('invoice.add')) and traces them back to their definition in YAML files.I18n.t('key'), t('key')i18n.t('key'), $t('key'), t('key')useTranslation(), <Trans>$t('key'), {{ $t('key') }}By default, the tool recognizes common code file extensions (.ts, .tsx, .js, .jsx, .vue, .rb, .py, .java, .php, .rs, .go, .cpp, .c, .cs, .kt, .swift).
For projects with custom file extensions, use the --include-extensions flag:
# Include files with custom extensions
cs "search text" --include-extensions html.ui,vue.custom
# Multiple extensions (comma-separated)
cs "search text" --include-extensions erb.rails,blade.php,twig.html
# Extensions with or without leading dot work the same
cs "search text" --include-extensions .html.ui,.vue.custom
This is particularly useful for:
.html.ui for UI frameworks).erb.rails, .blade.php).vue.custom, .component.ts)The tool automatically finds common i18n patterns where developers cache namespaces:
// Common pattern: Cache namespace to avoid repetition
const labels = I18n.t('invoice.labels');
const addButton = labels.t('add_new');
const editButton = labels.t('edit');
// Deeper namespace caching
const invoiceNS = I18n.t('invoice');
const addLabel = invoiceNS.labels.t('add_new');
When searching for "add new", the tool finds:
invoice.labels.add_new: "add new"I18n.t('invoice.labels') (parent namespace)labels.t('add_new') (child key)This works by generating strategic partial keys:
invoice.labels.add_newlabels.add_new (matches labels.t('add_new'))invoice.labels (matches I18n.t('invoice.labels'))# Basic i18n search
$ cs "add new"
=== Translation Files ===
config/locales/en.yml:4:invoice.labels.add_new: "add new"
=== Code References ===
app/components/invoices.ts:14:I18n.t('invoice.labels.add_new')
components/InvoiceManager.vue:3:{{ $t('invoice.labels.add_new') }}
# Include custom file types
$ cs "add new" --include-extensions html.ui,erb.rails
=== Translation Files ===
config/locales/en.yml:4:invoice.labels.add_new: "add new"
=== Code References ===
app/components/invoices.ts:14:I18n.t('invoice.labels.add_new')
components/InvoiceManager.vue:3:{{ $t('invoice.labels.add_new') }}
templates/invoice.html.ui:23:i18n('invoice.labels.add_new')
views/invoice.erb.rails:45:<%= t('invoice.labels.add_new') %>
--trace)--traceback)Built on a foundation of proven tools:
Typical search performance on real-world projects:
Optimizations:
Benchmarked on real-world codebases including Discourse open-source project (389 YAML files, ~50MB total).
The codebase includes a sophisticated bottom-up parsing optimization for YAML/JSON translation files:
Status: Fully implemented with comprehensive tests, temporarily disabled while debugging a key path construction issue. See BOTTOM_UP_PARSING.md for technical details.
This optimization represents significant engineering effort and will be enabled in a future release once the edge case is resolved.
brew tap weima/code-search https://github.com/weima/code-search
brew install cs
npm install -g code-search-cli
cargo install code-search-cli
Download the pre-compiled binary for your platform from Releases.
# i18n text tracing (default mode)
cs "button text"
# Search in specific directory
cs "button text" /path/to/project
# Case-sensitive search
cs "ExactText" -s
cs "ExactText" --case-sensitive
# Case-insensitive search (explicit)
cs "text" -i
cs "text" --ignore-case
# Forward call tracing (what does this function call?)
cs "functionName" --trace
# Backward call tracing (who calls this function?)
cs "functionName" --traceback
# Both directions
cs "functionName" --trace-all
# Custom depth (default: 3, max: 10)
cs "functionName" --trace --depth 5
# Word boundary matching (whole words only)
cs "function" -w
cs "function" --word-regexp
# Regular expression search
cs "fn \w+\(" --regex
# Glob pattern filtering (search only in matching files)
cs "text" -g "*.ts"
cs "text" --glob "*.js" --glob "*.tsx"
# Exclude patterns from search
cs "text" --exclude test,spec,mock
# Include custom file extensions
cs "text" --include-extensions html.ui,vue.custom
# Search for files by name only (skip content search)
cs "filename" -f
cs "filename" --file-only
# Clear the search result cache
cs --clear-cache
# Simple machine-readable output (no progress indicators)
cs "text" --simple
# Verbose output with detailed parse error messages
cs "text" --verbose
# Find UI text with custom file types
cs "Add New" --include-extensions html.ui,erb.rails
# Case-sensitive search excluding test files
cs "ClassName" -s --exclude test,spec
# Search TypeScript files only
cs "interface" -g "*.ts"
# Find function calls with regex
cs "handleClick.*(" --regex -g "*.tsx"
# Trace function calls to depth 5
cs "processPayment" --trace --depth 5
# Simple output for AI agents (no progress indicators)
cs "error message" --simple
cs --help
The project maintains high test coverage to ensure reliability:
Run tests locally:
# All tests
cargo test
# With output
cargo test -- --nocapture
# Benchmarks
cargo bench
Test fixtures include real-world translation files from production projects (Rails, React, Vue, Discourse) to ensure robust handling of edge cases.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
For technical implementation details, see:
Apache License 2.0 - See LICENSE file for details.