Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions analysis/src/create_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ module Source_file_extractor = struct
go 0

(* For each line from [line_start] to [line_end], whether it begins inside
a string or template literal that starts on an earlier line. Such lines
are part of the literal's value, so reindenting them would change it. *)
a string or template literal, or a comment, that starts on an earlier
line. Such lines are part of the literal's value, or of the comment's
text (a doc comment is the string payload of @res.doc), so reindenting
them would change it. *)
let literal_lines lines ~line_start ~col_start ~line_end =
let first = lines.(line_start) in
let col_start = max 0 (min col_start (String.length first)) in
Expand Down Expand Up @@ -47,7 +49,7 @@ module Source_file_extractor = struct
let rec go () =
match Res_scanner.scan scanner with
| _, _, Res_token.Eof -> ()
| start_pos, end_pos, String _ ->
| start_pos, end_pos, (String _ | Comment _) ->
mark start_pos end_pos;
go ()
| start_pos, _, Backtick ->
Expand All @@ -60,8 +62,8 @@ module Source_file_extractor = struct

(* The source text from [pos_start] to [pos_end], indented by [indent]:
the lines after the first keep their indentation relative to the line
the text starts on, except lines inside a string or template literal,
which are copied verbatim. *)
the text starts on, except lines inside a string or template literal or
a comment, which are copied verbatim. *)
let extract lines ~indent ~pos_start ~pos_end =
let line_start, col_start = pos_start in
let line_end, col_end = pos_end in
Expand Down
60 changes: 60 additions & 0 deletions tests/analysis_tests/tests/src/CreateInterfaceComments.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// ^int

/** Top level:
```rescript
let v: t = 1
```
indented
*/
type top = int

module A = {
module B = {
/** Example:
```rescript
let v: t = 1
```
two spaces
eight spaces
*/
type t = int

// A line comment with "a quote and `a backtick
type w = {
/** Field doc
continued
*/
a: int,
/* block
inside */
b: string,
/* Nested /* comment
with "a quote, 'a char and `a backtick
*/ still in the outer comment
*/
c: bool,
}

/** Doc of now
continued */
@val external now: unit => float = "Date.now"
}

/**
* Starred doc
* indented
*/
type v = B.t
}

module C = {
/** Source indented
deeper */
type d = {
// A line comment with "a quote, `a backtick and /* no block
e: int,
/* block
comment */
f: int,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Create Interface src/CreateInterfaceComments.res
/** Top level:
```rescript
let v: t = 1
```
indented
*/
type top = int
module A: {
module B: {
/** Example:
```rescript
let v: t = 1
```
two spaces
eight spaces
*/
type t = int
type w = {
/** Field doc
continued
*/
a: int,
/* block
inside */
b: string,
/* Nested /* comment
with "a quote, 'a char and `a backtick
*/ still in the outer comment
*/
c: bool,
}
/** Doc of now
continued */
@val external now: unit => float = "Date.now"
}
/**
* Starred doc
* indented
*/
type v = B.t
}
module C: {
/** Source indented
deeper */
type d = {
// A line comment with "a quote, `a backtick and /* no block
e: int,
/* block
comment */
f: int,
}
}

Loading