Skip to content

Keep the lines inside comments verbatim in created interfaces - #9202

Draft
cknitt wants to merge 1 commit into
masterfrom
drift-9181a-doc-comment-indent
Draft

cknitt wants to merge 1 commit into
masterfrom
drift-9181a-doc-comment-indent

Conversation

@cknitt

@cknitt cknitt commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Part of #9181 (first item). This fixes an unreleased regression from #9144, so it adds no changelog fragment; #9144's fragment covers the release note.

Since #9144, the editor's "create interface" command reindents the declarations it copies from the source to their nesting depth in the interface. It keeps the lines inside string and template literals verbatim, because reindenting them would change their value, but not the lines inside comments. A multi-line doc comment is the string payload of @res.doc, so its continuation lines were shifted too: in a nested module, a fenced code block in a doc comment became an indented code block for rescript-tools doc, and relative indentation inside the comment collapsed.

literal_lines in analysis/src/create_interface.ml now marks the lines inside comment tokens the same way as the lines inside literals, so the lines after the first line of a doc comment or block comment are copied verbatim. The scanner already returns comments as tokens, so quotes and backticks inside comments, nested block comments and /* inside // line comments are handled without further changes. As with a multi-line string, a line that ends a comment and continues with code keeps its source indentation.

Tests

  • New analysis fixture tests/analysis_tests/tests/src/CreateInterfaceComments.res: doc comments on types at the top level and two modules deep, on record fields and on an external, a starred doc comment, regular and nested block comments containing quotes and backticks, a // comment containing /*, and a module whose source is indented deeper than its place in the interface (lines outside comments are still reindented). Without the fix the comment lines in the nested modules are shifted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb

Why:
    Since #9144, "create interface" reindents copied declarations to their
    nesting depth and keeps only lines inside string and template literals
    verbatim. A multi-line doc comment is the string payload of @res.doc,
    so shifting its lines changed the documentation: a fenced code block
    became an indented one and relative indentation collapsed.

`literal_lines` now also marks the lines inside comments, doc comments and
regular block comments alike, so they are copied verbatim.

Format modified (created interface of a doc comment in a nested module):
Example:
    module A = {
      module B = {
        /** Example:
    ```rescript
    let v: t = 1
    ```
    */
        type t = int
      }
    }
Before (rescript):
    module A: {
      module B: {
        /** Example:
        ```rescript
        let v: t = 1
        ```
        */
        type t = int
      }
    }
After (rescript):
    module A: {
      module B: {
        /** Example:
    ```rescript
    let v: t = 1
    ```
    */
        type t = int
      }
    }

Review: What about a comment whose last line continues with code, such as
`*/ field: int`? The whole line keeps its source indentation, as a line
ending a multi-line string literal already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9181a-doc-comment-indent branch from 0e1f4fc to 51278ec Compare November 3, 2026 18:33
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Changelog

No changelog entry.

Semantic Diff

1 commit · Full page

Keep the lines inside comments verbatim in created interfaces

51278ec · cknitt + Claude · Nov 03, 2026, 18:32 UTC

Why

Since #9144, "create interface" reindents copied declarations to their nesting depth and keeps only lines inside string and template literals verbatim. A multi-line doc comment is the string payload of @res.doc, so shifting its lines changed the documentation: a fenced code block became an indented one and relative indentation collapsed.

literal_lines now also marks the lines inside comments, doc comments and regular block comments alike, so they are copied verbatim.

Format modified (created interface of a doc comment in a nested module)

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

rescript

 module A: {
   module B: {
     /** Example:
-    ```rescript
-    let v: t = 1
-    ```
-    */
+```rescript
+let v: t = 1
+```
+*/
     type t = int
   }
 }

Review

  • What about a comment whose last line continues with code, such as */ field: int? The whole line keeps its source indentation, as a line ending a multi-line string literal already does.

@cknitt cknitt added the changelog:skip No release notes needed label Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.73%. Comparing base (ac73578) to head (51278ec).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9202   +/-   ##
=======================================
  Coverage   81.73%   81.73%           
=======================================
  Files         458      458           
  Lines       65292    65292           
=======================================
  Hits        53364    53364           
  Misses      11928    11928           
Files with missing lines Coverage Δ
analysis/src/create_interface.ml 84.82% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9202

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9202

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9202

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9202

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9202

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9202

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9202

commit: 51278ec

@cknitt

cknitt commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T18:52:15.420844Z 51278ec Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 51278ecb33

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:skip No release notes needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant