Ejemplo n.º 1
0
        private async Task OnReplDidChangeTextDocumentAsync(ITextSnapshot before, ITextSnapshot after, IEnumerable <ITextChange> textChanges)
        {
            var contentChanges = new List <LSP.TextDocumentContentChangeEvent>();

            // The changes in textChanges all apply to the same original document state. The changes sent to the
            // server are expected to apply to the state as of the previous change in the list. To prevent the
            // changes from affecting one another we reverse the list.
            foreach (var textChange in textChanges.Reverse())
            {
                var changeEvent = new LSP.TextDocumentContentChangeEvent {
                    Text  = textChange.NewText,
                    Range = new LSP.Range {
                        Start = new LSP.Position {
                            Line      = before.GetLineNumberFromPosition(textChange.OldSpan.Start) + _previousCellsLineCount,
                            Character = textChange.OldSpan.Start - before.GetLineFromPosition(textChange.OldSpan.Start).Start.Position
                        },
                        End = new LSP.Position {
                            Line      = before.GetLineNumberFromPosition(textChange.OldSpan.End) + _previousCellsLineCount,
                            Character = textChange.OldSpan.End - before.GetLineFromPosition(textChange.OldSpan.End).Start.Position
                        },
                    },
                    RangeLength = textChange.OldSpan.Length
                };

                contentChanges.Add(changeEvent);
            }

            _version++;

            var changesOnlyParam = new LSP.DidChangeTextDocumentParams {
                ContentChanges = contentChanges.ToArray(),
                TextDocument   = new LSP.VersionedTextDocumentIdentifier {
                    Version = _version,
                    Uri     = new Uri(Path.GetFullPath(_tempFilePath)),
                }
            };

            await _client.InvokeTextDocumentDidChangeAsync(changesOnlyParam);
        }
 public static TextChange ContentChangeEventToTextChange(LSP.TextDocumentContentChangeEvent changeEvent, SourceText text)
 => new TextChange(RangeToTextSpan(changeEvent.Range, text), changeEvent.Text);