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

feature: Suggest candidates when alias not found #7004

Conversation

Alizter
Copy link
Collaborator

@Alizter Alizter commented Feb 5, 2023

We now suggest candidates when an alias is not found. Error messages look like:

$ dune build @fou
Error: Alias "fou" specified on the command line is empty.
It is not defined in . or any of its descendants.
Hint: did you mean fmt or foo?
[1]
  • changelog
  • tests

bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from 9e0d15e to 1e9854a Compare February 5, 2023 18:55
@Alizter Alizter marked this pull request as ready for review February 5, 2023 18:56
bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter requested a review from rgrinberg February 5, 2023 18:57
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch 3 times, most recently from 24707b7 to b295392 Compare February 9, 2023 15:20
@Alizter
Copy link
Collaborator Author

Alizter commented Feb 9, 2023

@emillon Would you like this in 3.7?

@emillon
Copy link
Collaborator

emillon commented Feb 9, 2023

That's "just" a CLI change that's low risk but still a UX improvement so yes I don't mind including it.

bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from b295392 to 3029fe6 Compare February 9, 2023 19:29
bin/alias.ml Outdated
~f:(fun _ a _ -> Some a)
build.aliases (aliases t)
| _ :: t -> aliases t
| _ -> Alias.Name.Map.empty
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is right. You should use --context or default to make the suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed in chat, getting hold of context_arg from the CLI is a bit tricky here as I would have to thread it through unrelated places.

bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from 3029fe6 to d02575a Compare February 12, 2023 17:33
@Alizter
Copy link
Collaborator Author

Alizter commented Feb 12, 2023

So there is an issue with this PR as pointed out by Rudi. The suggested aliases will only appear from the first context considered when generating the hints. However for most users, I feel as though this will not matter. The correct fix IMO, would be to get hold of Common.context_arg globally and pick the currently selected context for generating the hints. I don't think I will do that in this PR however.

@Alizter Alizter added this to the 3.7.0 milestone Feb 12, 2023
@@ -0,0 +1,8 @@
Dune should suggest similar aliases when it cannot find one.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you turn that into a file cram test ? (alias-candidate.t with cat > dune and cat > dune-project in it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, but why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's fewer files, tests are more self-contained. I think we said we now prefer that for new tests.

@emillon
Copy link
Collaborator

emillon commented Feb 13, 2023

This is an improvement even if it's not correct in the presence of several contexts. Fine to include it but please write a ticket or a test to document the followup. Or postpone to 3.8 as you prefer.

@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from d02575a to adcd3a5 Compare February 13, 2023 14:05
@Alizter
Copy link
Collaborator Author

Alizter commented Feb 13, 2023

@emillon I'll write a ticket for the followup.

#7060

@rgrinberg
Copy link
Member

The bigger problem with this feature is that it doesn't list the aliases defined in subdirectories. We might want to leave a note on that.

@Alizter
Copy link
Collaborator Author

Alizter commented Feb 14, 2023

OK I've decided against including this in 3.7. Let me implement this properly in 3.8.

@Alizter Alizter modified the milestones: 3.7.0, 3.8.0 Feb 14, 2023
@emillon
Copy link
Collaborator

emillon commented Apr 19, 2023

@Alizter what do you want to do about this one for 3.8?

@Alizter Alizter modified the milestones: 3.8.0, 3.9.0 Apr 19, 2023
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from adcd3a5 to 5338d67 Compare July 12, 2023 14:06
@Alizter
Copy link
Collaborator Author

Alizter commented Jul 12, 2023

So updating my position on this PR. @rgrinberg asked to limit the alias query to the build context however this doesn't make sense to me for a few reasons.

  1. dune build doesn't take --context the closest is -x.
  2. Aliases passed to dune build build in all contexts.

Therefore I think the status of the PR is good and ready to go.

@ocaml-benchmarks
Copy link

#7004 (5338d67) changes the metrics as follows in comparison to main (4256431) when running on fermat (bench/monorepo/bench.Dockerfile):

Benchmark: default

Test: dune monorepo benchmarks

  • build from scratch changed by 2.0%
  • null build changed by -5.2%
  • watch mode: changing file in 'base' library changed by 1.3%
  • watch mode: changing file in 'file_path' library changed by 0.8%
  • watch mode: fixing error in file in 'base' library changed by -2.4%
  • watch mode: fixing error in file in 'file_path' library changed by 0.3%
  • watch mode: introducing error in file in 'base' library changed by -2.3%
  • watch mode: introducing error in file in 'file_path' library changed by -8.2%

@ocaml-benchmarks
Copy link

#7004 (7864e0d) changes the metrics as follows in comparison to main (a0145b2) when running on fermat (bench/monorepo/bench.Dockerfile):

Benchmark: default

Test: dune monorepo benchmarks

  • build from scratch changed by 5.0%
  • null build changed by 3.9%
  • watch mode: changing file in 'base' library changed by -0.4%
  • watch mode: changing file in 'file_path' library changed by -5.4%
  • watch mode: fixing error in file in 'base' library changed by -2.8%
  • watch mode: fixing error in file in 'file_path' library changed by -3.2%
  • watch mode: introducing error in file in 'base' library changed by 1.2%
  • watch mode: introducing error in file in 'file_path' library changed by -12.3%

@Alizter Alizter requested review from emillon and rgrinberg July 14, 2023 12:01
bin/alias.ml Outdated Show resolved Hide resolved
Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Not perfect, but good enough for now. Some stylistic issues.

bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch 5 times, most recently from c44ec51 to fad6141 Compare October 20, 2023 14:35
@Alizter
Copy link
Collaborator Author

Alizter commented Oct 20, 2023

@rgrinberg I've made the stylistic changes you suggested and updated the changelog to the new directory.

CHANGES.md Outdated
@@ -331,6 +331,8 @@ Unreleased
- Bump minimum version of the dune language for the melange syntax extension
from 3.7 to 3.8 (#7665, @jchavarri)

- Dune now suggests other aliases when an alias is not found (#7004, @Alizter)
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't need a CHANGES entry

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 think this comment is out of date since I moved the changelog to its own file before you reviewed. Are you also suggesting I remove that?

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've removed that too for now, if we need a changelog we can just write a new one at a later date.

Copy link
Member

Choose a reason for hiding this comment

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

We usually don't write CHANGES entry for error message improvements

bin/alias.ml Outdated Show resolved Hide resolved
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from fad6141 to ed57ce5 Compare October 23, 2023 12:39
Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the ps/rr/feature__suggest_candidates_when_alias_not_found branch from ed57ce5 to 12c9365 Compare October 23, 2023 12:41
@Alizter
Copy link
Collaborator Author

Alizter commented Oct 23, 2023

@rgrinberg I've removed the changelog entry and refactored the accumulation of name suggestions to use a much shorter Alias.Name.Set.union_map.

@rgrinberg rgrinberg merged commit af9e838 into ocaml:main Oct 24, 2023
20 checks passed
@Alizter Alizter deleted the ps/rr/feature__suggest_candidates_when_alias_not_found branch October 24, 2023 09:52
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