public override void PublishCSharp(string filePath, SourceText sourceText, int hostDocumentVersion) { if (filePath is null) { throw new ArgumentNullException(nameof(filePath)); } if (sourceText is null) { throw new ArgumentNullException(nameof(sourceText)); } _foregroundDispatcher.AssertForegroundThread(); if (!_publishedCSharpData.TryGetValue(filePath, out var previouslyPublishedData)) { previouslyPublishedData = PublishData.Default; } var textChanges = SourceTextDiffer.GetMinimalTextChanges(previouslyPublishedData.SourceText, sourceText); if (textChanges.Count == 0 && hostDocumentVersion == previouslyPublishedData.HostDocumentVersion) { // Source texts match along with host document versions. We've already published something that looks like this. No-op. return; } if (_logger.IsEnabled(LogLevel.Trace)) { var previousDocumentLength = previouslyPublishedData.SourceText.Length; var currentDocumentLength = sourceText.Length; var documentLengthDelta = sourceText.Length - previousDocumentLength; _logger.LogTrace( "Updating C# buffer of {0} to correspond with host document version {1}. {2} -> {3} = Change delta of {4} via {5} text changes.", filePath, hostDocumentVersion, previousDocumentLength, currentDocumentLength, documentLengthDelta, textChanges.Count); } _publishedCSharpData[filePath] = new PublishData(sourceText, hostDocumentVersion); var request = new UpdateBufferRequest() { HostDocumentFilePath = filePath, Changes = textChanges, HostDocumentVersion = hostDocumentVersion, }; var result = _server.SendRequest(LanguageServerConstants.RazorUpdateCSharpBufferEndpoint, request); // This is the call that actually makes the request, any SendRequest without a .Returning* after it will do nothing. _ = result.ReturningVoid(CancellationToken.None); }
public override void PublishHtml(string filePath, SourceText sourceText, long hostDocumentVersion) { if (filePath is null) { throw new ArgumentNullException(nameof(filePath)); } if (sourceText is null) { throw new ArgumentNullException(nameof(sourceText)); } _foregroundDispatcher.AssertForegroundThread(); if (!_publishedHtmlData.TryGetValue(filePath, out var previouslyPublishedData)) { previouslyPublishedData = PublishData.Default; } IReadOnlyList <TextChange> textChanges = Array.Empty <TextChange>(); if (!sourceText.ContentEquals(previouslyPublishedData.SourceText)) { textChanges = sourceText.GetTextChanges(previouslyPublishedData.SourceText); } else if (hostDocumentVersion == previouslyPublishedData.HostDocumentVersion) { // Source texts match along with host document versions. We've already published something that looks like this. No-op. return; } _publishedHtmlData[filePath] = new PublishData(sourceText, hostDocumentVersion); var request = new UpdateBufferRequest() { HostDocumentFilePath = filePath, Changes = textChanges, HostDocumentVersion = hostDocumentVersion, }; _server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateHtmlBufferEndpoint, request); }
public override void PublishCSharp(string filePath, SourceText sourceText, int hostDocumentVersion) { if (filePath is null) { throw new ArgumentNullException(nameof(filePath)); } if (sourceText is null) { throw new ArgumentNullException(nameof(sourceText)); } _foregroundDispatcher.AssertForegroundThread(); if (!_publishedCSharpData.TryGetValue(filePath, out var previouslyPublishedData)) { previouslyPublishedData = PublishData.Default; } var textChanges = SourceTextDiffer.GetMinimalTextChanges(previouslyPublishedData.SourceText, sourceText); if (textChanges.Count == 0 && hostDocumentVersion == previouslyPublishedData.HostDocumentVersion) { // Source texts match along with host document versions. We've already published something that looks like this. No-op. return; } _publishedCSharpData[filePath] = new PublishData(sourceText, hostDocumentVersion); var request = new UpdateBufferRequest() { HostDocumentFilePath = filePath, Changes = textChanges, HostDocumentVersion = hostDocumentVersion, }; var result = _server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateCSharpBufferEndpoint, request); // This is the call that actually makes the request, any SendRequest without a .Returning* after it will do nothing. result.ReturningVoid(CancellationToken.None); }
public override void PublishHtml(string filePath, SourceText sourceText, long hostDocumentVersion) { if (filePath is null) { throw new ArgumentNullException(nameof(filePath)); } if (sourceText is null) { throw new ArgumentNullException(nameof(sourceText)); } _foregroundDispatcher.AssertForegroundThread(); if (!_publishedHtmlSourceText.TryGetValue(filePath, out var previouslyPublishedText)) { previouslyPublishedText = EmptySourceText; } IReadOnlyList <TextChange> textChanges = Array.Empty <TextChange>(); if (!sourceText.ContentEquals(previouslyPublishedText)) { textChanges = sourceText.GetTextChanges(previouslyPublishedText); } _publishedHtmlSourceText[filePath] = sourceText; var request = new UpdateBufferRequest() { HostDocumentFilePath = filePath, Changes = textChanges, HostDocumentVersion = hostDocumentVersion, }; _server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateHtmlBufferEndpoint, request); }