11import type { Definition , ParentPort , SgSearch } from './types'
2- import { execa } from 'execa'
32import { Unport , ChannelMessage } from 'unport'
43import * as vscode from 'vscode'
54import { workspace } from 'vscode'
5+ import { spawn } from 'node:child_process'
66
77export function activate ( context : vscode . ExtensionContext ) {
88 const provider = new SearchSidebarProvider ( context . extensionUri )
@@ -25,13 +25,20 @@ async function getPatternRes(pattern: string) {
2525 . get ( 'serverPath' , 'ast-grep' )
2626 const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
2727
28- // TODO: use ast-grep lsp to optimize the performance
2928 // TODO: multi-workspaces support
30- const { stdout } = await execa (
29+ // TODO: the code here is wrong, but we will change it
30+ let stdout = ''
31+ const child = spawn (
3132 command ,
32- [ 'run' , '--pattern' , pattern , '--json' ] ,
33- { cwd : uris [ 0 ] }
33+ [ 'run' , '--pattern' , pattern , '--json=compact' ] ,
34+ {
35+ cwd : uris [ 0 ]
36+ }
3437 )
38+ child . stdout . on ( 'data' , data => {
39+ stdout += data
40+ } )
41+ await new Promise ( r => child . on ( 'close' , r ) )
3542
3643 try {
3744 let res : SgSearch [ ] = JSON . parse ( stdout )
0 commit comments