Skip to content
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

Hide Stdlib in output #7305

Merged
merged 11 commits into from
Mar 11, 2025
Merged

Hide Stdlib in output #7305

merged 11 commits into from
Mar 11, 2025

Conversation

zth
Copy link
Collaborator

@zth zth commented Feb 17, 2025

This hides Stdlib prefixes in various outputs:

  • Error messages
  • Output from the editor tooling (hovers, completions, etc)

This is just a PoC/exploration, not sure if tis is how we want to solve this. But worth discussing the pros and cons.

cc @cristianoc, thoughts?

@zth zth force-pushed the hide-stdlib-in-output branch from 1874293 to 7bf0b50 Compare February 17, 2025 19:26
@zth
Copy link
Collaborator Author

zth commented Feb 17, 2025

cc @cknitt

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Syntax Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 4524ad3 Previous: 80744a5 Ratio
Parse RedBlackTree.res - time/run 2.1417238866666666 ms 1.87223692 ms 1.14
Print RedBlackTree.res - time/run 3.3576086933333333 ms 2.9391152133333334 ms 1.14
Print RedBlackTreeNoComments.res - time/run 3.0481397133333332 ms 2.693127673333333 ms 1.13
Parse Napkinscript.res - time/run 69.52510789333333 ms 60.98575317999999 ms 1.14
Print Napkinscript.res - time/run 113.42383125333333 ms 102.03488166 ms 1.11
Parse HeroGraphic.res - time/run 8.305685073333333 ms 7.62831228 ms 1.09
Print HeroGraphic.res - time/run 13.942951893333332 ms 12.308145193333333 ms 1.13

This comment was automatically generated by workflow using github-action-benchmark.

@@ -5,10 +5,10 @@ Definition src/Definition.res 10:23
{"uri": "Definition.res", "range": {"start": {"line": 6, "character": 7}, "end": {"line": 6, "character": 13}}}

Hover src/Definition.res 14:14
{"contents": {"kind": "markdown", "value": "```rescript\n(list<'a>, 'a => 'b) => list<'b>\n```\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) // list{3, 4}\n```\n"}}
{"contents": {"kind": "markdown", "value": "```rescript\n(List.t<'a>, 'a => 'b) => List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Stdlib_List.resi%22%2C36%2C0%5D)\n\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) // list{3, 4}\n```\n"}}
Copy link
Member

Choose a reason for hiding this comment

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

Why does list change back to List.t?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know, doesn't seem to happen locally for me. Will need to investigate if we decide to go this route.

@@ -571,8 +571,48 @@ let reset_and_mark_loops_list tyl =

(* Disabled in classic mode when printing an unification error *)

let remove_stdlib t =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering what's done for Pervasives, and there's some logic already around non_shadowed_pervasive, which could be adapted.

Copy link
Collaborator

@cristianoc cristianoc Feb 18, 2025

Choose a reason for hiding this comment

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

In general, I would do a search for the string "Pervasives" in the codebase, and see where there is logic to be copied.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great lead, will have a look!

@zth zth force-pushed the hide-stdlib-in-output branch from ef5af72 to 07ab10f Compare March 11, 2025 17:09
@zth zth requested a review from cristianoc March 11, 2025 17:29
@zth
Copy link
Collaborator Author

zth commented Mar 11, 2025

@cristianoc I changed approach to follow what's done for Pervasives, and this is much better. Please have another look and let me know what you think.

Comment on lines -66 to +74
| Pdot (_, s, _pos) as path when non_shadowed_pervasive path -> Oide_ident s
| Pdot (_, s, _pos) as path when non_shadowed_pervasive_or_stdlib path ->
Oide_ident s
| Pdot (p, s, _pos) when String.starts_with (Path.name p) ~prefix:"Stdlib_" ->
let path_name = Path.name p in
let ident_without_stdlib_prefix =
String.sub path_name 7 (String.length path_name - 7)
in
Oide_dot (Oide_ident ident_without_stdlib_prefix, s)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess we could list all Stdlib_* with proper idents here if we wanted..? Instead of doing a string match.

There's also the question of whether stdlib types should be dug to when possible (Date.t -> date), but that's probably a separate question from this PR.

Copy link
Member

Choose a reason for hiding this comment

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

And especially Promise.t -> promise as that's a built-in type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's a much better example, especially since date does not exist 🤦 😄

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Looks great.
I guess this fixes error messages too?

@zth zth force-pushed the hide-stdlib-in-output branch from 47fea5f to 00a8f1c Compare March 11, 2025 21:10
@zth zth marked this pull request as ready for review March 11, 2025 21:10
@zth zth merged commit 1d8560f into master Mar 11, 2025
20 checks passed
@zth zth deleted the hide-stdlib-in-output branch March 11, 2025 21:26
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.

3 participants