Reason Native
  • Docs
  • Help
  • GitHub

โ€บFile Context Printer

Overview

  • Introduction
  • Native Basics
  • Getting Started

Rely

  • Introduction
  • Quickstart
  • Guides

    • Setup and Teardown
    • Mock Functions

    API Reference

    • Basic API
    • Expect
  • Advanced

Console

  • Introduction
  • Quickstart
  • API

Pastel

  • Introduction
  • Quickstart
  • API
  • Console

Refmterr

  • Introduction
  • Quickstart

File Context Printer

  • Introduction
  • Quickstart
  • API

File Context Printer API

Prefer reading code? Check out FileContextPrinter.rei

Configuration Options

linesBefore

Lines of code to show before specified context. From there, extract and print file context like so:

module FCP =
  FileContextPrinter.Make({
    let config =
      FileContextPrinter.Config.initialize({linesBefore: 1, linesAfter: 3});
  });
FCP.printFile(
  "src/file-context-printer/test/DummyFile.re",
  ((7, 1), (7, 11)),
)
 6 โ”†  */;
 7 โ”† let myFunction = () => print_endline("do something");
 8 โ”† 
 9 โ”† let ex = (arg) => {
10 โ”†     if(arg === true) {

linesAfter

Lines of code to show before specified context. From there, extract and print file context like so:

module FCP =
  FileContextPrinter.Make({
    let config =
      FileContextPrinter.Config.initialize({linesBefore: 3, linesAfter: 1});
  });
FCP.printFile(
  "src/file-context-printer/test/DummyFile.re",
  ((7, 1), (7, 11)),
)
 4 โ”†  * This source code is licensed under the ...
 5 โ”†  * LICENSE file in the root directory of ...
 6 โ”†  */;
 7 โ”† let myFunction = () => print_endline("do something");
 8 โ”† 

Methods

printFile

Prints context from a file.

Signature

let printFile: (~path: string, ~highlight: rowColumnRange) => option(string);

Example

FCP.printFile(
  "src/file-context-printer/test/DummyFile.re",
  ((7, 1), (7, 11)),
)
 6 โ”†  */;
 7 โ”† let myFunction = () => print_endline("do something");
 8 โ”† 

print

Prints context from a list of lines

Signature

let print: (list(string), ~highlight: rowColumnRange) => string;

Example

FCP.print(
  [
    "/**",
    " * Copyright (c) Facebook, Inc. and its affiliates."
    " *",
    " * This source code is licensed under the MIT license found in the",
    " * LICENSE file in the root directory of this source tree.",
    " */;",
    "let myFunction = () => print_endline(\"do something\");",
    "",
    "let ex = (arg) => {",
    "  if(arg === true) {", 
    "    print_endline(\"raising an error\");",
    "    raise(Not_found);",
    "  }",
    "}",
  ],
  ((7, 1), (7, 11)),
)
 6 โ”†  */;
 7 โ”† let myFunction = () => print_endline("do something");
 8 โ”† 
โ† Quickstart
  • Configuration Options
    • linesBefore
    • linesAfter
  • Methods
    • printFile
    • print
Reason Native
Projects
RelyConsolePastelRefmterrFile Context Printer
More
GitHubStar
Facebook Open Source
Copyright ยฉ 2021 Facebook Inc.