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)),
)
[2m 6 โ [22m[2m */;[22m
[31m[2m 7 โ [22m[39m[31m[1m[4mlet myFunc[24m[22m[39m[2mtion = ()[22m[31m[2m => [22m[39m[2mprint_endline([22m[32m[2m"do something"[22m[39m[2m);[22m
[2m 8 โ [22m
[2m 9 โ [22m[35m[2mlet[22m[39m[2m ex = (arg)[22m[31m[2m => [22m[39m[2m{[22m
[2m10 โ [22m[2m [22m[33m[2mif[22m[39m[2m(arg === true) {[22m
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)),
)
[2m 4 โ [22m[2m * [22m[34m[2mThis[22m[39m[2m source code is licensed under the ...
[2m 5 โ [22m[2m * [22m[34m[2mLICENSE[22m[39m[2m file in the root directory of ...
[2m 6 โ [22m[2m */;[22m
[31m[2m 7 โ [22m[39m[31m[1m[4mlet myFunc[24m[22m[39m[2mtion = ()[22m[31m[2m => [22m[39m[2mprint_endline([22m[32m[2m"do something"[22m[39m[2m);[22m
[2m 8 โ [22m
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)),
)
[2m 6 โ [22m[2m */;[22m
[31m[2m 7 โ [22m[39m[31m[1m[4mlet myFunc[24m[22m[39m[2mtion = ()[22m[31m[2m => [22m[39m[2mprint_endline([22m[32m[2m"do something"[22m[39m[2m);[22m
[2m 8 โ [22m
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)),
)
[2m 6 โ [22m[2m */;[22m
[31m[2m 7 โ [22m[39m[31m[1m[4mlet myFunc[24m[22m[39m[2mtion = ()[22m[31m[2m => [22m[39m[2mprint_endline([22m[32m[2m"do something"[22m[39m[2m);[22m
[2m 8 โ [22m