-
Notifications
You must be signed in to change notification settings - Fork 510
Add code formatting presets #893
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
Conversation
], | ||
"default": "Custom", | ||
"description": "Sets the codeformatting options to follow the given indent style in a way that is compatible with PowerShell syntax. For more information about the brace styles please refer to https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81." | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we point to this or create some documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use this link for now until we get our own documentation together.
@@ -412,6 +412,16 @@ | |||
"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.preset": { | |||
"type":"string", | |||
"enum": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, I was looking for how to do the enum values and couldn't find it!
Nice work! |
Can we add a |
BTW I just did a git pull in both vscode-powershell and PSES but when I try to format code, I get an error indicating I missing a command |
Ahhh, I didn't look very closely at what Allman was :) Yeah, we should definitely have an additional preset for Stroutsroup. Also, should we rename OTBS to 1TBS? The Wikipedia article prioritizes the latter acronym: |
BTW I don't mind adding the support for Stroustrup, if that's OK with you guys. I assuming it will be pretty easy. :-) |
Invoke-Formatter comes from PSScriptAnalyzer 1.14, but I think Kapil's using some changes that will appear in 1.15. You might need to clone/build PSScriptAnalyzer for it to work |
Go for it man, that would be great! |
I went through the indent styles and I see that most PS script are not really Stroustrup but OTBS with Stroustrup else/elseif/catch/finally. The issue here also mentions the same. So maybe calling it |
Regarding |
Looks like the Stroustrup style in http://eslint.org/docs/rules/brace-style doesn't treat function declarations in a different way. If we want to use the style defined in the link as reference then I think the |
@kapilmb That is what I was thinking. Some folks will probably get a bit pedantic about it but I'm not finding a good "name" for this other than |
I agree |
Sounds good to me! |
Sounds good. So I've built PSSA and verified that I'm invoking the one I built but I get an error about the range parameter:
I also get a similar error inside VSCode. I've built the That said, if it would be easier for you to add this setting, go for it. I originally thought I would be updating something in the VSCode extensions TS files. I'm guessing that the only thing we need to do is copy the CodeFormattingOTBS.psd1 to CodeFormattingStroustrup.psd1 and change this one setting:
And update the vscode-powershell package.json/setttings.ts files. Right? Hmm, I could easily do this but I'm a bit nervous about not being able to test the changes. Any idea why the Range parameter error is happening. Do I not have the right "format": startLine, startCol, endLine, endCol? |
Two issues here:
The formatting changes are there in the Invoke-Formatter (Get-Content .\DebugTest.ps1 -raw) $settings 22,1,26,1 The original goal was to just create a settings file in PSScriptAnalyzer and let vscode extension use it as preset, with minor changes to settings.ts and package.json. But I soon realized that the settings files are static and the
On the PSSA-side you are right that we only need to make a copy of the OTBS psd1 file but we need to change the Regarding adding the setting, I am fine with either ways - either you add it or I add it. Let me know what you prefer. |
I've submitted a PR for vscode-powershell. I'll submit one shortly for PSES. Thanks for the tip on not using a path. My debugTest.p1 had those extra lines because I added an if/else statement to the bottom of the file - just for testing. :-) |
BTW am I getting the settings correctly in PSSA? I'm using: $settings = iex (gc .\settings\CodeFormattingStroustrup.psd1 | out-string) which results in $settings containing the hashtable. |
yeah, I think that should work. The
|
Adds the following presets for code formatting:
Related PRs:
PowerShell/PSScriptAnalyzer#784
PowerShell/PowerShellEditorServices#521