-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Rewrite fluid match pattern reconstruction #4513
Rewrite fluid match pattern reconstruction #4513
Conversation
Now, this better matches how we do this for exprs
I'm currently working through the outlined TODOs, but think that this is at a good place for an initial review. |
I'm having to revert this, as |
Along the way, correctly tokenize match expr cases that are after the first case. (fix a bug)
// this is only used for FluidDebugger. TODO: consider removing? Not sure why | ||
// we have this separate tokenizer - when would we have a FF but no expr | ||
// corresponding to the expr's ID? | ||
let tokenizeExprForDebugger = (e: FluidTypes.Editor.t, ast: FluidAST.t): list< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outstanding question - why do we need this separate tokenizer?
when would we have a FF but no expr corresponding to the expr's ID?
0cd71f1
to
e07c198
Compare
Yes, I've been thinking the same thing for weeks, I'm surprised I didn't actually mention it. There are a few places where we could use partial expressions to get better results, and we would want those in patterns as well, see #4494, #4493, and #4499.
With this sort of thing, I can't really tell in the abstract. If you have some examples I'd be better able to give an opinion.
Yes, I agree. I was trying to say something like this before, how maybe we could use caretTargets for this. Unsure if that's appropriate, but I agree the strong approach is untenable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good.
This PR has now accomplished its goals - original screenshot shows the main difference (able to reconstruct partially-selected match patterns), and everything is well-tested. |
Will look shortly. I agree with the new behaviour in the screenshots. |
Reconstruction (what happens when you copy/paste some Dark code) of Exprs has been generally solid in Fluid, but the implementation for reconstructing match patterns was hacky, and did not support reconstructing only some of a nested pattern (i.e. if a Tuple pattern or Constructor pattern was partially highlighted when cutting/copying, the whole thing would be reconstructed - even the unselected parts).
This is how it used to operate:
and here's with the fix
This broke down as follows:
FluidTokenization.res
, organize the code to have all of the actual 'tokenization' be in one area visually.match
expr)FluidTokenization.tokensForEditor
to.tokenizeForDebugger
previously, we had
tokensForEditor
andtokenizeForEditor
- I found this pretty confusing.TODOs:
based on the below feedback, potentially remove mentions of non-existantEdit: will leave the comments in, and follow up here soon when MPPartials are implemented.MPPartial
, and just commit to the logic we agree upon.In this re-implementation, I've reached for something like a
MPPartial
a few times - EPartials are used in reconstruction often when we've highlighted just part of a pattern, resulting in a way for the user to 'correct' the reconstructed code. For match pattern reconstruction, I've had to work around this. Would it make sense to add an MPPartial at some point?In the meantime, here are the cases where I reached for MPPartial:
Null
patternmy thought: reconstruct with a
Null
patternBool
pattern (with a value oftrue
orfalse
)my thought: reconstruct with the appropriate
Bool
patternConstructor
patternmy thought: reconstruct with a
Blank
patternWhat do you think about these cases?
When reconstructing a
match
, here's the logic to choose whichcases
should be reconstructed or skipped:This was recently (in a previous PR) written to match some previous logic.
I think this is generally appropriate, but wanted to get some input on the third branch:
| (None, Some(_expr)) => None
If we were able to reconstruct some Expr, but not reconstruct the Match Pattern (i.e. if you select the expr "downwards"), we don't create the new case. I don't think that makes sense - rather, I'd expect us to reconstruct a new
case
, but with aBlank
pattern. What do you think about this branch?I've lately become increasingly wary of searching for these magic strings
"match-pattern-variable"
withinFluid.res
. I'm tempted to create a copy of theFluidTypes.Token.t
which doesn't have the internals, and is a simple DU to use in these cases. That wouldn't help the existing CSS usages of the magic strings, but those are pretty rare anyway.