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

Add fault tolerant parsing for case expressions #3978

Open
GearsDatapacks opened this issue Dec 11, 2024 · 11 comments
Open

Add fault tolerant parsing for case expressions #3978

GearsDatapacks opened this issue Dec 11, 2024 · 11 comments
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:high

Comments

@GearsDatapacks
Copy link
Member

Currently, case something is a syntax error (obviously). The problem is, the language server cannot provide autocomplete when typing the subject of the case expression. We could make this fault tolerant in the same way as record., to allow for a better LSP experience.

@giacomocavalieri
Copy link
Member

Love this! It would be a huge dx win

@lpil lpil added help wanted Contributions encouraged good first issue Good for newcomers priority:high labels Dec 16, 2024
@lpil
Copy link
Member

lpil commented Dec 16, 2024

Definitely!

@giacomocavalieri
Copy link
Member

I can think of two ways of approaching this, which one do you think would be best?

  1. Syntactically allow writing case wibble (with no curly braces) and turn the syntax error into a missing patterns error. Since a case subject is already fault tolerant one would be able to hover over the subject to get its type, trigger code actions, and get completions for free!
  2. Keep case wibble a syntax error and change the completer to work around the syntax error inspecting the code around the cursor.

To implement 1, one would have to change the parser and nothing much besides that, everything else should already be in place to make it work. I'm not really sure how 2 could be implemented, I haven't looked much at the completer

@GearsDatapacks
Copy link
Member Author

1 is probably easier, that's how we handle wibble.. I think that's fine unless Louis has any objections.

We would need to be careful though, because some code actions (such as fill missing patterns) rely on the syntax being well formed, and saying that this syntax is valid could lead to odd behaviour there.

@giacomocavalieri
Copy link
Member

That's great to know! Would you like to work on this or can I give it a try today?

@GearsDatapacks
Copy link
Member Author

I'm still away for a the next couple of days, so I won't be able to work on it much until next week. Go for it if you want to!

@lpil
Copy link
Member

lpil commented Jan 4, 2025

Sounds good to me, but we are going to need to introduce some capability for fault tolerant parsing in the future also.

@GearsDatapacks
Copy link
Member Author

That's true. We could either do that as part of this, or separately, in preparation for future fault tolerance.

I presume we would do it in a similar way to analysis fault tolerance?

@giacomocavalieri
Copy link
Member

A small report, I tried going for the easy implementation but as usual the devil's in the details 😆
What happened is it made errors worse in some cases. For example if one writes this:

case 1, test {

}

case 1 would now parse correctly as a valid case expression and give an error at test with a confusing message.

@GearsDatapacks
Copy link
Member Author

Interesting. Surely you could write it in such a way that it would be greedy and parse all subjects before checking for curly braces?

@giacomocavalieri
Copy link
Member

Yeah I'll try that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:high
Projects
None yet
Development

No branches or pull requests

3 participants