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

Improvements to multiline type/data declarations #147

Merged
merged 4 commits into from
May 2, 2020

Conversation

sheaf
Copy link
Collaborator

@sheaf sheaf commented May 1, 2020

Quite a lot of changes in this one:

  • There was a really annoying bug with data declarations indentation tracking, because of the typo (\s)* instead of (\s*), so we were capturing a single space of indentation as opposed to the whole indentation. Fixing this means indented data declarations now work properly (fixing Typeclasses with exactly one declaration don't highlight properly #91 for good).
  • Data instance / newtype instance declarations are now highlighted properly (just re-use the code for data/newtype).
  • Multiline type and data declarations work a lot better now, including allowing comments. It even skips over lines which just consist of a -- comment. This is done with the \s*-*--(?![\p{S}\p{P}&&[^(),;\[\]`{}_"']]).*$ regexp. Unfortunately I can't skip over block comments because I can't do that computation in a regular expression. Edit: Not true as pointed out below, now block comments supported too.
  • Fixes the = sign not always being properly highlighted in multiline type declarations. Brought to my attention by Line breaks breaks type synonym highlighting #146 (added three test cases to completely cover the different situations).

Fixes test cases Comments, Keywords, T0091.

@sheaf sheaf requested a review from JustusAdam May 1, 2020 17:24
@sheaf
Copy link
Collaborator Author

sheaf commented May 1, 2020

Oops looks like I broke something with newtype declarations, working on a fix.

@sheaf sheaf marked this pull request as draft May 1, 2020 17:48
@JustusAdam
Copy link
Owner

Hey this looks like good work 👍

I think we can deal with block comments. We can add block_comment to the patterns. The begin from block_comment will match, resulting in the block_comment multiline match taking over from the one from type/data. This means so long as the block comment has not ended the end pattern from the outer multiline match will not trigger. Once the block comment finishes the outer match should take over again.

@sheaf sheaf marked this pull request as ready for review May 1, 2020 18:20
@sheaf
Copy link
Collaborator Author

sheaf commented May 1, 2020

I fixed the breakage with newtypes and I added your suggestion regarding block comments, which seems to work nicely! I didn't realise the outer match would take over again like that.

Edit: Added changelog entry.

@JustusAdam
Copy link
Owner

Yeah, I don't think they even document those mechanics. I only frustratingly found out in bugs where you have to repeat the end condition because otherwise it never terminates the outer condition.

@sheaf sheaf merged commit b39c52a into JustusAdam:master May 2, 2020
@JustusAdam
Copy link
Owner

Oh. Thanks for fixing it. 😅 I had some issues trying to get the test runner working locally

@sheaf
Copy link
Collaborator Author

sheaf commented May 3, 2020

The issue was that you accidentally removed the name: meta.declaration.adt.haskell scope, so one of the tests failed. The test output should be more readable now, so you should be able to make sense of the tests without needing to run them locally.

@sheaf sheaf deleted the multiline branch May 15, 2020 23:49
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