Skip to content

Add feature to format PowerShell source files #426

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

Merged
merged 20 commits into from
Jan 17, 2017
Merged

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Jan 12, 2017

@daviwil
Copy link
Contributor

daviwil commented Jan 12, 2017

Really happy to have this feature now! I think we need to take a slightly different approach with the client/server protocol for this to align with the Language Server Protocol since they've already specified the message types for document and range formatting. I'm happy to chat about it tomorrow at the office if you have questions.

@@ -270,6 +270,21 @@
"type": "boolean",
"default": false,
"description": "Launches the language service with the /waitForDebugger flag to force it to wait for a .NET debugger to attach before proceeding."
},
"powershell.codeformatting.openBraceOnSameLine":{
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice if codeformatting was cased as codeFormatting, but it's not a big deal if you don't feel like changing it right now

Copy link
Author

Choose a reason for hiding this comment

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

fixed!

@@ -0,0 +1,277 @@
import vscode = require('vscode');
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget the copyright header

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

"PSUseConsistentIndentation"];

// Allows edits to be undone and redone is a single step.
// Should we expose this through settings?
Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, I'd say that the formatting operation should always be treated as one atomic edit.

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

document: TextDocument,
range: Range,
options: FormattingOptions,
index: number): Thenable<TextEdit[]> | TextEdit[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we could simplify this code a lot by using the TextEdit class as the means for transporting the formatting edits back and forth between extension and server. Check out VS Code's TextEdit class compared to the one we have in the Protocol assembly, they are exactly the same.

I'd recommend pushing as much of this logic to the service side as you can and only sending back the valid TextEdits from the server which will be applied by the client. In fact, I think we should implement this based on the exact protocol messages that are coming in the Language Server Protocol 3.0 since we'll be snapping to that pretty soon anyway. Check these out:

https://github.com/Microsoft/language-server-protocol/blob/master/versions/protocol-2-x.md#textDocument_formatting

The request type is fairly similar to yours now and the response type is simply an array of TextEdit. Implementing it this way will future-proof us a lot better.

@daviwil
Copy link
Contributor

daviwil commented Jan 13, 2017

Kapil and I discussed the protocol changes I asked for, we're going to wait until the next extension update for that work. I'll merge this PR and the one on PSES after the PSScriptAnalyzer PR gets merged.

@daviwil
Copy link
Contributor

daviwil commented Jan 17, 2017

Great work! I'll play around with this a bit later today.

@daviwil daviwil merged commit 37ad0e3 into master Jan 17, 2017
@daviwil daviwil deleted the kapilmb/code-formatting branch January 17, 2017 20:03
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.

3 participants