-
Notifications
You must be signed in to change notification settings - Fork 235
Add request handlers for document formatting #516
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
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4c6b4f4
Add stub to handle formatting request
ca1f97e
Add handler to format document with default settings
78ad540
Add formatting related types
2a83b0f
Remove unused handler from LanguageServer
44ca6b3
Fix DocumentFormattingParams request type
0b8e8a2
Add a method to enumerate PSScriptAnalyzer cmdlets
f09d70c
Execute formatter only if module is present
3da17ee
Handle null value returned by formatter
7c3ebf8
Add all formatting types and requests
2f50051
Convert Range type to class from struct
d8bf331
Update AnalysisService.Format method
39d69d4
Add range formatting capability to the server
d00e2ca
Fix format wrapper method
c4e8866
Disable server side range formatting
d799a88
Add CodeFormattingSettings type
466248e
Make properties of FormattingOptions type public
fb63ff7
Provide settings for formatting
9eb1b11
Create an abstract base class for settings
4c1a861
Create a class to represent editor settings
404b0ae
Disable server side document formatting capability
ebb6f03
Capitalize options property in FormattingOptions
0ebfb5e
Send a range array to Format method
efd884f
Fix merge conflict in LanguageServer.cs
2851e80
Remove AbstractSettings base class
6ac7b0d
Update inline xml documentation
7fc858b
Remove unused request type and its handler
d74d369
Fix test failures
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/PowerShellEditorServices.Protocol/LanguageServer/Formatting.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer | ||
{ | ||
public class DocumentFormattingRequest | ||
{ | ||
public static readonly RequestType<DocumentFormattingParams, TextEdit[], object, TextDocumentRegistrationOptions> Type = RequestType<DocumentFormattingParams, TextEdit[], object, TextDocumentRegistrationOptions>.Create("textDocument/formatting"); | ||
} | ||
|
||
public class DocumentRangeFormattingRequest | ||
{ | ||
public static readonly RequestType<DocumentRangeFormattingParams, TextEdit[], object, TextDocumentRegistrationOptions> Type = RequestType<DocumentRangeFormattingParams, TextEdit[], object, TextDocumentRegistrationOptions>.Create("textDocument/rangeFormatting"); | ||
|
||
} | ||
|
||
public class DocumentOnTypeFormattingRequest | ||
{ | ||
public static readonly RequestType<DocumentOnTypeFormattingRequest, TextEdit[], object, TextDocumentRegistrationOptions> Type = RequestType<DocumentOnTypeFormattingRequest, TextEdit[], object, TextDocumentRegistrationOptions>.Create("textDocument/onTypeFormatting"); | ||
|
||
} | ||
|
||
public class DocumentRangeFormattingParams | ||
{ | ||
/// <summary> | ||
/// The document to format. | ||
/// </summary> | ||
public TextDocumentIdentifier TextDocument { get; set; } | ||
|
||
/// <summary> | ||
/// The range to format. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Range Range { get; set; } | ||
|
||
/// <summary> | ||
/// The format options. | ||
/// </summary> | ||
public FormattingOptions Options { get; set; } | ||
} | ||
|
||
public class DocumentOnTypeFormattingParams | ||
{ | ||
/// <summary> | ||
/// The document to format. | ||
/// </summary> | ||
public TextDocumentIdentifier TextDocument { get; set; } | ||
|
||
/// <summary> | ||
/// The position at which this request was sent. | ||
/// </summary> | ||
public Position Position { get; set; } | ||
|
||
/// <summary> | ||
/// The character that has been typed. | ||
/// </summary> | ||
public string ch { get; set; } | ||
|
||
/// <summary> | ||
/// The format options. | ||
/// </summary> | ||
public FormattingOptions options { get; set; } | ||
} | ||
|
||
public class DocumentFormattingParams | ||
{ | ||
/// <summary> | ||
/// The document to format. | ||
/// </summary> | ||
public TextDocumentIdentifier TextDocument { get; set; } | ||
|
||
/// <summary> | ||
/// The format options. | ||
/// </summary> | ||
public FormattingOptions options { get; set; } | ||
} | ||
|
||
public class FormattingOptions | ||
{ | ||
/// <summary> | ||
/// Size of a tab in spaces. | ||
/// </summary> | ||
public int TabSize { get; set; } | ||
|
||
/// <summary> | ||
/// Prefer spaces over tabs. | ||
/// </summary> | ||
public bool InsertSpaces { get; set; } | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this be
true
? Or are you doing this as a workaround to the FormattingOptions issue?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.
I saw the answer to my question in the other PR :)
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.
Yes, this is part of the workaround - when I started working on this I had set it to
true
, only to run into theFormattingOptions
issue later. So I set to to false, which is redundant as the it would befalse
by default.