Skip to content

Commit c91d5a5

Browse files
feat: add pattern/yaml mode toggle
1 parent d8b0336 commit c91d5a5

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

media/pattern-dark.svg

Lines changed: 4 additions & 0 deletions
Loading

media/pattern-light.svg

Lines changed: 4 additions & 0 deletions
Loading

media/yaml-dark.svg

Lines changed: 3 additions & 0 deletions
Loading

media/yaml-light.svg

Lines changed: 3 additions & 0 deletions
Loading

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@
8181
"dark": "media/expand-dark.svg"
8282
}
8383
},
84+
{
85+
"command": "ast-grep.enableYAML",
86+
"title": "Use YAML",
87+
"icon": {
88+
"light": "media/yaml-light.svg",
89+
"dark": "media/yaml-dark.svg"
90+
}
91+
},
92+
{
93+
"command": "ast-grep.enablePattern",
94+
"title": "Use Pattern",
95+
"icon": {
96+
"light": "media/pattern-light.svg",
97+
"dark": "media/pattern-dark.svg"
98+
}
99+
},
84100
{
85101
"command": "ast-grep.searchByCode",
86102
"title": "ast-grep: Search by Code"
@@ -103,6 +119,16 @@
103119
}
104120
],
105121
"view/title": [
122+
{
123+
"command": "ast-grep.enableYAML",
124+
"when": "view == ast-grep.search.input && !ast-grep.yamlMode",
125+
"group": "navigation"
126+
},
127+
{
128+
"command": "ast-grep.enablePattern",
129+
"when": "view == ast-grep.search.input && ast-grep.yamlMode",
130+
"group": "navigation"
131+
},
106132
{
107133
"command": "ast-grep.collapseAll",
108134
"when": "view == ast-grep.search.input && !ast-grep.searchDefaultCollapse",

src/extension/webview.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export function activateWebview(context: vscode.ExtensionContext) {
1919
commands.registerCommand('ast-grep.clearSearchResults', clearSearchResults),
2020
commands.registerCommand('ast-grep.expandAll', toggleAllSearch),
2121
commands.registerCommand('ast-grep.collapseAll', toggleAllSearch),
22+
commands.registerCommand('ast-grep.enableYAML', enableYAML),
23+
commands.registerCommand('ast-grep.enablePattern', enablePattern),
2224
)
2325
}
2426

@@ -122,6 +124,22 @@ function clearSearchResults() {
122124
parentPort.postMessage('clearSearchResults', {})
123125
}
124126

127+
function enableYAML() {
128+
vscode.commands.executeCommand(
129+
'setContext',
130+
'ast-grep.yamlMode',
131+
true,
132+
)
133+
}
134+
135+
function enablePattern() {
136+
vscode.commands.executeCommand(
137+
'setContext',
138+
'ast-grep.yamlMode',
139+
false,
140+
)
141+
}
142+
125143
let defaultCollapse = false
126144

127145
// reset default collapse when starting a new search

0 commit comments

Comments
 (0)