( file: string, line1: number, column1: number, nextRootDirectory: string )
| 433 | * relative to `nextRootDirectory`. |
| 434 | */ |
| 435 | export async function openFileInEditor( |
| 436 | file: string, |
| 437 | line1: number, |
| 438 | column1: number, |
| 439 | nextRootDirectory: string |
| 440 | ): Promise<{ found: boolean; error: unknown | null }> { |
| 441 | let filePath: string |
| 442 | if (file.startsWith('file://')) { |
| 443 | try { |
| 444 | filePath = fileURLToPath(file) |
| 445 | } catch (error) { |
| 446 | return { found: false, error } |
| 447 | } |
| 448 | } else if (path.isAbsolute(file)) { |
| 449 | filePath = file |
| 450 | } else { |
| 451 | filePath = path.join(nextRootDirectory, file) |
| 452 | } |
| 453 | |
| 454 | const result = { |
| 455 | found: false, |
| 456 | error: null as unknown | null, |
| 457 | } |
| 458 | const existed = await fsp.access(filePath, fs.constants.F_OK).then( |
| 459 | () => true, |
| 460 | () => false |
| 461 | ) |
| 462 | if (existed) { |
| 463 | try { |
| 464 | launchEditor(filePath, line1, column1) |
| 465 | result.found = true |
| 466 | } catch (err) { |
| 467 | result.error = err |
| 468 | } |
| 469 | } |
| 470 | return result |
| 471 | } |
no test coverage detected