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

Complete switch constructor #415

Merged
merged 12 commits into from
May 12, 2022
Merged

Complete switch constructor #415

merged 12 commits into from
May 12, 2022

Conversation

cristianoc
Copy link
Collaborator

No description provided.

Complete tests/src/Completion.res 362:8
posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3]
posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3]
XXX Pexp_match with 1 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This shows that parser recovery leads to a single case being considered in the switch.

Complete tests/src/Completion.res 367:30
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:11->367:30]
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->367:30]
XXX Pexp_match with 1 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This shows that parser recovery also gives 1 case when no more cases others follow.

Complete tests/src/Completion.res 372:8
posCursor:[372:8] posNoWhite:[372:7] Found expr:[370:8->376:3]
posCursor:[372:8] posNoWhite:[372:7] Found expr:[371:2->376:3]
XXX Pexp_match with 2 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This example confirms that the first 2 cases are squashed into one.

XXX Pexp_match with 1 cases not handled
XXX first case pattern:[362:7->364:5] expression:[364:9->364:10]
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5]
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the location, this could be the pattern T.

XXX first case pattern:[362:7->364:5] expression:[364:9->364:10]
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5]
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8]
XXX Ppat_construct T:[362:7->362:8]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed here's the T pattern.

posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3]
posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5]
posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21]
XXX Ppat_construct AndThatOther.T:[373:7->373:21]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like we can catch more complex paths too.

Printf.printf "XXX Ppat_construct %s:%s\n"
(lidPath |> String.concat ".")
(Loc.toString lid.loc);
setResult (Cpath (CPId (lidPath, Value)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Triggering completion as a Value. There's no need for specific completions for Constructor because of the upper case. Lower-case ids are normal values, and upper-case values are constructors.

"detail": "That\n\ntype v = This | That",
"documentation": null
}, {
"label": "This",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This and That are found as expected.

"detail": "This\n\ntype v = This | That",
"documentation": null
}, {
"label": "TableclothMap",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a module starting with T which happens to be in scope.
This is accurate, as the user might be in the process of writing ThatSpecificModule.SomeConstructor.

Choose a reason for hiding this comment

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

I disagree with this, except in the rare case where the type of the switch variable is not known (because it might be used to disambiguate, as you suggested). That should only happen once, or in many cases never.

My understanding is that once the type is known the compiler no longer needs disambiguation to find constructors. At that point seeing all scope modules in the autocomplete list is just noise.

https://rescript-lang.org/try?code=LYewJgrgNgpgBAeQC4AsYCc4F44G8BQccSAngA7wBu2iAdvAD5wAqA7iHE8yujDIXFhI4AMxqUAhlAjwsAPgFEAzqwCWSAMYo4k6fAJEiAeiNxaHMKqUTgAI1UBzCBKSqQtRZzqy5cAIyeXOzYvgBMgSw8fCFwAMyeAL74SfhCouJSMiECKupaOpn6AiZwSqq0DrBwltZ2js6u7gJMyGjoAHQI9DEBREEc8nDhfZG8PnECSUA

I'm about to start looking at how to remove modules from the autocomplete list in this scenario, but now I realise it was intentional... can we discuss whether removing them is a good idea?

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 you're interested in type contexts, here: #494
Not this PR.

Choose a reason for hiding this comment

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

I am, but then I found this PR and it looked like completion in switch statements already included all the valid constructors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an ongoing process. Not everything is at the level it could be.
In the process, some techniques have been used to aid autocompletion where the alternative would be to get nothing.

@@ -1030,6 +1030,7 @@ Completable: Cpath Value[SomeLocal]
}]

Complete tests/src/Completion.res 271:20
posCursor:[271:20] posNoWhite:[271:19] Found pattern:[271:7->274:3]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This, and other similar lines indicate that this affects a bit existing test cases, but does not lead to a different outcome.
It just means that the relevant type, found below, happens to be inside a pattern containing the cursor.

@cristianoc cristianoc merged commit 34ace4b into master May 12, 2022
@cristianoc cristianoc deleted the complete_switch_constructor branch May 12, 2022 08:01
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