Skip to content

Commit 11d1208

Browse files
feat: add error report
fix #133
1 parent 4731795 commit 11d1208

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export type Definition = {
4343
id: number
4444
inputValue: string
4545
}
46-
error: Error
46+
error: {
47+
id: number
48+
error: Error
49+
}
4750
}
4851
child2parent: {
4952
search: {

src/view.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ function setupParentPort(webviewView: vscode.WebviewView) {
187187
}
188188
await getPatternRes(payload.inputValue, {
189189
onData,
190-
onError(e) {
191-
parentPort.postMessage('error', e)
190+
onError(error) {
191+
parentPort.postMessage('error', {
192+
error,
193+
...payload
194+
})
192195
}
193196
})
194197
parentPort.postMessage('searchEnd', payload)

src/webview/SearchSidebar/SearchProviderMessage/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,31 @@ interface SearchProviderMessageProps {
5353
resultCount: number
5454
fileCount: number
5555
pattern: string
56+
error: Error | null
5657
}
5758

5859
const SearchProviderMessage = ({
5960
pattern,
6061
resultCount,
61-
fileCount
62+
fileCount,
63+
error
6264
}: SearchProviderMessageProps) => {
65+
if (error) {
66+
return (
67+
<div style={style}>
68+
Error occurs when running <code>ast-grep</code>.<br />
69+
Make sure you{' '}
70+
<VSCodeLink href="https://ast-grep.github.io/guide/quick-start.html#installation">
71+
installed the binary
72+
</VSCodeLink>{' '}
73+
and the command <code>ast-grep</code> is accessible{' '}
74+
<VSCodeLink href="https://github.com/ast-grep/ast-grep-vscode/issues/133#issuecomment-1943153446">
75+
by your editor
76+
</VSCodeLink>
77+
.
78+
</div>
79+
)
80+
}
6381
return (
6482
<>
6583
{resultCount === 0 ? (

src/webview/SearchSidebar/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export const SearchSidebar = () => {
1717
searchCount,
1818
groupedByFileSearchResult,
1919
refreshSearchResult,
20-
searching
20+
searching,
21+
searchError
2122
} = useSearchResult(inputValue)
2223

2324
// rendering tree is too expensive, useDeferredValue
@@ -35,6 +36,7 @@ export const SearchSidebar = () => {
3536
/>
3637
<SearchProviderMessage
3738
pattern={queryInFlight}
39+
error={searchError}
3840
resultCount={searchCount}
3941
fileCount={groupedByFileSearchResult.length}
4042
/>

src/webview/hooks/useSearch.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let grouped = [] as [string, DisplayResult[]][]
1313
let queryInFlight = ''
1414
let searching = true
1515
let notify = () => {}
16+
let searchError: Error | null = null
1617
// we will not immediately drop previous result
1718
// instead, use a stale flag and update it on streaming or end
1819
let hasStaleResult = false
@@ -22,6 +23,7 @@ function postSearch(inputValue: string) {
2223
childPort.postMessage('search', { id, inputValue })
2324
searching = true
2425
hasStaleResult = true
26+
searchError = null
2527
notify()
2628
}
2729

@@ -52,6 +54,16 @@ childPort.onMessage('searchEnd', event => {
5254
notify()
5355
})
5456

57+
childPort.onMessage('error', event => {
58+
if (event.id !== id) {
59+
return
60+
}
61+
searchError = event.error
62+
searching = false
63+
grouped = []
64+
notify()
65+
})
66+
5567
function groupBy(matches: DisplayResult[]) {
5668
const groups = new Map<string, DisplayResult[]>()
5769
for (const match of matches) {
@@ -104,6 +116,7 @@ export const useSearchResult = (inputValue: string) => {
104116
return {
105117
queryInFlight,
106118
searching,
119+
searchError,
107120
groupedByFileSearchResult: grouped,
108121
searchCount: grouped.reduce((a, l) => a + l[1].length, 0),
109122
refreshSearchResult

0 commit comments

Comments
 (0)