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

Implement on-type block formatting #165

Closed
jakebailey opened this issue Sep 27, 2018 · 1 comment
Closed

Implement on-type block formatting #165

jakebailey opened this issue Sep 27, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@jakebailey
Copy link
Member

jakebailey commented Sep 27, 2018

The VS Code extension provides an on-type formatter that triggers on : which allows for block formatting. For example, you can hit colon after the else in the following code:

if x:
    pass
    else

Which will then be reformatted into:

if x:
    pass
else:

This functionality should be implemented in language server for feature parity. The language server may even be able to handle more cases correctly than the extension's use of regex, since we have access to an AST.

Since on-type formatting has only one entrypoint (DocumentOnTypeFormatting), that function would need to map trigger characters to the right handler. A nicety would be to have a Dictionary of handlers, then produce the DocumentOnTypeFormattingOptions's trigger character members from that dictionary rather than needing to remember to change the characters in two different files.

Related to microsoft/vscode-python#2714.

@MikhailArkhipov
Copy link

MikhailArkhipov commented Oct 8, 2018

DonJayamanne pushed a commit to microsoft/vscode-python that referenced this issue Oct 9, 2018
For #2690.

Similar to #2612. Note that `:`-based formatting isn't implemented in language server yet (microsoft/python-language-server#165), but it hasn't been enabled in the extension for anyone for a while now either (fixed in #2714/#2724).

Since line formatting is relatively new in language server, this likely shouldn't make it out into a release until the language server downloaded by default is new enough to include that functionality. I haven't been monitoring that side of things, so feel free to hold off on merging this until the right time.
jakebailey pushed a commit to jakebailey/python-language-server that referenced this issue Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants