Skip to content

Commit 7663796

Browse files
feat: add yaml widget
1 parent c91d5a5 commit 7663796

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

src/extension/webview.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ function clearSearchResults() {
125125
}
126126

127127
function enableYAML() {
128+
parentPort.postMessage('enableYAML', true)
129+
parentPort.postMessage('clearSearchResults', {})
128130
vscode.commands.executeCommand(
129131
'setContext',
130132
'ast-grep.yamlMode',
@@ -133,6 +135,8 @@ function enableYAML() {
133135
}
134136

135137
function enablePattern() {
138+
parentPort.postMessage('enableYAML', false)
139+
parentPort.postMessage('clearSearchResults', {})
136140
vscode.commands.executeCommand(
137141
'setContext',
138142
'ast-grep.yamlMode',

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface ParentToChild {
7070
clearSearchResults: unknown
7171
toggleAllSearch: unknown
7272
searchByCode: { text: string }
73+
enableYAML: boolean
7374
}
7475

7576
export interface Diff {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as stylex from '@stylexjs/stylex'
2+
import { VSCodeButton, VSCodeTextArea } from '@vscode/webview-ui-toolkit/react'
3+
import { useState } from 'react'
4+
5+
const styles = stylex.create({
6+
yaml: {
7+
marginLeft: 18,
8+
display: 'flex',
9+
flexDirection: 'column',
10+
},
11+
editor: {
12+
width: '100%',
13+
},
14+
searchButton: {
15+
marginTop: 4,
16+
alignSelf: 'flex-end',
17+
},
18+
})
19+
20+
export default function YamlWidget() {
21+
const [value, setValue] = useState('')
22+
return (
23+
<div {...stylex.props(styles.yaml)}>
24+
<VSCodeTextArea
25+
{...stylex.props(styles.editor)}
26+
value={value}
27+
placeholder="YAML configuration"
28+
resize="vertical"
29+
onInput={(e: any) => {
30+
const newValue = e.target.value || ''
31+
setValue(newValue)
32+
}}
33+
/>
34+
<VSCodeButton
35+
{...stylex.props(styles.searchButton)}
36+
appearance="primary"
37+
onClick={() => {
38+
// Handle save or apply logic here
39+
console.log('YAML Config:', value)
40+
}}
41+
>
42+
Search
43+
</VSCodeButton>
44+
</div>
45+
)
46+
}

src/webview/SearchSidebar/SearchWidgetContainer/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { memo } from 'react'
1+
import { memo, useState } from 'react'
2+
import { useEffectOnce } from 'react-use'
3+
import { childPort } from '../../postMessage'
24
import SearchOptions from './SearchOptions'
35
import SearchWidget from './SearchWidget'
6+
import YamlWidget from './YamlWidget'
47

58
function SearchWidgetContainer() {
9+
const [isYaml, setIsYaml] = useState(false)
10+
useEffectOnce(() => {
11+
childPort.onMessage('enableYAML', setIsYaml)
12+
})
613
return (
714
<div style={{ margin: '0 12px 0 2px' }}>
8-
<SearchWidget />
15+
{isYaml ? <YamlWidget /> : <SearchWidget />}
916
<SearchOptions />
1017
</div>
1118
)

0 commit comments

Comments
 (0)