Removed 'goto' from 'LineFormatter' and other code refactorings#168
Removed 'goto' from 'LineFormatter' and other code refactorings#168AlexanderSher merged 11 commits intomicrosoft:masterfrom
Conversation
- Added TextEditCollectionAssertions - Various miscellaneous code clean-ups
|
Couple of follow-up questions:
|
| var tokenExt = new TokenExt { | ||
| Token = token, | ||
| PreceedingWhitespace = _tokenizer.PreceedingWhiteSpace, | ||
| PrecedingWhitespace = _tokenizer.PreceedingWhiteSpace, |
There was a problem hiding this comment.
Not a comment on your code, but "preceding" is misspelled in the tokenizer too and should probably be fixed at some point. (That's probably why I also misspelled it.)
There was a problem hiding this comment.
Public property of public class. @MikhailArkhipov , can we rename that?
Yes, I think that's correct. *a, b, c = [1, 2, 3, 4, 5]Where
My intention was to write a simple full-document formatter and potentially reuse the formatter for formatting of the same file multiple times (since tokens do not change), but I don't think either is really a good idea or practical. What it's doing right now is allowing for less-complicated logic for moving |
- Use `Range.ToString()` in tests - Add test case for `\r\n` line break (test fails).
- Made line 0-based, as it is in `Tokenizer` and LSP. - Removed `Peek` from `TokenizerWrapper` - it isn't needed, checking current token is enough. - Simplified the code by removing all usages of `SourceLocation` and `SourceSpan`: those types aren't required and conversion to `line/character` representation is needed only at the very end of `FormatLine` method. - Added `GetLineStartIndex` and `GetLineEndIndex` methods, cause `NewLineLocation` doesn't have that information. - Fixed `GrammarFile` test. It has been taking substring of length `end.character - start.character - 1`. `Range.end` is exclusive, so length should be calculated as `end.character - start.character` - Added couple of helper methods to the `Tokenizer`
So do we format code that has syntax errors?
Got it. |
The line formatter will run regardless of syntax. Unpacking was one of the pain points of Mikhail's original implementation in VS Code, and we essentially get this specific handling for free by using |
|
Yes we do format code with errors. Other editors do it too. |
Removed 'goto' from 'LineFormatter' and other code refactorings
This PR merges #162.
gotokeywords are removed,breakstatements that belong to theswitchflow are all straighten to avoid confusion withbreakstatements in loopsTextEditCollectionAssertionsto get better messages for test failures