8000 feat(mapper): show the file's comment and statement in the hover by colinhacks · Pull Request #17 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content

feat(mapper): show the file's comment and statement in the hover - #17

Merged
colinhacks merged 7 commits into
mainfrom
statement-jsdoc
Oct 22, 2026
Merged

colinhacks merged 7 commits into
mainfrom
statement-jsdoc

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

A comment written at the top of a .sql file now shows when you hover over the import. The module the content mapper writes gives query (the default export), sql and raw doc comments. Each holds the file's leading comment as prose, then the statement in a ```sql block:

  • The import (query): the statement as written.
  • sql (the export and the property of query): the statement as Reylo sends it, with $1 on Postgres and ? / CAST(? AS …) on MySQL and SQLite.
  • raw: the statement as written.

Before / after

get_user.sql on Postgres:

-- The signed-in user's profile.
-- Null when the id no longer exists.
select id, name, email from users where id = :id

Before, the hover over getUser showed only the type: (alias) const query: Query<{ id: number }, { … }, "maybeOne", "postgres"> & { readonly sql: typeof sql; readonly raw: typeof raw }. After, the type is followed by:

The signed-in user's profile.
Null when the id no longer exists.

```sql
select id, name, email from users where id = :id
```

The hover over getUser.sql ((property) sql: "-- The signed-in user's profile.\n…where id = $1\n") now carries:

The signed-in user's profile.
Null when the id no longer exists.

```sql
select id, name, email from users where id = $1
```

The statement as Reylo sends it to the database, as the module's `sql` export: `:id` is `$1` on Postgres and `?` on MySQL and SQLite, and each cast is the dialect's own.

Details

  • What counts as the leading comment (src/doc-comment.ts): the -- lines and /* … */ blocks before the first token, with the markers stripped and the lines kept. A blank line starts a new paragraph. Comments are read the way each dialect reads them:
    • Postgres nests block comments.
    • On MySQL, # starts a comment, -- starts one only when a space follows, and /*! / /*+ are code, not comments.
  • Code blocks: they leave out the leading comment.
    • A file with no comment still gets the code blocks.
    • A failed analysis still gets the prose and the statement as written. Its sql is plain string, so that doc carries only the prose and the note.
  • Query's own sql and raw lose their doc comments. TypeScript showed that generic text first and ran it into the module's doc in the same paragraph. The generic sentence now closes the module's sql and raw docs instead.
  • Escaping: a star followed by a slash is written with a backslash between them, so it cannot end the comment. The code fence is longer than any run of backticks in the statement. A fence the prose leaves open is closed before the code block.
  • Go-to-definition: the span map is one atom over the whole module, so the added lines move nothing.
  • Docs site: site/scripts/capture-types.ts writes the same doc comments and site/lib/sql-modules.json was captured again. With the comments stripped, the result is identical to main's. The Editors section mentions the hover.

Verified

  • tests/definition.test.ts hovers over the import and over .sql in the real tsc --lsp and checks the prose and both statements.
  • tests/doc-comment.test.ts unit-tests the comment reading and the escaping.
  • tests/compiled.test.ts checks the declaration text on SQLite, Postgres and MySQL.
  • Hovers checked by hand on Postgres 18, MySQL 8.4 and SQLite.
  • Gates typecheck, loader-tests (191 passed, 0 skipped), package and site all pass.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 18:18
@vercel
vercel Bot commented Oct 22, 2026 •
Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reylo Ready Ready Preview Oct 22, 2026 7:34pm UTC

Request Review

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pullfrog pullfrog Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues. Two rough edges are worth a look, inline.

Reviewed changes

This review covers the whole PR: three commits that add JSDoc to the module the content mapper writes, so a hover shows the .sql file's leading comment and its statement.

  • src/doc-comment.ts: new leadingComment / statementAfter / docComment. They read the leading comments the way each dialect does, and they escape */ and code fences.
  • src/mapper.ts: query, sql and raw (both the exports and the properties of the & { … } intersection, which is now multi-line) carry doc comments. The no-project path and the failed-analysis path get them too.
  • src/index.ts: Query.sql / Query.raw drop their own JSDoc, because the intersection hover would otherwise run it together with the module's doc.
  • site/scripts/capture-types.ts + site/lib/sql-modules.json: the docs-site capture mirrors the mapper, and the modules were captured again.
  • Tests: a doc-comment unit suite, a real tsc --lsp hover check, and updated compiled declaration assertions. tests/doc-comment.test.ts passes locally on Node 24. The LSP tests were not run here because dependencies weren't installed.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread src/doc-comment.ts Resolved
Comment thread site/scripts/capture-types.ts Resolved
@pullfrog pullfrog Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found. Both earlier threads are resolved.

Reviewed changes

This review covers the one commit since the last Pullfrog review (3755f40 → ba6adac).

  • Fixed summary() in site/scripts/capture-types.ts: it now matches declare const query: Query<…> & { at the end of its line, and the dialect strip anchors on "<dialect>"$. I checked this in Node against a multi-line declaration with nested generics. The capture log prints the one-line params/row/cardinality summary again.
  • Added an @-line hover check to tests/definition.test.ts: a SQLite add_post.sql whose @title / @body lines start with @. The test asserts that the import's hover ends with the whole sql block, which guards the TypeScript 7.1 behavior. I didn't run the LSP test here because node_modules isn't installed.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@colinhacks
colinhacks merged commit cb43f3e into main Oct 22, 2026
4 checks passed
@colinhacks
colinhacks deleted the statement-jsdoc branch October 22, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5878

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0