Skip to content

Conversation

mediremi
Copy link
Member

@mediremi mediremi commented Jul 4, 2025

This change improves inline record completions by:

  1. showing the inline record's type when completing constructor payloads
  2. showing each field's type for field completion
Before After
image image
image image

These changes were implemented by reusing the completion logic used for records.

Explanation

While we currently show completions for record fields by creating a Field field completion for each field...

fields
|> List.filter (fun (field : field) ->
List.mem field.fname.txt seenFields = false)
|> List.map (fun (field : field) ->
match (field.optional, mode) with
| true, Pattern Destructuring ->
create ("?" ^ field.fname.txt) ?deprecated:field.deprecated
~docstring:
[
field.fname.txt
^ " is an optional field, and needs to be destructured \
using '?'.";
]
~kind:
(Field (field, TypeUtils.extractedTypeToString extractedType))
~env
| _ ->
create field.fname.txt ?deprecated:field.deprecated
~kind:
(Field (field, TypeUtils.extractedTypeToString extractedType))
~env)
|> filterItems ~prefix

... for inline records we only emit Label "Inline record":

|> List.map (fun (field : field) ->
create field.fname.txt ~kind:(Label "Inline record")
?deprecated:field.deprecated ~env)

In commit 1b0296c, I copied the completion logic for records over to the inline records handler. I also added completion tests for inline records.

Then in commit 2758057, I extracted the common logic into a helper function called getRecordCompletions.

@mediremi mediremi marked this pull request as ready for review July 4, 2025 18:28
Copy link

pkg-pr-new bot commented Jul 4, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7601

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7601

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/win32-x64

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

commit: 328a3eb

Copy link
Member

@zth zth left a comment

Choose a reason for hiding this comment

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

Fantastic, that's awesome! Nice work!

@zth zth merged commit 8b2f3f5 into rescript-lang:master Jul 4, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants