Skip to content

Commit ef8007f

Browse files
feat: add lang filter
1 parent 5b64d2d commit ef8007f

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

src/extension/search.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export function buildCommand(query: SearchQuery) {
124124
if (strictness && strictness !== 'smart') {
125125
args.push('--strictness', strictness)
126126
}
127+
if (query.lang) {
128+
args.push('--lang', query.lang)
129+
}
127130
args.push(...includeFile.split(',').filter(Boolean))
128131
console.debug('running', query, command, args)
129132
// TODO: multi-workspaces support

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface SearchQueryBasic {
3232
rewrite: string
3333
strictness: string
3434
selector: string
35+
lang: string
3536
}
3637

3738
export interface SearchQuery extends SearchQueryBasic {

src/webview/SearchSidebar/SearchProviderMessage/index.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ function Empty({ query }: { query: SearchQuery }) {
4343
supported
4444
</VSCodeLink>
4545
</li>
46-
<li>
47-
Adjust your gitignore files.{' '}
48-
<VSCodeLink href="https://ast-grep.github.io/reference/cli/run.html#no-ignore-file-type">
49-
See doc
50-
</VSCodeLink>
51-
</li>
46+
{query.lang ? (
47+
<li>
48+
Remove language filter <code style={codeStyle}>{query.lang}</code>{' '}
49+
and search in all files.
50+
</li>
51+
) : null}
5252
{query.strictness !== 'smart' ? (
5353
<li>
5454
Adjust pattern{' '}
@@ -71,6 +71,12 @@ function Empty({ query }: { query: SearchQuery }) {
7171
.
7272
</li>
7373
) : null}
74+
<li>
75+
Adjust your gitignore files.{' '}
76+
<VSCodeLink href="https://ast-grep.github.io/reference/cli/run.html#no-ignore-file-type">
77+
See doc
78+
</VSCodeLink>
79+
</li>
7480
</ul>
7581
</div>
7682
)

src/webview/SearchSidebar/SearchWidgetContainer/LangSelect.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as stylex from '@stylexjs/stylex'
22
import { Icon, icons } from '../SearchResultList/Icon'
3-
import { ChangeEvent, useCallback, useState } from 'react'
3+
import { ChangeEvent, useCallback } from 'react'
44
import { VscListFlat } from 'react-icons/vsc'
5+
import { useSearchField } from '../../hooks/useQuery'
56

67
const styles = stylex.create({
78
langButton: {
@@ -43,12 +44,12 @@ const styles = stylex.create({
4344
},
4445
})
4546

46-
function capitalize(word) {
47+
function capitalize(word: string) {
4748
return word.charAt(0).toUpperCase() + word.slice(1)
4849
}
4950

5051
export function LangSelect() {
51-
const [lang, setLang] = useState('')
52+
const [lang, setLang] = useSearchField('lang')
5253
const title = lang
5354
? `Search pattern in ${lang}`
5455
: 'Search pattern in specific language'
@@ -66,6 +67,7 @@ export function LangSelect() {
6667
<select
6768
{...stylex.props(styles.langDropdown)}
6869
style={{ outline: 'none' }}
70+
value={lang}
6971
onChange={onChange}
7072
>
7173
<option value="">Auto Detect</option>

src/webview/hooks/useQuery.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const searchQuery: Record<keyof SearchQuery, string> = {
1313
selector: '',
1414
includeFile: '',
1515
rewrite: '',
16+
lang: '',
1617
}
1718

1819
type PatternKeys = 'selector'
@@ -22,6 +23,7 @@ const LS_KEYS: Record<Exclude<keyof SearchQuery, PatternKeys>, string> = {
2223
includeFile: 'ast-grep-search-panel-include-value',
2324
rewrite: 'ast-grep-search-panel-rewrite-value',
2425
strictness: 'ast-grep-search-panel-strictness-value',
26+
lang: 'ast-grep-search-panel-lang-value',
2527
}
2628

2729
export function refreshResult() {

0 commit comments

Comments
 (0)