(absPath: string, language: Language)
| 187 | } |
| 188 | |
| 189 | async function treeFor(absPath: string, language: Language): Promise<CachedTree | null> { |
| 190 | let stat: fs.Stats; |
| 191 | try { |
| 192 | stat = fs.statSync(absPath); |
| 193 | } catch { |
| 194 | return null; |
| 195 | } |
| 196 | const key = `${language}:${stat.mtimeMs}:${stat.size}`; |
| 197 | const hit = treeCache.get(absPath); |
| 198 | if (hit && hit.key === key) return hit; |
| 199 | if (stat.size > MAX_PARSE_BYTES) return null; |
| 200 | let source: string; |
| 201 | try { |
| 202 | source = fs.readFileSync(absPath, 'utf8'); |
| 203 | } catch { |
| 204 | return null; |
| 205 | } |
| 206 | const tree = await parse(source, language); |
| 207 | if (!tree) return null; |
| 208 | const entry = { key, tree, source }; |
| 209 | remember(absPath, entry); |
| 210 | return entry; |
| 211 | } |
| 212 | |
| 213 | async function parse(source: string, language: Language): Promise<Tree | null> { |
| 214 | try { |
no test coverage detected