MCPcopy
hub / github.com/vercel/next.js / openFileInEditor

Function openFileInEditor

packages/next/src/next-devtools/server/launch-editor.ts:435–471  ·  view source on GitHub ↗
(
  file: string,
  line1: number,
  column1: number,
  nextRootDirectory: string
)

Source from the content-addressed store, hash-verified

433 * relative to `nextRootDirectory`.
434 */
435export 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}

Callers 2

getOverlayMiddlewareFunction · 0.90
getOverlayMiddlewareFunction · 0.90

Calls 4

launchEditorFunction · 0.85
startsWithMethod · 0.80
thenMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected