Skip to content
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

Add request handlers for document formatting #516

Merged
merged 27 commits into from
Jun 14, 2017
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4c6b4f4
Add stub to handle formatting request
May 30, 2017
ca1f97e
Add handler to format document with default settings
Jun 7, 2017
78ad540
Add formatting related types
Jun 7, 2017
2a83b0f
Remove unused handler from LanguageServer
Jun 7, 2017
44ca6b3
Fix DocumentFormattingParams request type
Jun 7, 2017
0b8e8a2
Add a method to enumerate PSScriptAnalyzer cmdlets
Jun 7, 2017
f09d70c
Execute formatter only if module is present
Jun 7, 2017
3da17ee
Handle null value returned by formatter
Jun 7, 2017
7c3ebf8
Add all formatting types and requests
Jun 7, 2017
2f50051
Convert Range type to class from struct
Jun 7, 2017
d8bf331
Update AnalysisService.Format method
Jun 7, 2017
39d69d4
Add range formatting capability to the server
Jun 7, 2017
d00e2ca
Fix format wrapper method
Jun 7, 2017
c4e8866
Disable server side range formatting
Jun 9, 2017
d799a88
Add CodeFormattingSettings type
Jun 10, 2017
466248e
Make properties of FormattingOptions type public
Jun 10, 2017
fb63ff7
Provide settings for formatting
Jun 10, 2017
9eb1b11
Create an abstract base class for settings
Jun 10, 2017
4c1a861
Create a class to represent editor settings
Jun 10, 2017
404b0ae
Disable server side document formatting capability
Jun 13, 2017
ebb6f03
Capitalize options property in FormattingOptions
Jun 13, 2017
0ebfb5e
Send a range array to Format method
Jun 13, 2017
efd884f
Fix merge conflict in LanguageServer.cs
Jun 13, 2017
2851e80
Remove AbstractSettings base class
Jun 13, 2017
6ac7b0d
Update inline xml documentation
Jun 13, 2017
7fc858b
Remove unused request type and its handler
Jun 13, 2017
d74d369
Fix test failures
Jun 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update AnalysisService.Format method
The format method now takes start/end line/column numbers to allow formatting in a given range. We cannot use Range type in AnalysisService form some strange reason, probably because it leads to circular dependency. Therefore we resort to passing in the integer parameters.
  • Loading branch information
Kapil Borle committed Jun 7, 2017
commit d8bf33169c58e807f2bbd22bf78bc14581ae4f0d
14 changes: 12 additions & 2 deletions src/PowerShellEditorServices/Analysis/AnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
/// </summary>
/// <param name="scriptDefinition">Script text to be formatted</param>
/// <returns>The formatted script text.</returns>
public async Task<string> Format(string scriptDefinition)
public async Task<string> Format(
string scriptDefinition,
int startLineNumber = -1,
int startColumnNumber = -1,
int endLineNumber = -1,
int endColumnNumber = -1)
{
// we cannot use Range type therefore this workaround of using -1 default value
if (!hasScriptAnalyzerModule)
{
return null;
Expand All @@ -261,7 +267,11 @@ public async Task<string> Format(string scriptDefinition)
var result = await InvokePowerShellAsync(
"Invoke-Formatter",
new Dictionary<string, object> {
{"ScriptDefinition", scriptDefinition}
{"ScriptDefinition", scriptDefinition},
{"StartLineNumber", startLineNumber},
{"StartColumnNumber", startColumnNumber},
{"EndLineNumber", endLineNumber},
{"EndColumnNumber", endColumnNumber}
});

return result?.Select(r => r.ImmediateBaseObject as string).FirstOrDefault();
Expand Down