opencode-plugin-search 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/dist/index.js +12556 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Evgeny Lyzov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# OpenCode Search Plugin
|
|
2
|
+
|
|
3
|
+
This plugin enhances OpenCode with advanced code search capabilities, including structural AST-based search using [ast-grep](https://ast-grep.github.io/) for sophisticated code analysis, linting, and rewriting.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Advanced code search**: Structural AST-based search capabilities
|
|
8
|
+
- **Pattern-based search**: Find code using simple AST patterns
|
|
9
|
+
- **Rule-based search**: Use YAML rules for complex structural queries
|
|
10
|
+
- **Syntax tree debugging**: Dump AST/CST to understand code structure
|
|
11
|
+
- **Rule testing**: Test YAML rules against code snippets
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this plugin to your OpenCode configuration:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"plugins": ["opencode-plugin-search"]
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Ensure `ast-grep` is installed and available in your PATH (or via devbox) for AST-based search functionality.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
The plugin provides advanced search tools powered by ast-grep:
|
|
28
|
+
|
|
29
|
+
### `ast_grep_find`
|
|
30
|
+
|
|
31
|
+
Search code in the project using AST patterns for structural matching.
|
|
32
|
+
|
|
33
|
+
**Arguments**:
|
|
34
|
+
- `pattern` (string): The ast-grep pattern (e.g., `"console.log($ARG)"`)
|
|
35
|
+
- `language` (string, optional): Programming language (default: auto-detect)
|
|
36
|
+
- `max_results` (number, optional): Maximum matches to return
|
|
37
|
+
- `output_format` (string, optional): `"text"` (human-readable) or `"json"`
|
|
38
|
+
|
|
39
|
+
**Example**:
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"pattern": "function $NAME($$$)",
|
|
43
|
+
"language": "javascript",
|
|
44
|
+
"max_results": 5
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `ast_grep_find_by_rule`
|
|
49
|
+
|
|
50
|
+
Search code using complex YAML rules for advanced structural queries.
|
|
51
|
+
|
|
52
|
+
**Arguments**:
|
|
53
|
+
- `yaml` (string): The ast-grep YAML rule definition
|
|
54
|
+
- `max_results` (number, optional): Maximum matches to return
|
|
55
|
+
- `output_format` (string, optional): `"text"` or `"json"`
|
|
56
|
+
|
|
57
|
+
**Example**:
|
|
58
|
+
```yaml
|
|
59
|
+
id: find-async-functions
|
|
60
|
+
language: javascript
|
|
61
|
+
rule:
|
|
62
|
+
kind: function_declaration
|
|
63
|
+
has:
|
|
64
|
+
pattern: await $EXPR
|
|
65
|
+
stopBy: end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### `ast_grep_dump_syntax`
|
|
69
|
+
|
|
70
|
+
Analyze code structure by dumping syntax trees for debugging and understanding.
|
|
71
|
+
|
|
72
|
+
**Arguments**:
|
|
73
|
+
- `code` (string): The code to analyze
|
|
74
|
+
- `language` (string): Programming language
|
|
75
|
+
- `format` (string, optional): `"cst"` (concrete syntax tree), `"ast"` (abstract syntax tree), or `"pattern"` (pattern interpretation)
|
|
76
|
+
|
|
77
|
+
**Example**:
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"code": "async function example() { await fetch(); }",
|
|
81
|
+
"language": "javascript",
|
|
82
|
+
"format": "cst"
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `ast_grep_test_rule`
|
|
87
|
+
|
|
88
|
+
Test and validate YAML rules against code snippets to ensure correct matching.
|
|
89
|
+
|
|
90
|
+
**Arguments**:
|
|
91
|
+
- `code` (string): The code to test
|
|
92
|
+
- `yaml` (string): The ast-grep YAML rule
|
|
93
|
+
|
|
94
|
+
**Example**:
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"code": "async function test() { await fetch(); }",
|
|
98
|
+
"yaml": "id: test\nlanguage: javascript\nrule:\n kind: function_declaration\n has:\n pattern: await $EXPR\n stopBy: end"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
The plugin automatically looks for `sgconfig.yaml` in the project root to support custom languages and rule directories for ast-grep search functionality. See [ast-grep documentation](https://ast-grep.github.io/advanced/custom-language.html) for configuration details.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Install dependencies
|
|
110
|
+
bun install
|
|
111
|
+
|
|
112
|
+
# Build plugin
|
|
113
|
+
bun run build
|
|
114
|
+
|
|
115
|
+
# Type checking
|
|
116
|
+
bun run typecheck
|
|
117
|
+
|
|
118
|
+
# Run tests
|
|
119
|
+
bun run test
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT
|