Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Port regex-based block formatting from vscode-python #217

Merged
merged 5 commits into from
Oct 9, 2018

Conversation

jakebailey
Copy link
Member

Updates #165.

This is a 1:1 port of the : triggered block formatter that's running in the extension, including its tests. See here for the current implementation:

This may not be the most efficient or most correct way to do this sort of formatting, but not having any block formatting in PLS means that we can't also ship the line formatting code. This will at least behave the same way and let us ship the new line formatter without regressing the editor in terms of features. This can be replaced later with something that uses the tokenizer/parser to act much more generally.


[TestMethod, Priority(0)]
public async Task FirstLine() {
using (var reader = new StringReader("")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need using for StringReader when it is used explicitly. It doesn't hold any resources.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can certainly remove it, but I'm a little bit wary of not disposing of it just because we know it doesn't do anything given that a future .NET release could easily implement it differently.

Copy link

@MikhailArkhipov MikhailArkhipov Oct 9, 2018

Choose a reason for hiding this comment

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

If you are really concerned about resources, then use string.Empty and not "" ;-)
Actually, I believe it used to be disposable and held resources back in a day, but not anymore and no one disposes of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's disposable because it's a subclass of TextReader, which is IDisposable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll fix that string.Empty thing though. Muscle memory from other languages which don't allocate an empty string...

@jakebailey jakebailey merged commit ac25dfb into microsoft:master Oct 9, 2018
@jakebailey jakebailey deleted the block-formatting-port branch February 14, 2019 20:12
jakebailey added a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
* port block formatting on colon from vscode-python

* port tests

* basic check in LanguageServerTests

* split apart LanguageServer tests for OnTypeFormatting

* string.Empty instead of empty literal
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants