Exemple #1
0
        public void TextDocumentFactory_TextDocumentCreated_Host_TracksDocument()
        {
            // Arrange
            var textBuffer = new Mock <ITextBuffer>();

            textBuffer.Setup(buffer => buffer.ContentType)
            .Returns(Mock.Of <IContentType>());
            textBuffer.Setup(buffer => buffer.ChangeContentType(RazorContentType, null))
            .Verifiable();
            var textBufferProperties = new PropertyCollection();

            textBuffer.Setup(buffer => buffer.Properties)
            .Returns(textBufferProperties);
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            lspDocumentManager.Setup(manager => manager.TrackDocument(It.IsAny <ITextBuffer>()))
            .Verifiable();
            var listener     = CreateListener(lspDocumentManager.Object);
            var textDocument = CreateTextDocument(filePath: "file.razor", textBuffer.Object);
            var args         = new TextDocumentEventArgs(textDocument);

            // Act
            listener.TextDocumentFactory_TextDocumentCreated(sender: null, args);

            // Assert
            lspDocumentManager.VerifyAll();
        }
Exemple #2
0
        private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
        {
            lock (_spansOnDocuments)
            {
                if (_spansOnDocuments.TryGetValue(e.TextDocument, out PersistentSpanSet spanSet))
                {
                    spanSet.DocumentClosed();
                    _spansOnDocuments.Remove(e.TextDocument);

                    if (_spansOnDocuments.TryGetValue(spanSet.FileKey, out PersistentSpanSet existingSpansOnPath))
                    {
                        // Handle (badly) the case where a document is renamed to an existing closed document & then closed.
                        // We should only end up in this case if we had spans on two open documents that were both renamed
                        // to the same file name & then closed.
                        foreach (var s in spanSet.Spans)
                        {
                            s.SetSpanSet(existingSpansOnPath);
                            existingSpansOnPath.Spans.Add(s);
                        }

                        spanSet.Spans.Clear();
                        spanSet.Dispose();
                    }
                    else
                    {
                        _spansOnDocuments.Add(spanSet.FileKey, spanSet);
                    }
                }
            }
        }
        private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
        {
            FrugalList <PersistentSpan> spans;

            lock (_spansOnDocuments)
            {
                if (_spansOnDocuments.TryGetValue(e.TextDocument, out spans))
                {
                    foreach (var span in spans)
                    {
                        span.DocumentClosed();
                    }

                    _spansOnDocuments.Remove(e.TextDocument);

                    var path = new FileNameKey(e.TextDocument.FilePath);
                    FrugalList <PersistentSpan> existingSpansOnPath;
                    if (_spansOnDocuments.TryGetValue(path, out existingSpansOnPath))
                    {
                        //Handle (badly) the case where a document is renamed to an existing closed document & then closed.
                        existingSpansOnPath.AddRange(spans);
                    }
                    else
                    {
                        _spansOnDocuments.Add(path, spans);
                    }
                }
            }
        }
 private void DocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument == this.document)
     {
         this.Dispose();
     }
 }
Exemple #5
0
 void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument.TextBuffer == this.TextBuffer)
     {
         Close();
     }
 }
Exemple #6
0
 private void DocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument == this.document)
     {
         this.Dispose();
     }
 }
Exemple #7
0
 private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument.TextBuffer == _textBuffer)
     {
         Dispose();
     }
 }
 internal void OnTextDocumentDisposed(ITextDocument textDocument, TextDocumentEventArgs e)
 {
     lock (OpenFilesLock)
     {
         OpenFiles.TryRemove(textDocument.FilePath, out var tmp);
     }
     OpenViewsChangedInternal?.Invoke(this, EventArgs.Empty);
 }
 private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument.TextBuffer == _textBuffer)
     {
         GeneralChangingService.Instance.GeneralChanged -= OnGeneralChanged;
         _documentFactoryService.TextDocumentDisposed   -= OnTextDocumentDisposed;
     }
 }
 // TODO: it's not good idea to subscribe on text document disposed. Try to subscribe on text
 // document closed.
 private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument.TextBuffer == _textBuffer)
     {
         _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed;
         _editorChangingService.EditorOptionsChanged      -= OnEditorOptionsChanged;
     }
 }
Exemple #11
0
 // TODO: it's not good idea subscribe on text document disposed. Try to subscribe on text
 // document closed.
 private void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     if (e.TextDocument.TextBuffer == _textBuffer)
     {
         _semanticModel       = null;
         _textBuffer.Changed -= OnTextBufferChanged;
         _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed;
     }
 }
Exemple #12
0
// ReSharper disable InconsistentNaming
        void documentFactoryService_TextDocumentDisposed(object sender, TextDocumentEventArgs e)
// ReSharper restore InconsistentNaming
        {
            var fileNode = GetFileNodeForFileImpl(e.TextDocument.FilePath);

            if (fileNode != null)
            {
                fileNode.Bind(null);
            }
        }
 private void TextDocFactory_TextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     try
     {
         TeamCodingPackage.Current.LocalIdeModel.OnTextDocumentDisposed(e.TextDocument, e);
     }
     catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached)
     {
         TeamCodingPackage.Current.Logger.WriteError(ex);
     }
 }
 private void TextDocumentFactoryServiceOnTextDocumentCreated(object sender, TextDocumentEventArgs textDocumentEventArgs) {
   if (textDocumentEventArgs.TextDocument != null) {
     _fileRegistrationRequestService.RegisterTextDocument(textDocumentEventArgs.TextDocument);
     textDocumentEventArgs.TextDocument.FileActionOccurred += (o, args) => {
       if (args.FileActionType.HasFlag(FileActionTypes.DocumentRenamed)) {
         var document = (ITextDocument)o;
         _fileRegistrationRequestService.RegisterFile(args.FilePath);
         _fileRegistrationRequestService.UnregisterFile(document.FilePath);
       }
     };
   }
 }
Exemple #15
0
        public void TextDocumentFactory_TextDocumentCreated_EditorUnavailable_Noops()
        {
            // Arrange
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);
            var listener           = CreateListener(lspDocumentManager.Object, UnavailableFeatureDetector);
            var textDocument       = CreateTextDocument(filePath: "file.razor");
            var args = new TextDocumentEventArgs(textDocument);

            // Act
            listener.TextDocumentFactory_TextDocumentCreated(sender: null, args);

            // Assert
            lspDocumentManager.VerifyAll();
        }
        // Internal for testing
        internal void TextDocumentFactory_TextDocumentDisposed(object sender, TextDocumentEventArgs args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            // Do a lighter check to see if we care about this document.
            if (IsRazorFilePath(args.TextDocument.FilePath))
            {
                // If we don't know about this document we'll no-op
                _lspDocumentManager.UntrackDocument(args.TextDocument.TextBuffer);
            }
        }
Exemple #17
0
        public void TextDocumentFactory_TextDocumentDisposed_NonRazorFile_Noops()
        {
            // Arrange
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            lspDocumentManager.Setup(manager => manager.UntrackDocument(It.IsAny <ITextBuffer>()))
            .Throws <XunitException>();
            var listener     = CreateListener(lspDocumentManager.Object);
            var textDocument = CreateTextDocument(filePath: "file.txt");
            var args         = new TextDocumentEventArgs(textDocument);

            // Act & Assert
            listener.TextDocumentFactory_TextDocumentDisposed(sender: null, args);
        }
Exemple #18
0
        public void TextDocumentFactory_TextDocumentCreated_RemoteClient_DoesNotTrackDocument()
        {
            // Arrange
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            lspDocumentManager.Setup(manager => manager.TrackDocument(It.IsAny <ITextBuffer>()))
            .Throws <XunitException>();
            var featureDetector = Mock.Of <LSPEditorFeatureDetector>(detector => detector.IsRemoteClient() == true);
            var listener        = CreateListener(lspDocumentManager.Object);
            var textDocument    = CreateTextDocument(filePath: "file.razor");
            var args            = new TextDocumentEventArgs(textDocument);

            // Act & Assert
            listener.TextDocumentFactory_TextDocumentCreated(sender: null, args);
        }
Exemple #19
0
        private void OnTextDocumentCreated(object sender, TextDocumentEventArgs e)
        {
            var path = new FileNameKey(e.TextDocument.FilePath);

            lock (_spansOnDocuments)
            {
                if (_spansOnDocuments.TryGetValue(path, out PersistentSpanSet spanSet))
                {
                    spanSet.DocumentReopened(e.TextDocument);

                    _spansOnDocuments.Remove(path);
                    _spansOnDocuments.Add(e.TextDocument, spanSet);
                }
            }
        }
        private void DocumentFactory_TextDocumentCreated(object sender, TextDocumentEventArgs e)
        {
            ITextDocument document = e.TextDocument;

            if (document.FilePath != TempTxtFile)
            {
                document.FileActionOccurred     += this.Document_FileActionOccurred;
                document.TextBuffer.PostChanged += this.TextBuffer_PostChanged;
                this.AddChangedDocument(document);

                lock (this.attachedDocuments)
                {
                    this.attachedDocuments.Add(document);
                }
            }
        }
        private void DocumentFactory_TextDocumentDisposed(object sender, TextDocumentEventArgs e)
        {
            ITextDocument document = e.TextDocument;

            if (document.FilePath != TempTxtFile)
            {
                this.AddChangedDocument(document.FilePath, null);

                this.DetachEventHandlers(document);

                lock (this.attachedDocuments)
                {
                    this.attachedDocuments.Remove(document);
                }
            }
        }
Exemple #22
0
        public void TextDocumentFactory_TextDocumentDisposed_RazorFile_Untracks(string extension)
        {
            // Arrange
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            lspDocumentManager.Setup(manager => manager.UntrackDocument(It.IsAny <ITextBuffer>()))
            .Verifiable();
            var listener     = CreateListener(lspDocumentManager.Object);
            var textDocument = CreateTextDocument(filePath: "file" + extension);
            var args         = new TextDocumentEventArgs(textDocument);

            // Act
            listener.TextDocumentFactory_TextDocumentDisposed(sender: null, args);

            // Assert
            lspDocumentManager.VerifyAll();
        }
        private void OnTextDocumentCreated(object sender, TextDocumentEventArgs e)
        {
            var path = new FileNameKey(e.TextDocument.FilePath);
            FrugalList <PersistentSpan> spans;

            lock (_spansOnDocuments)
            {
                if (_spansOnDocuments.TryGetValue(path, out spans))
                {
                    foreach (var span in spans)
                    {
                        span.DocumentReopened(e.TextDocument);
                    }

                    _spansOnDocuments.Remove(path);
                    _spansOnDocuments.Add(e.TextDocument, spans);
                }
            }
        }
        // Internal for testing
        internal void TextDocumentFactory_TextDocumentCreated(object sender, TextDocumentEventArgs args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            if (!IsRazorLSPTextDocument(args.TextDocument))
            {
                return;
            }

            var textBuffer = args.TextDocument.TextBuffer;

            if (!textBuffer.ContentType.IsOfType(RazorLSPContentTypeDefinition.Name))
            {
                // This Razor text buffer has yet to be initialized.

                InitializeRazorLSPTextBuffer(textBuffer);
            }
        }
Exemple #25
0
        // Internal for testing
        internal void TextDocumentFactory_TextDocumentDisposed(object sender, TextDocumentEventArgs args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            // Do a lighter check to see if we care about this document.
            if (IsRazorFilePath(args.TextDocument.FilePath))
            {
                // If we don't know about this document we'll no-op
                _lspDocumentManager.UntrackDocument(args.TextDocument.TextBuffer);

                if (_lspEditorFeatureDetector.IsRemoteClient() &&
                    args.TextDocument.TextBuffer.Properties.ContainsProperty(FilePathPropertyKey))
                {
                    // We no longer want to watch for guest buffer changes.
                    args.TextDocument.TextBuffer.Properties.RemoveProperty(FilePathPropertyKey);
                    args.TextDocument.TextBuffer.ChangedHighPriority -= RazorGuestBuffer_Changed;
                }
            }
        }
Exemple #26
0
        public void TextDocumentFactory_TextDocumentCreated_UninitializedTextBuffer_InitializesWithClientName()
        {
            // Arrange
            var listener   = CreateListener();
            var textBuffer = new Mock <ITextBuffer>();

            textBuffer.Setup(buffer => buffer.ContentType)
            .Returns(Mock.Of <IContentType>());
            textBuffer.Setup(buffer => buffer.ChangeContentType(RazorContentType, null))
            .Verifiable();
            var textBufferProperties = new PropertyCollection();

            textBuffer.Setup(buffer => buffer.Properties)
            .Returns(textBufferProperties);
            var textDocument = CreateTextDocument(filePath: "file.razor", textBuffer.Object);
            var args         = new TextDocumentEventArgs(textDocument);

            // Act
            listener.TextDocumentFactory_TextDocumentCreated(sender: null, args);

            // Assert
            textBuffer.VerifyAll();
            Assert.True(textBufferProperties.TryGetProperty <string>(LanguageClientConstants.ClientNamePropertyKey, out _));
        }
Exemple #27
0
        public void TextDocumentFactory_TextDocumentCreated_UninitializedTextBuffer_RemoteClient_InitializesWithoutClientName()
        {
            // Arrange
            var featureDetector = Mock.Of <LSPEditorFeatureDetector>(detector =>
                                                                     detector.IsLSPEditorAvailable(It.IsAny <string>(), null) == true &&
                                                                     detector.IsRemoteClient() == true);
            var listener   = CreateListener(lspEditorFeatureDetector: featureDetector);
            var textBuffer = new Mock <ITextBuffer>();

            textBuffer.Setup(buffer => buffer.ContentType)
            .Returns(Mock.Of <IContentType>());
            var textBufferProperties = new PropertyCollection();

            textBuffer.Setup(buffer => buffer.Properties)
            .Returns(textBufferProperties);
            var textDocument = CreateTextDocument(filePath: "file.razor", textBuffer.Object);
            var args         = new TextDocumentEventArgs(textDocument);

            // Act
            listener.TextDocumentFactory_TextDocumentCreated(sender: null, args);

            // Assert
            Assert.False(textBufferProperties.TryGetProperty <string>(LanguageClientConstants.ClientNamePropertyKey, out _));
        }
 private void TextDocumentFactoryServiceOnTextDocumentCreated(object sender, TextDocumentEventArgs args) {
   var document = args.TextDocument;
   document.FileActionOccurred += TextDocumentOnFileActionOccurred;
   if (FullPath.IsValid(document.FilePath)) {
     var path = new FullPath(document.FilePath);
     _openDocuments[path] = document;
   }
 }
 private void TextDocumentFactoryServiceOnTextDocumentDisposed(object sender, TextDocumentEventArgs textDocumentEventArgs) {
   if (textDocumentEventArgs.TextDocument != null) {
     _fileRegistrationRequestService.UnregisterTextDocument(textDocumentEventArgs.TextDocument);
   }
 }
Exemple #30
0
 // ReSharper restore InconsistentNaming
 // ReSharper disable InconsistentNaming
 void documentFactoryService_TextDocumentDisposed(object sender, TextDocumentEventArgs e)
 {
     var fileNode = GetFileNodeForFileImpl(e.TextDocument.FilePath);
     if (fileNode != null)
         fileNode.Bind(null);
 }
 public UnitTestingTextDocumentEventArgsWrapper(TextDocumentEventArgs underlyingObject)
 => UnderlyingObject = underlyingObject ?? throw new ArgumentNullException(nameof(underlyingObject));
Exemple #32
0
 private void TextDocumentFactoryServiceOnTextDocumentDisposed(object sender, TextDocumentEventArgs textDocumentEventArgs)
 {
     _textDocumentService.OnDocumentClose(textDocumentEventArgs.TextDocument);
 }
Exemple #33
0
 private void TextDocumentFactoryServiceOnTextDocumentCreated(object sender, TextDocumentEventArgs textDocumentEventArgs)
 {
     _textDocumentService.OnDocumentOpen(textDocumentEventArgs.TextDocument);
 }
 private void TextDocumentFactoryServiceOnTextDocumentDisposed(object sender, TextDocumentEventArgs textDocumentEventArgs)
 {
     _textDocumentService.OnDocumentClose(textDocumentEventArgs.TextDocument);
 }
 private void TextDocumentFactoryServiceOnTextDocumentDisposed(object sender, TextDocumentEventArgs args) {
   var document = args.TextDocument;
   if (FullPath.IsValid(document.FilePath)) {
     var path = new FullPath(document.FilePath);
     _openDocuments.Remove(path);
   }
 }
 private void TextDocumentFactoryServiceOnTextDocumentCreated(object sender, TextDocumentEventArgs textDocumentEventArgs)
 {
     _textDocumentService.OnDocumentOpen(textDocumentEventArgs.TextDocument);
 }
Exemple #37
0
 void OnTextDocumentDisposed(object sender, TextDocumentEventArgs e) {
     if (e.TextDocument.TextBuffer == this.TextBuffer) {
         Close();
     }
 }