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

(GH-1417) Fix code folding on CRLF documents #1418

Merged
merged 5 commits into from
Jul 11, 2018

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Jul 10, 2018

PR Summary

Previously the folding provider would tokenize the entire document at a time.
While this mostly works, it causes issues with regular expressions which use the
$ anchor. This anchor will interpret CRLF vs LF differently. While it may be
possible to munge the document prior to tokenization, the prior art within the
VS Code codebase shows that this is not the intended usage, i.e. lines should be
tokenized, not an entire document. This commit changes the tokenization process
to tokenize per line but still preserves the original folding behaviour.

This PR also updates the test fixtures used to be more robust and DRY.

Fixes #1417

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

Previously the folding provider would tokenize the entire document at a time.
While this mostly works, it causes issues with regular expressions which use the
`$` anchor.  This anchor will interpret CRLF vs LF differently. While it may be
possible to munge the document prior to tokenization, the prior art within the
VS Code codebase shows that this is not the intended usage, i.e. lines should be
tokenized, not an entire document.  This commit changes the tokenization process
to tokenize per line but still preserves the original folding behaviour.
Previously the test fixtures were failing on some Windows systems due to git
changing the line endings.  This commit adds a new test fixture, and runs the
same tests on the same content document, but each with a different line-ending
(CRLF and LF).
Previously some of the text in the test fixtures was confusing e.g. Text that
says 'cannot fold' should read 'should fold'.  This commit updates the text in
the fixture to describe the expected behaviour for humans.
Previously only single quoted here strings were tested for folding.  This commit
adds a test for the double quoted herestrings as well.
Previously there was some duplication in the folder test fixtures.  This commit
refactors the expectation to be more DRY.  This commit also adds an expectation
on the line endings as we're depending on git to clone correctly.  Without this
we may get false positive results.
@glennsarti glennsarti changed the title WIP (GH-1417) Fix code folding on CRLF documents (GH-1417) Fix code folding on CRLF documents Jul 11, 2018
@glennsarti
Copy link
Contributor Author

Ping @rkeithhill and @rjmholt

@glennsarti
Copy link
Contributor Author

Ready to throw the switch

light is green, trap is clean

// Note that line endings (CRLF/LF/CR) have interpolation issues so don't
// tokenize an entire document if the line endings are variable.
const tokens: ITokenList = new Array<IToken>();
let tokenizationState = null;
Copy link
Contributor Author

@glennsarti glennsarti Jul 11, 2018

Choose a reason for hiding this comment

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

Should I create an interface for this...Doesn't seem like I really need to....

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

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

LGTM

@rjmholt rjmholt merged commit 84e4ec6 into PowerShell:master Jul 11, 2018
@lucdekens
Copy link

Did this break #region - #endregion folding in VSC 1.25.1?

@rkeithhill
Copy link
Contributor

Yes it did. See #1430 for the fix - not yet merged.

@lucdekens
Copy link

lucdekens commented Jul 13, 2018

Thanks, I'll go back to pre-1.8.0 till the fix is merged

@glennsarti
Copy link
Contributor Author

@lucdekens You can also just disable the syntax folding so you can still get all the bugfixes etc. in 1.8.0 but not the folding.

powershell.codeFolding.enable": false,

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.

Code provider folding is not folding here strings
4 participants