private void NotifyDocumentManagerChangeListeners( LSPDocumentSnapshot old, LSPDocumentSnapshot @new, VirtualDocumentSnapshot virtualOld, VirtualDocumentSnapshot virtualNew, LSPDocumentChangeKind kind) { foreach (var listener in _documentManagerChangeListeners) { var notifyListener = false; if (old != null && listener.Metadata.ContentTypes.Any(ct => old.Snapshot.ContentType.IsOfType(ct))) { notifyListener = true; } else if (@new != null && listener.Metadata.ContentTypes.Any(ct => @new.Snapshot.ContentType.IsOfType(ct))) { notifyListener = true; } if (notifyListener) { listener.Value.Changed(old, @new, virtualOld, virtualNew, kind); } } }
public LSPDocumentChangeEventArgs( LSPDocumentSnapshot old, LSPDocumentSnapshot @new, VirtualDocumentSnapshot virtualOld, VirtualDocumentSnapshot virtualNew, LSPDocumentChangeKind kind) { Old = old; New = @new; VirtualOld = virtualOld; VirtualNew = virtualNew; Kind = kind; }
public override void Changed(LSPDocumentSnapshot old, LSPDocumentSnapshot @new, VirtualDocumentSnapshot virtualOld, VirtualDocumentSnapshot virtualNew, LSPDocumentChangeKind kind) { lock (_documentContextLock) { if (kind == LSPDocumentChangeKind.Added) { var lspDocument = @new; for (var i = 0; i < lspDocument.VirtualDocuments.Count; i++) { var virtualDocument = lspDocument.VirtualDocuments[i]; Debug.Assert(!_virtualDocumentContexts.ContainsKey(virtualDocument.Uri)); var virtualDocumentTextBuffer = virtualDocument.Snapshot.TextBuffer; virtualDocumentTextBuffer.PostChanged += VirtualDocumentBuffer_PostChanged; _virtualDocumentContexts[virtualDocument.Uri] = new DocumentContext(_synchronizationTimeout); } } else if (kind == LSPDocumentChangeKind.Removed) { var lspDocument = old; for (var i = 0; i < lspDocument.VirtualDocuments.Count; i++) { var virtualDocument = lspDocument.VirtualDocuments[i]; if (!_virtualDocumentContexts.TryGetValue(virtualDocument.Uri, out var virtualDocumentContext)) { Debug.Fail("Could not locate virtual document context, it should have been added."); continue; } var virtualDocumentTextBuffer = virtualDocument.Snapshot.TextBuffer; virtualDocumentTextBuffer.PostChanged -= VirtualDocumentBuffer_PostChanged; virtualDocumentContext.Dispose(); _virtualDocumentContexts.Remove(virtualDocument.Uri); } } else if (kind == LSPDocumentChangeKind.VirtualDocumentChanged) { if (virtualOld.Snapshot.Version == virtualNew.Snapshot.Version) { // UpdateDocumentContextVersionInternal is typically invoked through a buffer notification, // however in the case where VirtualDocumentBase.Update is called with a zero change edit, // there won't be such an edit to hook into. Instead, we'll detect that case here and // update the document context version appropriately. UpdateDocumentContextVersionInternal(virtualNew.Snapshot.TextBuffer); } } } }
public abstract void Changed( LSPDocumentSnapshot old, LSPDocumentSnapshot @new, VirtualDocumentSnapshot virtualOld, VirtualDocumentSnapshot virtualNew, LSPDocumentChangeKind kind);
public LSPDocumentChangeEventArgs(LSPDocumentSnapshot old, LSPDocumentSnapshot @new, LSPDocumentChangeKind kind) : this(old, @new, virtualOld : null, virtualNew : null, kind) { }
// Internal for testing public override void Changed(LSPDocumentSnapshot old, LSPDocumentSnapshot @new, VirtualDocumentSnapshot virtualOld, VirtualDocumentSnapshot virtualNew, LSPDocumentChangeKind kind) { // We need the below check to address a race condition between when a request is sent to the C# server // for a generated document and when the C# server receives a document/didOpen notification. This race // condition may occur when the Razor server finishes initializing before C# receives and processes the // document open request. // This workaround adds the Razor client name to the generated document so the C# server will recognize // it, despite the document not being formally opened. Note this is meant to only be a temporary // workaround until a longer-term solution is implemented in the future. if (kind == LSPDocumentChangeKind.Added && _dynamicFileInfoProvider is DefaultRazorDynamicFileInfoProvider defaultProvider) { defaultProvider.PromoteBackgroundDocument(@new.Uri, CSharpDocumentPropertiesService.Instance); } if (kind != LSPDocumentChangeKind.VirtualDocumentChanged) { return; } if (virtualNew is CSharpVirtualDocumentSnapshot) { var csharpContainer = new CSharpVirtualDocumentContainer(_lspDocumentMappingProvider, @new, virtualNew.Snapshot); _dynamicFileInfoProvider.UpdateLSPFileInfo(@new.Uri, csharpContainer); } }