@@ -154,61 +154,70 @@ interface ScanResult {
154154}
155155
156156function activateLsp ( context : ExtensionContext ) {
157- let disposable = commands . registerCommand ( 'ast-grep.search' , async _uri => {
158- let curWorkspace = workspace . workspaceFolders ?. [ 0 ]
159- if ( ! curWorkspace ) {
160- return
161- }
162- const referenceView = await extensions
163- . getExtension ( 'vscode.references-view' )
164- ?. activate ( )
165- let pattern
166- try {
167- pattern = await window . showInputBox ( { } )
168- } catch {
169- return
170- }
171- if ( ! pattern ) {
172- return
173- }
174- let res = await client . sendRequest < ScanResult [ ] > ( 'ast-grep/search' , {
175- pattern : pattern
176- } )
157+ context . subscriptions . push (
158+ commands . registerCommand ( 'ast-grep.search' , async _uri => {
159+ let curWorkspace = workspace . workspaceFolders ?. [ 0 ]
160+ if ( ! curWorkspace ) {
161+ return
162+ }
163+ const referenceView = await extensions
164+ . getExtension ( 'vscode.references-view' )
165+ ?. activate ( )
166+ let pattern
167+ try {
168+ pattern = await window . showInputBox ( { } )
169+ } catch {
170+ return
171+ }
172+ if ( ! pattern ) {
173+ return
174+ }
175+ let res = await client . sendRequest < ScanResult [ ] > ( 'ast-grep/search' , {
176+ pattern : pattern
177+ } )
177178
178- let treeItemList : AstGrepScanTreeItem [ ] = [ ]
179- let grouped = groupBy ( res , 'uri' )
180- for ( let uri of Object . keys ( grouped ) ) {
181- let scanResultList = grouped [ uri ]
182- for ( let element of scanResultList ) {
183- treeItemList . push (
184- new AstGrepScanTreeItem ( {
185- source : element . content ,
186- range : element . position ,
187- uri : element . uri
188- } )
189- )
179+ let treeItemList : AstGrepScanTreeItem [ ] = [ ]
180+ let grouped = groupBy ( res , 'uri' )
181+ for ( let uri of Object . keys ( grouped ) ) {
182+ let scanResultList = grouped [ uri ]
183+ for ( let element of scanResultList ) {
184+ treeItemList . push (
185+ new AstGrepScanTreeItem ( {
186+ source : element . content ,
187+ range : element . position ,
188+ uri : element . uri
189+ } )
190+ )
191+ }
190192 }
191- }
192- let provider = new NodeDependenciesProvider ( grouped )
193+ let provider = new NodeDependenciesProvider ( grouped )
193194
194- let symbolTreeInput = {
195- contextValue : 'ast-grep' ,
196- title : 'ast-grep' ,
197- location : {
198- uri : window . activeTextEditor ?. document . uri ,
199- range : new Range ( new Position ( 0 , 0 ) , new Position ( 0 , 0 ) )
200- } ,
201- resolve ( ) {
202- return provider
203- } ,
204- with ( ) {
205- return symbolTreeInput
195+ let symbolTreeInput = {
196+ contextValue : 'ast-grep' ,
197+ title : 'ast-grep' ,
198+ location : {
199+ uri : window . activeTextEditor ?. document . uri ,
200+ range : new Range ( new Position ( 0 , 0 ) , new Position ( 0 , 0 ) )
201+ } ,
202+ resolve ( ) {
203+ return provider
204+ } ,
205+ with ( ) {
206+ return symbolTreeInput
207+ }
206208 }
207- }
208- referenceView . setInput ( symbolTreeInput )
209- } )
209+ referenceView . setInput ( symbolTreeInput )
210+ } )
211+ )
210212
211- context . subscriptions . push ( disposable )
213+ context . subscriptions . push (
214+ workspace . onDidChangeConfiguration ( changeEvent => {
215+ if ( changeEvent . affectsConfiguration ( 'astGrep' ) ) {
216+ deactivate ( )
217+ client . start ( )
218+ }
219+ } )
220+ )
212221
213222 // instantiate and set input which updates the view
214223 // If the extension is launched in debug mode then the debug server options are used
@@ -331,13 +340,6 @@ async function restart() {
331340 return await client . start ( )
332341}
333342
334- workspace . onDidChangeConfiguration ( changeEvent => {
335- if ( changeEvent . affectsConfiguration ( 'astGrep' ) ) {
336- deactivate ( )
337- client . start ( )
338- }
339- } )
340-
341343export function deactivate ( ) : Promise < void > | undefined {
342344 if ( ! client ) {
343345 return undefined
0 commit comments