public async Task <FormatRangeResponse> FormatAfterKeystroke(FormatAfterKeystrokeRequest request)
        {
            var document = _workspace.GetDocument(request.FileName);

            if (document == null)
            {
                return(null);
            }

            var lines    = (await document.GetSyntaxTreeAsync()).GetText().Lines;
            var position = lines.GetPosition(new LinePosition(request.Line - 1, request.Column - 1));
            var changes  = await Formatting.GetFormattingChangesAfterKeystroke(_workspace, Options, document, position, request.Char);

            return(new FormatRangeResponse()
            {
                Changes = changes
            });
        }
        public async override Task <TextEditContainer> Handle(DocumentOnTypeFormattingParams request, CancellationToken cancellationToken)
        {
            // TODO: request.options
            var omnisharpRequest = new FormatAfterKeystrokeRequest()
            {
                Character = request.Character,
                Line      = Convert.ToInt32(request.Position.Line),
                Column    = Convert.ToInt32(request.Position.Character),
                FileName  = Helpers.FromUri(request.TextDocument.Uri),
            };

            var omnisharpResponse = await _formatAfterKeystrokeHandler.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());
        }
        private async Task <(FormatRangeResponse, TestFile)> GetResponse(string text, string character, string fileName)
        {
            var file = new TestFile(fileName, text);

            SharedOmniSharpTestHost.AddFilesToWorkspace(file);
            var point = file.Content.GetPointFromPosition();

            var request = new FormatAfterKeystrokeRequest
            {
                Line      = point.Line,
                Column    = point.Offset,
                FileName  = fileName,
                Character = character,
            };

            var requestHandler = SharedOmniSharpTestHost.GetRequestHandler <FormatAfterKeystrokeService>(OmniSharpEndpoints.FormatAfterKeystroke);

            return(await requestHandler.Handle(request), file);
        }
        private async Task <(FormatRangeResponse, TestFile)> GetResponse(string text, string character, string fileName)
        {
            // Ensure system newlines are used
            var options = SharedOmniSharpTestHost.Workspace.Options.WithChangedOption(FormattingOptions.NewLine, LanguageNames.CSharp, System.Environment.NewLine);

            SharedOmniSharpTestHost.Workspace.TryApplyChanges(SharedOmniSharpTestHost.Workspace.CurrentSolution.WithOptions(options));

            var file = new TestFile(fileName, text);

            SharedOmniSharpTestHost.AddFilesToWorkspace(file);
            var point = file.Content.GetPointFromPosition();

            var request = new FormatAfterKeystrokeRequest
            {
                Line      = point.Line,
                Column    = point.Offset,
                FileName  = fileName,
                Character = character,
            };

            var requestHandler = SharedOmniSharpTestHost.GetRequestHandler <FormatAfterKeystrokeService>(OmniSharpEndpoints.FormatAfterKeystroke);

            return(await requestHandler.Handle(request), file);
        }