@@ -24,13 +24,13 @@ The first argument is the language, the second argument is the file globs, and t
2424
2525``` ts
2626// matches is an array of AST (immutable) nodes
27- const { matches } = await sg .search (" src/*.ts" , " console.log($META)" )
27+ const { matches } = await sg .search (" ts " , " src/*.ts" , " console.log($META)" )
2828```
2929
3030- find all TypeScript functions without comments. This example uses the [ rule syntax] ( https://ast-grep.github.io/reference/rule.html ) .
3131
3232``` ts
33- const { matches } = await sg .search (" src/fib.ts" , {
33+ const { matches } = await sg .search (" ts " , " src/fib.ts" , {
3434 rule: {
3535 kind: " function_declaration" ,
3636 not: {
@@ -74,7 +74,7 @@ that do not intersect with the `to` files of the diff.
7474
7575``` ts "{ diff }" wrap
7676const diff = await git .diff ({ base: " main" })
77- const { matches } = await sg .search (" src/fib.ts" , {... }, { diff })
77+ const { matches } = await sg .search (" ts " , " src/fib.ts" , {... }, { diff })
7878```
7979
8080## Changesets
@@ -155,19 +155,28 @@ If your language is not supported, go to [ast-grep langs](https://github.com/ast
155155
156156:::
157157
158+ ### Filename extension mapping
159+
160+ The following file extensions are mapped to the corresponding languages:
161+
162+ - HTML: ` html ` , ` htm`
163+ - JavaScript: ` cjs` , ` mjs` , ` js`
164+ - TypeScript: ` cts` , ` mts` , ` ts`
165+ - TSX: ` tsx`
166+ - CSS: ` css`
167+ - c: ` c`
168+ - cpp: ` cpp` , ` cxx` , ` h` , ` hpp` , ` hxx`
169+ - python: ` py`
170+ - C#: ` cs`
171+ - sql: ` sql `
172+
158173# ## Overriding the language selection
159174
160175GenAIScript has default mappings from well- known file extensions to languages.
161176However, you can override this by passing the ` lang` option to the ` search` method.
162177
163178` ` ` ts " { lang: " ts" }"
164- const { matches } = await sg .search (" src/fib.ts" , {... }, { lang: " ts" })
165- ` ` `
166-
167- or if you want to search multiple languages, by providing a ` extension` to ` lang` mapping.
168-
169- ` ` ` ts ' lang: { "ttts": "ts", "jjjs":"js" }'
170- const { matches } = await sg .search (" src/*" , {... }, { lang: { " ttts" : " ts" , " jjjs" : " js" } })
179+ const { matches } = await sg .search (" ts" , " src/fib.ts" , {... }, { lang: " ts" })
171180` ` `
172181
173182## Learning ast-grep
0 commit comments