Skip to content

Commit 6659a60

Browse files
Merge pull request #14 from sebthom/maxResults
Add maxResults parameter and return text results by default
2 parents beeb6a3 + 7b2721b commit 6659a60

File tree

9 files changed

+1183
-134
lines changed

9 files changed

+1183
-134
lines changed

.github/workflows/test.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
name: Tests
3+
4+
on: # https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
push:
6+
branches:
7+
- '**'
8+
tags-ignore: # don't build tags
9+
- '**'
10+
paths-ignore:
11+
- '**/*.md'
12+
pull_request:
13+
paths-ignore:
14+
- '**/*.md'
15+
workflow_dispatch:
16+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch
17+
18+
defaults:
19+
run:
20+
shell: bash
21+
22+
jobs:
23+
test:
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
matrix:
27+
os: [ubuntu-latest, windows-latest, macos-latest]
28+
fail-fast: false
29+
30+
steps:
31+
- name: Git Checkout
32+
uses: actions/checkout@v4 # https://github.com/actions/checkout
33+
34+
- name: Install uv
35+
uses: astral-sh/setup-uv@v5
36+
with:
37+
enable-cache: true
38+
39+
- name: Set up Python
40+
run: uv python install
41+
42+
- name: Install ast-grep
43+
run: |
44+
npm install -g @ast-grep/cli
45+
ast-grep --version
46+
47+
- name: Install dependencies
48+
run: |
49+
uv sync --all-extras --dev
50+
51+
- name: Lint with ruff
52+
run: |
53+
uv run ruff check .
54+
55+
- name: Format check with ruff
56+
run: |
57+
uv run ruff format --check .
58+
continue-on-error: true # TODO
59+
60+
- name: Type check with mypy
61+
run: |
62+
uv run mypy main.py
63+
64+
- name: Run unit tests
65+
run: |
66+
uv run pytest tests/test_unit.py -v --cov=main --cov-report=term-missing
67+
68+
- name: Run integration tests
69+
run: |
70+
uv run pytest tests/test_integration.py -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ dist/
66
wheels/
77
*.egg-info
88

9+
# MyPy. Ruff, PyTest cache folders
10+
.*_cache/
11+
912
# Virtual environments
1013
.venv

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ Test ast-grep YAML rules against code snippets before applying them to larger co
131131
### 🎯 `find_code`
132132
Search codebases using simple ast-grep patterns for straightforward structural matches.
133133

134+
**Parameters:**
135+
- `max_results`: Limit number of complete matches returned (default: unlimited)
136+
- `output_format`: Choose between `"text"` (default, ~75% fewer tokens) or `"json"` (full metadata)
137+
138+
**Text Output Format:**
139+
```
140+
Found 2 matches:
141+
142+
path/to/file.py:10-15
143+
def example_function():
144+
# function body
145+
return result
146+
147+
path/to/file.py:20-22
148+
def another_function():
149+
pass
150+
```
151+
134152
**Use cases:**
135153
- Find function calls with specific patterns
136154
- Locate variable declarations
@@ -139,6 +157,10 @@ Search codebases using simple ast-grep patterns for straightforward structural m
139157
### 🚀 `find_code_by_rule`
140158
Advanced codebase search using complex YAML rules that can express sophisticated matching criteria.
141159

160+
**Parameters:**
161+
- `max_results`: Limit number of complete matches returned (default: unlimited)
162+
- `output_format`: Choose between `"text"` (default, ~75% fewer tokens) or `"json"` (full metadata)
163+
142164
**Use cases:**
143165
- Find nested code structures
144166
- Search with relational constraints (inside, has, precedes, follows)

0 commit comments

Comments
 (0)