-
Notifications
You must be signed in to change notification settings - Fork 471
Preserve @as decorator on record fields when creating interface #7779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -38,6 +38,8 @@ module AttributesUtils : sig | |||||
|
||||||
val contains : string -> t -> bool | ||||||
|
||||||
val isEmpty : t -> bool | ||||||
|
||||||
val toString : t -> string | ||||||
end = struct | ||||||
type attribute = {line: int; offset: int; name: string} | ||||||
|
@@ -76,6 +78,8 @@ end = struct | |||||
let contains attributeForSearch t = | ||||||
t |> List.exists (fun {name} -> name = attributeForSearch) | ||||||
|
||||||
let isEmpty t = t = [] | ||||||
|
||||||
let toString t = | ||||||
match t with | ||||||
| [] -> "" | ||||||
|
@@ -250,11 +254,22 @@ let printSignature ~extractor ~signature = | |||||
Buffer.add_string buf (indent ^ newItemStr ^ "\n"); | ||||||
processSignature ~indent items | ||||||
| Sig_type (id, typeDecl, resStatus) :: items -> | ||||||
let newItemStr = | ||||||
sigItemToString | ||||||
(Printtyp.tree_of_type_declaration id typeDecl resStatus) | ||||||
let lines = | ||||||
let posStart, posEnd = Loc.range typeDecl.type_loc in | ||||||
extractor |> SourceFileExtractor.extract ~posStart ~posEnd | ||||||
in | ||||||
Buffer.add_string buf (indent ^ newItemStr ^ "\n"); | ||||||
let attributes = AttributesUtils.make lines in | ||||||
|
||||||
(if not (AttributesUtils.isEmpty attributes) then | ||||||
(* Copy the type declaration verbatim to preserve attributes *) | ||||||
Buffer.add_string buf ((lines |> String.concat "\n") ^ "\n") | ||||||
|
Buffer.add_string buf ((lines |> String.concat "\n") ^ "\n") | |
Array.iter (fun line -> Buffer.add_string buf line; Buffer.add_char buf '\n') lines |
Copilot uses AI. Check for mistakes.
Outdated
Copilot
AI
Aug 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The conditional logic should be inverted to reduce nesting. Consider using early return pattern: if AttributesUtils.isEmpty attributes then (* normal processing *) else (* verbatim copy *)
.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work in the
else
branch too? Can we always copy verbatim? Or what's the tradeoff here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the
else
branch since every type declaration should be valid in an interface file when copied verbatim 👍 The only tradeoff I can think of is that we'll be copying any non-doc comments within the declaration