Skip to content

Commit 4941b77

Browse files
refactor: use searchQuery directly
1 parent 8e5d263 commit 4941b77

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

src/extension/preview.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ async function refreshSearchResult(
247247
fileUri: Uri,
248248
query: SearchQuery,
249249
) {
250-
const command = buildCommand({
251-
pattern: query.pattern,
252-
rewrite: query.rewrite,
253-
includeFiles: [query.includeFile],
254-
})
250+
const command = buildCommand(query)
255251
const bytes = await workspace.fs.readFile(fileUri)
256252
const { receiveResult, conclude } = bufferMaker(bytes)
257253
const updatedResults: DisplayResult[] = []

src/extension/search.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,9 @@ async function uniqueCommand(
106106
}
107107
}
108108

109-
interface CommandArgs {
110-
pattern: string
111-
rewrite?: string
112-
includeFiles: string[]
113-
}
114-
115109
// TODO: add unit test for commandBuilder
116-
export function buildCommand(query: CommandArgs) {
117-
const { pattern, includeFiles, rewrite } = query
110+
export function buildCommand(query: SearchQuery) {
111+
const { pattern, includeFile, rewrite } = query
118112
if (!pattern) {
119113
return
120114
}
@@ -124,7 +118,7 @@ export function buildCommand(query: CommandArgs) {
124118
if (rewrite) {
125119
args.push('--rewrite', rewrite)
126120
}
127-
args.push(...includeFiles.filter(Boolean))
121+
args.push(...includeFile.split(',').filter(Boolean))
128122
console.debug('running', query, command, args)
129123
// TODO: multi-workspaces support
130124
return spawn(command, args, {
@@ -139,11 +133,7 @@ interface Handlers {
139133
}
140134

141135
function getPatternRes(query: SearchQuery, handlers: Handlers) {
142-
const proc = buildCommand({
143-
pattern: query.pattern,
144-
includeFiles: [query.includeFile],
145-
rewrite: query.rewrite,
146-
})
136+
const proc = buildCommand(query)
147137
if (proc) {
148138
proc.on('error', error => {
149139
console.debug('ast-grep CLI runs error')

src/webview/SearchSidebar/SearchWidgetContainer/PatternConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const NOOP = () => {}
1717
export default function PatternConfig() {
1818
const [strictness, setStrictness] = usePatternConfig('strictness', 'smart')
1919
const [selector, setSelector] = usePatternConfig('selector', '')
20-
// biome-ignore lint/suspicious/noExplicitAny: onChange event has wrong type signature.
2120
const onStrictnessChange = useCallback(
21+
// biome-ignore lint/suspicious/noExplicitAny: onChange event has wrong type signature.
2222
(e: any) => {
2323
const select = e.target as HTMLSelectElement
2424
setStrictness(select.value)

0 commit comments

Comments
 (0)