File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 3232 "command" : " ast-grep.restartLanguageServer" ,
3333 "title" : " restart Language Server" ,
3434 "category" : " ast-grep"
35+ },
36+ {
37+ "command" : " ast-grep.searchInFolder" ,
38+ "title" : " Find ast-grep Pattern in Folder"
3539 }
3640 ],
41+ "menus" : {
42+ "explorer/context" : [
43+ {
44+ "command" : " ast-grep.searchInFolder" ,
45+ "group" : " 4_search" ,
46+ "when" : " explorerResourceIsFolder"
47+ }
48+ ]
49+ },
3750 "configuration" : {
3851 "type" : " object" ,
3952 "title" : " ast-grep" ,
Original file line number Diff line number Diff line change 77 Executable
88} from 'vscode-languageclient/node'
99
10- import { activate as activateWebview } from './view'
10+ import { activate as activateWebview , findInFolder } from './view'
1111
1212let client : LanguageClient
1313const diagnosticCollectionName = 'ast-grep-diagnostics'
@@ -35,6 +35,7 @@ function getExecutable(isDebug: boolean): Executable {
3535
3636function activateLsp ( context : ExtensionContext ) {
3737 context . subscriptions . push (
38+ commands . registerCommand ( 'ast-grep.searchInFolder' , findInFolder ) ,
3839 commands . registerCommand ( 'ast-grep.restartLanguageServer' , async ( ) => {
3940 console . log (
4041 'Restart the ast-grep language server by ast-grep.restart command'
Original file line number Diff line number Diff line change 1+ import path from 'path'
12import type {
23 Definition ,
34 ParentPort ,
@@ -7,14 +8,14 @@ import type {
78} from './types'
89import { Unport , ChannelMessage } from 'unport'
910import * as vscode from 'vscode'
10- import { workspace } from 'vscode'
11+ import { workspace , window } from 'vscode'
1112import { type ChildProcessWithoutNullStreams , spawn } from 'node:child_process'
1213
1314export function activate ( context : vscode . ExtensionContext ) {
1415 const provider = new SearchSidebarProvider ( context . extensionUri )
1516
1617 context . subscriptions . push (
17- vscode . window . registerWebviewViewProvider (
18+ window . registerWebviewViewProvider (
1819 SearchSidebarProvider . viewType ,
1920 provider ,
2021 { webviewOptions : { retainContextWhenHidden : true } }
@@ -288,3 +289,14 @@ function getNonce() {
288289 }
289290 return text
290291}
292+
293+ export function findInFolder ( data : any ) {
294+ const workspacePath = workspace . workspaceFolders ?. [ 0 ] . uri . fsPath
295+ // compute relative path to the workspace folder
296+ const relative = workspacePath && path . relative ( workspacePath , data . fsPath )
297+ if ( ! relative ) {
298+ window . showErrorMessage ( 'ast-grep Error: folder is not in the workspace' )
299+ return
300+ }
301+ window . showInformationMessage ( 'ast-grep: searching in ' + relative )
302+ }
You can’t perform that action at this time.
0 commit comments