( filepath: string, queryPath: string, )
| 172 | }; |
| 173 | |
| 174 | export async function getQueryForFile( |
| 175 | filepath: string, |
| 176 | queryPath: string, |
| 177 | ): Promise<Parser.Query | undefined> { |
| 178 | const language = await getLanguageForFile(filepath); |
| 179 | if (!language) { |
| 180 | return undefined; |
| 181 | } |
| 182 | |
| 183 | const sourcePath = path.join( |
| 184 | process.env.NODE_ENV === "test" ? process.cwd() : __dirname, |
| 185 | "..", |
| 186 | ...(process.env.NODE_ENV === "test" |
| 187 | ? ["extensions", "vscode", "tree-sitter"] |
| 188 | : ["tree-sitter"]), |
| 189 | queryPath, |
| 190 | ); |
| 191 | if (!fs.existsSync(sourcePath)) { |
| 192 | return undefined; |
| 193 | } |
| 194 | const querySource = fs.readFileSync(sourcePath).toString(); |
| 195 | |
| 196 | const query = language.query(querySource); |
| 197 | return query; |
| 198 | } |
| 199 | |
| 200 | async function loadLanguageForFileExt( |
| 201 | fileExtension: string, |
no test coverage detected