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

Broken source fixer #57

Merged
merged 26 commits into from
Dec 15, 2022
Merged

Broken source fixer #57

merged 26 commits into from
Dec 15, 2022

Conversation

asterite
Copy link
Collaborator

@asterite asterite commented Dec 5, 2022

This is for #55, but it's just a part of it.

This PR introduces a new type, BrokenSourceFixer. It tries to add missing "end" and closing curly braces based on the code's indentation. It assumes users will use two spaces of indentation and use the formatter so that everything is usually aligned except when they are typing an expression.

The idea then would be to run this code before feeing it to the parser, if the source code is actually broken (for that we could try to parse it and if it parses fine then there's nothing to fix.)

I didn't hook up the code yet because I wasn't sure exactly where to do that.

Edit: another thing is that the fixer tries not to add new lines. In that way any code that needs parse locations will still work fine, as the fixer only adds to the end of lines.

@asterite
Copy link
Collaborator Author

asterite commented Dec 5, 2022

Okay, things are hooked up now but probably not in the best way (there's a bit of repetition and you have to remember to call fix_source.)

In any case I can already showcase the improvements. Take a look at this:

image

It's autocompleting the x. thing even though the source has a lot of missing ends.

Or this:

image

It's showing the hierarchy at the top (Foo -> Bar -> foo) but the source is kind of broken.

Also "Go to definition" works fine in this state.

@asterite asterite changed the title WIP: Broken source fixer Broken source fixer Dec 6, 2022
@asterite
Copy link
Collaborator Author

asterite commented Dec 6, 2022

This is ready for review now. I've tried it with a bunch of files, removing "end" or curly braces, and it seems to be working fine.

One thing I noticed is that there weren't specs before so CI didn't run them. If we are going to have specs we might want to run them in CI.

@elbywan
Copy link
Owner

elbywan commented Dec 7, 2022

This is ready for review now. I've tried it with a bunch of files, removing "end" or curly braces, and it seems to be working fine.

Sorry busy week I won't be able to review until this week end, but it is looking great from what I read so far ❤️.

One thing I noticed is that there weren't specs before so CI didn't run them. If we are going to have specs we might want to run them in CI.

True! I'll plug a github actions workflow for that.

Copy link
Owner

@elbywan elbywan left a comment

Choose a reason for hiding this comment

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

Looks perfect to me, this is a great addition! 👍

If we are going to have specs we might want to run them in CI.

It should be allright now, the CI runs specs as a required check ✔️ (which is actually pending for this PR since the workflow did not exist at the time of the latest commit)

end

private def self.line_keyword(line : String) : String?
if line.starts_with?(/\s*
Copy link
Owner

Choose a reason for hiding this comment

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

would it make sense to add begin to the list as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, good catch! I think I also missed macro, and rescue/ensure/else for begin and def. I'll add those on Monday.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done! I forgot to mention that Mondays happen on Wednesday in Argentina.

Copy link
Owner

@elbywan elbywan Dec 15, 2022

Choose a reason for hiding this comment

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

I forgot to mention that Mondays happen on Wednesday in Argentina.

Haha no worries in France we have the same concept 😄.

I'm not seeing any new commits though, did you forget to push by any chance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I pushed to this repo instead of the fork. Now it's done.

@elbywan elbywan merged commit 0b87573 into elbywan:master Dec 15, 2022
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