opencode-plugin-search 0.0.2 → 0.0.3
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/README.md +52 -13
- package/dist/index.js +2791 -39
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -47,22 +47,29 @@ Search code in the project using AST patterns for structural matching.
|
|
|
47
47
|
|
|
48
48
|
### `ast_grep_find_by_rule`
|
|
49
49
|
|
|
50
|
-
Search code using
|
|
50
|
+
Search code using structured AST rules for advanced structural queries.
|
|
51
51
|
|
|
52
52
|
**Arguments**:
|
|
53
|
-
- `
|
|
53
|
+
- `rule` (object): The ast-grep rule definition as a structured object with required `id`, `language`, and `rule` fields
|
|
54
54
|
- `max_results` (number, optional): Maximum matches to return
|
|
55
55
|
- `output_format` (string, optional): `"text"` or `"json"`
|
|
56
56
|
|
|
57
57
|
**Example**:
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"rule": {
|
|
61
|
+
"id": "find-async-functions",
|
|
62
|
+
"language": "javascript",
|
|
63
|
+
"rule": {
|
|
64
|
+
"kind": "function_declaration",
|
|
65
|
+
"has": {
|
|
66
|
+
"pattern": "await $EXPR",
|
|
67
|
+
"stopBy": "end"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"max_results": 10
|
|
72
|
+
}
|
|
66
73
|
```
|
|
67
74
|
|
|
68
75
|
### `ast_grep_dump_syntax`
|
|
@@ -85,20 +92,52 @@ Analyze code structure by dumping syntax trees for debugging and understanding.
|
|
|
85
92
|
|
|
86
93
|
### `ast_grep_test_rule`
|
|
87
94
|
|
|
88
|
-
Test and validate
|
|
95
|
+
Test and validate structured AST rules against code snippets to ensure correct matching.
|
|
89
96
|
|
|
90
97
|
**Arguments**:
|
|
91
98
|
- `code` (string): The code to test
|
|
92
|
-
- `
|
|
99
|
+
- `rule` (object): The ast-grep rule definition as a structured object with required `id`, `language`, and `rule` fields
|
|
93
100
|
|
|
94
101
|
**Example**:
|
|
95
102
|
```json
|
|
96
103
|
{
|
|
97
104
|
"code": "async function test() { await fetch(); }",
|
|
98
|
-
"
|
|
105
|
+
"rule": {
|
|
106
|
+
"id": "test",
|
|
107
|
+
"language": "javascript",
|
|
108
|
+
"rule": {
|
|
109
|
+
"kind": "function_declaration",
|
|
110
|
+
"has": {
|
|
111
|
+
"pattern": "await $EXPR",
|
|
112
|
+
"stopBy": "end"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
99
116
|
}
|
|
100
117
|
```
|
|
101
118
|
|
|
119
|
+
## Rule Structure
|
|
120
|
+
|
|
121
|
+
The rule object follows the ast-grep rule configuration interface:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
interface RuleObject {
|
|
125
|
+
pattern?: string | Pattern
|
|
126
|
+
kind?: string
|
|
127
|
+
regex?: string
|
|
128
|
+
inside?: RuleObject & Relation
|
|
129
|
+
has?: RuleObject & Relation
|
|
130
|
+
follows?: RuleObject & Relation
|
|
131
|
+
precedes?: RuleObject & Relation
|
|
132
|
+
all?: RuleObject[]
|
|
133
|
+
any?: RuleObject[]
|
|
134
|
+
not?: RuleObject
|
|
135
|
+
matches?: string
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See [ast-grep rule documentation](https://ast-grep.github.io/guide/rule-config.html) for detailed examples.
|
|
140
|
+
|
|
102
141
|
## Configuration
|
|
103
142
|
|
|
104
143
|
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.
|