-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/CheckForOverflowUnderflow
- Loading branch information
Showing
17 changed files
with
276 additions
and
226 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
52 changes: 52 additions & 0 deletions
52
src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormatRangeHandler.cs
This file contains 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,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Server; | ||
using OmniSharp.Models.Format; | ||
|
||
namespace OmniSharp.LanguageServerProtocol.Handlers | ||
{ | ||
internal sealed class OmniSharpDocumentFormatRangeHandler : DocumentRangeFormattingHandler | ||
{ | ||
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers) | ||
{ | ||
foreach (var (selector, handler) in handlers | ||
.OfType<Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse>>()) | ||
if (handler != null) | ||
yield return new OmniSharpDocumentFormatRangeHandler(handler, selector); | ||
} | ||
|
||
private readonly Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> _formatRangeHandler; | ||
|
||
public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> formatRangeHandler, DocumentSelector documentSelector) : base(new TextDocumentRegistrationOptions() | ||
{ | ||
DocumentSelector = documentSelector, | ||
}) | ||
{ | ||
_formatRangeHandler = formatRangeHandler; | ||
} | ||
|
||
public async override Task<TextEditContainer> Handle(DocumentRangeFormattingParams request, CancellationToken cancellationToken) | ||
{ | ||
var omnisharpRequest = new FormatRangeRequest() | ||
{ | ||
FileName = Helpers.FromUri(request.TextDocument.Uri), | ||
Line = Convert.ToInt32(request.Range.Start.Line), | ||
Column = Convert.ToInt32(request.Range.Start.Character), | ||
EndLine = Convert.ToInt32(request.Range.End.Line), | ||
EndColumn = Convert.ToInt32(request.Range.End.Character), | ||
}; | ||
|
||
var omnisharpResponse = await _formatRangeHandler.Handle(omnisharpRequest); | ||
return omnisharpResponse.Changes.Select(change => new TextEdit() | ||
{ | ||
NewText = change.NewText, | ||
Range = new Range(new Position(change.StartLine, change.StartColumn), new Position(change.EndLine, change.EndColumn)) | ||
}).ToArray(); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormattingHandler.cs
This file contains 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,51 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Server; | ||
using OmniSharp.Models.CodeFormat; | ||
using OmniSharp.Models.MembersTree; | ||
using OmniSharp.Models.V2.CodeStructure; | ||
|
||
namespace OmniSharp.LanguageServerProtocol.Handlers | ||
{ | ||
internal sealed class OmniSharpDocumentFormattingHandler : DocumentFormattingHandler | ||
{ | ||
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers) | ||
{ | ||
foreach (var (selector, handler) in handlers | ||
.OfType<Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse>>()) | ||
if (handler != null) | ||
yield return new OmniSharpDocumentFormattingHandler(handler, selector); | ||
} | ||
|
||
private readonly Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> _codeFormatHandler; | ||
|
||
public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> codeFormatHandler, DocumentSelector documentSelector) : base(new TextDocumentRegistrationOptions() | ||
{ | ||
DocumentSelector = documentSelector, | ||
}) | ||
{ | ||
_codeFormatHandler = codeFormatHandler; | ||
} | ||
|
||
public async override Task<TextEditContainer> Handle(DocumentFormattingParams request, CancellationToken cancellationToken) | ||
{ | ||
var omnisharpRequest = new CodeFormatRequest() | ||
{ | ||
FileName = Helpers.FromUri(request.TextDocument.Uri), | ||
WantsTextChanges = true | ||
}; | ||
|
||
var omnisharpResponse = await _codeFormatHandler.Handle(omnisharpRequest); | ||
return omnisharpResponse.Changes.Select(change => new TextEdit() | ||
{ | ||
NewText = change.NewText, | ||
Range = new Range(new Position(change.StartLine, change.StartColumn), new Position(change.EndLine, change.EndColumn)) | ||
}).ToArray(); | ||
} | ||
} | ||
} |
Oops, something went wrong.