public void VsTextViewCreated(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                throw new ArgumentNullException(nameof(vsTextView));
            }

            if (ErrorHandler.Failed(vsTextView.GetBuffer(out var textLines)))
            {
                return;
            }

            IVsUserData userData = textLines as IVsUserData;

            if (userData == null)
            {
                return;
            }

            Guid monikerGuid = typeof(IVsUserData).GUID;

            if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out var monikerObj)))
            {
                return;
            }

            string filePath = monikerObj as string;

            _rdt.Value.FindDocument(filePath, out var hierarchy, out var itemId, out var docCookie);

            AbstractProject project = GetXamlProject(hierarchy);

            if (project == null)
            {
                project = new XamlProject(
                    _vsWorkspace.GetProjectTrackerAndInitializeIfNecessary(_serviceProvider),
                    hierarchy,
                    _serviceProvider,
                    _vsWorkspace);
            }

            IVisualStudioHostDocument vsDocument = project.GetCurrentDocumentFromPath(filePath);

            if (vsDocument == null)
            {
                if (!TryCreateXamlDocument(project, filePath, out vsDocument))
                {
                    return;
                }

                project.AddDocument(vsDocument, isCurrentContext: true, hookupHandlers: true);
            }

            AttachRunningDocTableEvents();

            var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView);
            var target      = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);

            target.AttachToVsTextView();
        }
예제 #2
0
 private void CancelPendingDocumentInitializationTask(IVisualStudioHostDocument document)
 {
     lock (_gate)
     {
         CancelPendingDocumentInitializationTask_NoLock(document);
     }
 }
예제 #3
0
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, ImmutableArray <string> .Empty, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType));

            return(vsDocument != null);
        }
예제 #4
0
        private void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(IVisualStudioHostDocument document, CancellationToken cancellationToken)
        {
            AssertIsForeground();

            cancellationToken.ThrowIfCancellationRequested();

            // Ignore any other unknown kinds of documents
            var standardDocument = document as StandardTextDocument;

            if (standardDocument == null)
            {
                return;
            }

            // If it's already open, then we have nothing more to do here.
            if (standardDocument.IsOpen)
            {
                return;
            }

            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie))
            {
                TryProcessOpenForDocCookie(docCookie, cancellationToken);
            }

            cancellationToken.ThrowIfCancellationRequested();
            CancelPendingDocumentInitializationTask(document);
        }
예제 #5
0
        internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
        {
            // We need to ensure the file is saved, only if a global undo transaction is open
            var  globalUndoService = this.Services.GetService <IGlobalUndoService>();
            bool needsSave         = globalUndoService.IsGlobalTransactionOpen(this);
            bool needsUndoDisabled = needsSave && this.Services.GetService <IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));

            return(new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled));
        }
예제 #6
0
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, filePath, SourceCodeKind.Regular,
                tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType),
                _ => SpecializedCollections.EmptyReadOnlyList <string>());

            return(vsDocument != null);
        }
예제 #7
0
 private void CancelPendingDocumentInitializationTask_NoLock(IVisualStudioHostDocument document)
 {
     // Remove pending initialization task for the document, if any, and dispose the cancellation token source.
     if (_pendingDocumentInitializationTasks.TryGetValue(document.Id, out var taskAndTokenSource))
     {
         taskAndTokenSource.CancellationTokenSource.Cancel();
         taskAndTokenSource.CancellationTokenSource.Dispose();
         _pendingDocumentInitializationTasks.Remove(document.Id);
     }
 }
예제 #8
0
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            // We already have an AbstractProject, so the workspace has been created
            vsDocument = _vsWorkspace.DeferredState.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, filePath, SourceCodeKind.Regular,
                tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType),
                ImmutableArray <string> .Empty);

            return(vsDocument != null);
        }
예제 #9
0
        internal void OnFileIncludedInProject(IVisualStudioHostDocument document)
        {
            uint docCookie;

            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.FilePath, out docCookie))
            {
                TryRemoveDocumentFromMiscellaneousWorkspace(docCookie, document.FilePath);
            }

            _filesInProjects.Add(document.Key);
        }
예제 #10
0
        public void RemoveAdditionalFile(string additionalFilePath)
        {
            IVisualStudioHostDocument document = this.GetCurrentDocumentFromPath(additionalFilePath);

            if (document == null)
            {
                throw new InvalidOperationException("The document is not a part of the finalProject.");
            }

            RemoveAdditionalDocument(document);
        }
예제 #11
0
        /// <summary>
        /// If the document is open in the running document table, this returns the hierarchy in
        /// which it is currently open. Otherwise, it returns null.
        /// </summary>
        private IVsHierarchy GetContextHierarchyFromRunningDocumentTable(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();
            if (!runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie))
            {
                return null;
            }

            runningDocumentTable.GetDocumentHierarchyItem(docCookie, out var hierarchy, out var itemid);

            return hierarchy;
        }
예제 #12
0
        /// <summary>
        /// If the document is open in the running document table, this returns the hierarchy in
        /// which it is currently open. Otherwise, it returns null.
        /// </summary>
        private IVsHierarchy GetContextHierarchyFromRunningDocumentTable(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();
            if (!runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie))
            {
                return(null);
            }

            runningDocumentTable.GetDocumentHierarchyItem(docCookie, out var hierarchy, out var itemid);

            return(hierarchy);
        }
예제 #13
0
        internal void OnFileRemovedFromProject(IVisualStudioHostDocument document)
        {
            // Remove the document key from the filesInProjects map first because adding documents
            // to the misc files workspace requires that they not appear in this map.
            _filesInProjects.Remove(document.Key);

            uint docCookie;

            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie))
            {
                AddDocumentToMiscellaneousOrMetadataAsSourceWorkspace(docCookie, document.Key.Moniker);
            }
        }
예제 #14
0
 /// <summary>
 /// Notifies the document provider that this document is now registered in a project.
 /// If we are on a foregroud thread, then this is done right away.
 /// Otherwise, we schedule a task on foreground task scheduler.
 /// </summary>
 public void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(IVisualStudioHostDocument document)
 {
     if (IsForeground())
     {
         NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cancellationToken: CancellationToken.None);
     }
     else
     {
         var cts  = new CancellationTokenSource();
         var task = InvokeBelowInputPriority(() => NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cts.Token), cts.Token);
         AddPendingDocumentInitializationTask(document, task, cts);
     }
 }
예제 #15
0
 private void AddPendingDocumentInitializationTask(IVisualStudioHostDocument document, Task task, CancellationTokenSource cts)
 {
     var taskAndTokenSource = new TaskAndTokenSource() { Task = task, CancellationTokenSource = cts };
     lock (_gate)
     {
         // Add taskAndTokenSource to the pending document initialization tasks.
         // Check for cancellation before adding as the task might already have been completed/cancelled/faulted before we reached here.
         if (!cts.IsCancellationRequested && !task.IsCompleted)
         {
             _pendingDocumentInitializationTasks.Add(document.Id, taskAndTokenSource);
         }
     }
 }
예제 #16
0
        private void OnDocumentClosed(uint docCookie)
        {
            RunningDocumentInfo info    = _rdt.Value.GetDocumentInfo(docCookie);
            AbstractProject     project = GetXamlProject(info.Hierarchy);

            if (project == null)
            {
                return;
            }

            IVisualStudioHostDocument document = project.GetCurrentDocumentFromPath(info.Moniker);

            if (document == null)
            {
                return;
            }

            project.RemoveDocument(document);
        }
예제 #17
0
        /// <summary>
        /// If the document is in a Shared Code project, this returns that project's 
        /// SharedItemContextHierarchy. Otherwise, it returns null. 
        /// </summary>
        private IVsHierarchy GetSharedItemContextHierarchy(IVisualStudioHostDocument document)
        {
            AssertIsForeground();

            var itemId = document.GetItemId();
            if (itemId == (uint)VSConstants.VSITEMID.Nil)
            {
                // the document is no longer part of the solution
                return null;
            }

            var sharedHierarchy = GetSharedHierarchyForItem(document.Project.Hierarchy, itemId);
            if (sharedHierarchy == null)
            {
                return null;
            }

            return GetSharedItemContextHierarchy(sharedHierarchy);
        }
예제 #18
0
        private bool TryGetFrame(IVisualStudioHostDocument document, out IVsWindowFrame frame)
        {
            frame = null;

            var itemId = document.GetItemId();

            if (itemId == (uint)VSConstants.VSITEMID.Nil)
            {
                // If the ItemId is Nil, then then IVsProject would not be able to open the
                // document using its ItemId. Thus, we must use OpenDocumentViaProject, which only
                // depends on the file path.

                uint               itemid;
                IVsUIHierarchy     uiHierarchy;
                OLEServiceProvider oleServiceProvider;

                return(ErrorHandler.Succeeded(_shellOpenDocument.OpenDocumentViaProject(
                                                  document.FilePath,
                                                  VSConstants.LOGVIEWID.TextView_guid,
                                                  out oleServiceProvider,
                                                  out uiHierarchy,
                                                  out itemid,
                                                  out frame)));
            }
            else
            {
                // If the ItemId is not Nil, then we should not call IVsUIShellDocument
                // .OpenDocumentViaProject here because that simply takes a file path and opens the
                // file within the context of the first project it finds. That would cause problems
                // if the document we're trying to open is actually a linked file in another
                // project. So, we get the project's hierarchy and open the document using its item
                // ID.

                // It's conceivable that IVsHierarchy might not implement IVsProject. However,
                // OpenDocumentViaProject itself relies upon this QI working, so it should be OK to
                // use here.

                var vsProject = document.Project.Hierarchy as IVsProject;
                return(vsProject != null &&
                       ErrorHandler.Succeeded(vsProject.OpenItem(itemId, VSConstants.LOGVIEWID.TextView_guid, s_docDataExisting_Unknown, out frame)));
            }
        }
예제 #19
0
        /// <summary>
        /// If the document is in a Shared Code project, this returns that project's
        /// SharedItemContextHierarchy. Otherwise, it returns null.
        /// </summary>
        private IVsHierarchy GetSharedItemContextHierarchy(IVisualStudioHostDocument document)
        {
            AssertIsForeground();

            var itemId = document.GetItemId();

            if (itemId == (uint)VSConstants.VSITEMID.Nil)
            {
                // the document is no longer part of the solution
                return(null);
            }

            var sharedHierarchy = GetSharedHierarchyForItem(document.Project.Hierarchy, itemId);

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

            return(GetSharedItemContextHierarchy(sharedHierarchy));
        }
예제 #20
0
        private void OnDocumentMonikerChanged(IVsHierarchy hierarchy, string oldMoniker, string newMoniker)
        {
            // If the moniker change only involves casing differences then the project system will
            // not remove & add the file again with the new name, so we should not clear any state.
            // Leaving the old casing in the DocumentKey is safe because DocumentKey equality
            // checks ignore the casing of the moniker.
            if (oldMoniker.Equals(newMoniker, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // If the moniker change only involves a non-XAML project then ignore it.
            AbstractProject project = GetXamlProject(hierarchy);

            if (project == null)
            {
                return;
            }

            // Managed languages rely on the msbuild host object to add and remove documents during rename.
            // For XAML we have to do that ourselves.
            IVisualStudioHostDocument oldDocument = project.GetCurrentDocumentFromPath(oldMoniker);

            if (oldDocument != null)
            {
                project.RemoveDocument(oldDocument);
            }

            IVisualStudioHostDocument newDocument = project.GetCurrentDocumentFromPath(newMoniker);

            Debug.Assert(newDocument == null, "Why does the renamed document already exist in the project?");
            if (newDocument == null)
            {
                if (TryCreateXamlDocument(project, newMoniker, out newDocument))
                {
                    project.AddDocument(newDocument, isCurrentContext: true, hookupHandlers: true);
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Notifies the document provider that this document is now registered in a project.
        /// </summary>
        public void NotifyDocumentRegisteredToProject(IVisualStudioHostDocument document)
        {
            // Ignore any other unknown kinds of documents
            var standardDocument = document as StandardTextDocument;

            if (standardDocument == null)
            {
                return;
            }

            // If it's already open, then we have nothing more to do here.
            if (standardDocument.IsOpen)
            {
                return;
            }

            uint docCookie;

            if (RunningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie))
            {
                TryProcessOpenForDocCookie(docCookie);
            }
        }
        internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
        {
            // We need to ensure the file is saved, only if a global undo transaction is open
            var globalUndoService = this.Services.GetService <IGlobalUndoService>();
            var needsSave         = globalUndoService.IsGlobalTransactionOpen(this);

            var needsUndoDisabled = false;

            if (needsSave)
            {
                if (this.CurrentSolution.ContainsDocument(hostDocument.Id))
                {
                    // Disable undo on generated documents
                    needsUndoDisabled = this.Services.GetService <IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));
                }
                else
                {
                    // Enable undo on "additional documents" or if no document can be found.
                    needsUndoDisabled = false;
                }
            }

            return(new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled));
        }
        internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
        {
            var globalUndoService = this.Services.GetService <IGlobalUndoService>();
            var needsUndoDisabled = false;

            // Do not save the file if is open and there is not a global undo transaction.
            var needsSave = globalUndoService.IsGlobalTransactionOpen(this) || !hostDocument.IsOpen;

            if (needsSave)
            {
                if (this.CurrentSolution.ContainsDocument(hostDocument.Id))
                {
                    // Disable undo on generated documents
                    needsUndoDisabled = this.CurrentSolution.GetDocument(hostDocument.Id).IsGeneratedCode(CancellationToken.None);
                }
                else
                {
                    // Enable undo on "additional documents" or if no document can be found.
                    needsUndoDisabled = false;
                }
            }

            return(new InvisibleEditor(DeferredState.ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled));
        }
예제 #24
0
 /// <summary>
 /// Finds the current context hierarchy for the given document. If the document is in a
 /// Shared Code project, this returns that project's SharedItemContextHierarchy. If the
 /// document is linked into multiple projects, this returns the hierarchy in which it is
 /// currently open as indicated by the running document table. Otherwise, it returns the
 /// hierarchy of the document's project.
 /// </summary>
 public static IVsHierarchy GetContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return s_singleton.GetContextHierarchyInternal(document, runningDocumentTable);
 }
예제 #25
0
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, ImmutableArray<string>.Empty, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType));

            return vsDocument != null;
        }
예제 #26
0
        private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();

            return GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy;
        }
예제 #27
0
        /// <summary>
        /// Notifies the document provider that this document is now registered in a project.
        /// </summary>
        public void NotifyDocumentRegisteredToProject(IVisualStudioHostDocument document)
        {
            // Ignore any other unknown kinds of documents
            var standardDocument = document as StandardTextDocument;
            if (standardDocument == null)
            {
                return;
            }

            // If it's already open, then we have nothing more to do here.
            if (standardDocument.IsOpen)
            {
                return;
            }

            uint docCookie;
            if (RunningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie))
            {
                TryProcessOpenForDocCookie(docCookie);
            }
        }
예제 #28
0
 /// <summary>
 /// Finds the current context hierarchy for the given document. If the document is in a
 /// Shared Code project, this returns that project's SharedItemContextHierarchy. If the
 /// document is linked into multiple projects, this returns the hierarchy in which it is
 /// currently open as indicated by the running document table. Otherwise, it returns the
 /// hierarchy of the document's project.
 /// </summary>
 public static IVsHierarchy GetContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return(s_singleton.GetContextHierarchyInternal(document, runningDocumentTable));
 }
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, filePath, SourceCodeKind.Regular,
                tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType),
                _ => SpecializedCollections.EmptyReadOnlyList<string>());

            return vsDocument != null;
        }
예제 #30
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     // runningDocumentTable might be null for tests.
     return runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable);
 }
예제 #31
0
        internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
        {
            // We need to ensure the file is saved, only if a global undo transaction is open
            var globalUndoService = this.Services.GetService<IGlobalUndoService>();
            var needsSave = globalUndoService.IsGlobalTransactionOpen(this);

            var needsUndoDisabled = false;
            if (needsSave)
            {
                if (this.CurrentSolution.ContainsDocument(hostDocument.Id))
                {
                    // Disable undo on generated documents
                    needsUndoDisabled = this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));
                }
                else
                {
                    // Enable undo on "additional documents" or if no document can be found.
                    needsUndoDisabled = false;
                }
            }

            return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled);
        }
예제 #32
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return(document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable));
 }
예제 #33
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable);
 }
예제 #34
0
        internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext)
        {
            _additionalDocuments.Add(document.Id, document);
            _documentMonikers.Add(document.Key.Moniker, document);

            if (_pushingChangesToWorkspaceHosts)
            {
                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentAdded(document.GetInitialState()));

                if (document.IsOpen)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
                }
            }

            document.Opened += s_additionalDocumentOpenedEventHandler;
            document.Closing += s_additionalDocumentClosingEventHandler;
            document.UpdatedOnDisk += s_additionalDocumentUpdatedOnDiskEventHandler;

            DocumentProvider.NotifyDocumentRegisteredToProject(document);

            if (!_pushingChangesToWorkspaceHosts && document.IsOpen)
            {
                StartPushingToWorkspaceAndNotifyOfOpenDocuments();
            }
        }
예제 #35
0
        private void AddGeneratedDocument(IVisualStudioHostDocument document, bool isCurrentContext)
        {
            // We do not want to allow message pumping/reentrancy when processing project system changes.
            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                _documents.Add(document.Id, document);
                _documentMonikers.Add(document.Key.Moniker, document);

                if (_pushingChangesToWorkspaceHosts)
                {
                    if (document.IsOpen)
                    {
                        this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
                    }
                }

                document.Opened += s_documentOpenedEventHandler;
                document.Closing += s_documentClosingEventHandler;
                document.UpdatedOnDisk += s_documentUpdatedOnDiskEventHandler;

                DocumentProvider.NotifyDocumentRegisteredToProject(document);

                if (!_pushingChangesToWorkspaceHosts && document.IsOpen)
                {
                    StartPushingToWorkspaceAndNotifyOfOpenDocuments();
                }
            }
        }
예제 #36
0
 internal abstract IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument document);
예제 #37
0
        private void UninitializeAdditionalDocument(IVisualStudioHostDocument document)
        {
            if (_pushingChangesToWorkspaceHosts)
            {
                if (document.IsOpen)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader));
                }

                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentRemoved(document.Id));
            }

            document.Opened -= s_additionalDocumentOpenedEventHandler;
            document.Closing -= s_additionalDocumentClosingEventHandler;
            document.UpdatedOnDisk -= s_additionalDocumentUpdatedOnDiskEventHandler;

            document.Dispose();
        }
        internal void OnFileIncludedInProject(IVisualStudioHostDocument document)
        {
            uint docCookie;
            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.FilePath, out docCookie))
            {
                TryRemoveDocumentFromMiscellaneousWorkspace(docCookie, document.FilePath);
            }

            _filesInProjects.Add(document.Key);
        }
예제 #39
0
        internal void RemoveAdditionalDocument(IVisualStudioHostDocument document)
        {
            _additionalDocuments.Remove(document.Id);
            _documentMonikers.Remove(document.Key.Moniker);

            UninitializeAdditionalDocument(document);
        }
예제 #40
0
        private void UninitializeDocument(IVisualStudioHostDocument document)
        {
            if (_pushingChangesToWorkspaceHosts)
            {
                if (document.IsOpen)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader, updateActiveContext: true));
                }

                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentRemoved(document.Id));
            }

            if (_miscellaneousFilesWorkspaceOpt != null)
            {
                _miscellaneousFilesWorkspaceOpt.OnFileRemovedFromProject(document);
            }

            document.Opened -= s_documentOpenedEventHandler;
            document.Closing -= s_documentClosingEventHandler;
            document.UpdatedOnDisk -= s_documentUpdatedOnDiskEventHandler;

            document.Dispose();
        }
예제 #41
0
        private void RemoveGeneratedDocument(IVisualStudioHostDocument document)
        {
            // We do not want to allow message pumping/reentrancy when processing project system changes.
            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                _documents.Remove(document.Id);
                _documentMonikers.Remove(document.Key.Moniker);

                UninitializeDocument(document);
                OnDocumentRemoved(document.Key.Moniker);
            }
        }
예제 #42
0
        internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext)
        {
            AssertIsForeground();

            lock (_gate)
            {
                _additionalDocuments.Add(document.Id, document);
                _documentMonikers.Add(document.Key.Moniker, document);
            }

            if (_pushingChangesToWorkspaceHosts)
            {
                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentAdded(document.GetInitialState()));

                if (document.IsOpen)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
                }
            }

            DocumentProvider.NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(document);

            if (!_pushingChangesToWorkspaceHosts && document.IsOpen)
            {
                StartPushingToWorkspaceAndNotifyOfOpenDocuments();
            }
        }
        internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
        {
            // We need to ensure the file is saved, only if a global undo transaction is open
            var globalUndoService = this.Services.GetService<IGlobalUndoService>();
            bool needsSave = globalUndoService.IsGlobalTransactionOpen(this);
            bool needsUndoDisabled = needsSave && this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));

            return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled);
        }
예제 #44
0
        internal void RemoveAdditionalDocument(IVisualStudioHostDocument document)
        {
            AssertIsForeground();

            lock (_gate)
            {
                _additionalDocuments.Remove(document.Id);
                _documentMonikers.Remove(document.Key.Moniker);
            }

            UninitializeAdditionalDocument(document);
        }
예제 #45
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     // runningDocumentTable might be null for tests.
     return(runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable));
 }
예제 #46
0
 internal abstract IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument document);
예제 #47
0
        private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();

            return(GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy);
        }
예제 #48
0
        private void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(IVisualStudioHostDocument document, CancellationToken cancellationToken)
        {
            AssertIsForeground();

            cancellationToken.ThrowIfCancellationRequested();

            // Ignore any other unknown kinds of documents
            var standardDocument = document as StandardTextDocument;
            if (standardDocument == null)
            {
                return;
            }

            // If it's already open, then we have nothing more to do here.
            if (standardDocument.IsOpen)
            {
                return;
            }

            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie))
            {
                TryProcessOpenForDocCookie(docCookie, cancellationToken);
            }

            cancellationToken.ThrowIfCancellationRequested();
            CancelPendingDocumentInitializationTask(document);
        }
예제 #49
0
 /// <summary>
 /// Notifies the document provider that this document is now registered in a project.
 /// If we are on a foregroud thread, then this is done right away.
 /// Otherwise, we schedule a task on foreground task scheduler.
 /// </summary>
 public void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(IVisualStudioHostDocument document)
 {
     if (IsForeground())
     {
         NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cancellationToken: CancellationToken.None);
     }
     else
     {
         var cts = new CancellationTokenSource();
         var task = InvokeBelowInputPriority(() => NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cts.Token), cts.Token);
         AddPendingDocumentInitializationTask(document, task, cts);
     }
 }
        internal void OnFileRemovedFromProject(IVisualStudioHostDocument document)
        {
            // Remove the document key from the filesInProjects map first because adding documents
            // to the misc files workspace requires that they not appear in this map.
            _filesInProjects.Remove(document.Key);

            uint docCookie;
            if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie))
            {
                AddDocumentToMiscellaneousOrMetadataAsSourceWorkspace(docCookie, document.Key.Moniker);
            }
        }
예제 #51
0
        private void UninitializeDocument(IVisualStudioHostDocument document)
        {
            AssertIsForeground();

            if (_pushingChangesToWorkspaceHosts)
            {
                if (document.IsOpen)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader, updateActiveContext: true));
                }

                this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentRemoved(document.Id));
            }

            document.Opened -= s_documentOpenedEventHandler;
            document.Closing -= s_documentClosingEventHandler;
            document.UpdatedOnDisk -= s_documentUpdatedOnDiskEventHandler;

            document.Dispose();
        }
예제 #52
0
 private void AddPendingDocumentInitializationTask(IVisualStudioHostDocument document, Task task, CancellationTokenSource cts)
 {
     var taskAndTokenSource = new TaskAndTokenSource() { Task = task, CancellationTokenSource = cts };
     lock (_gate)
     {
         // Add taskAndTokenSource to the pending document initialization tasks.
         // Check for cancellation before adding as the task might already have been completed/cancelled/faulted before we reached here.
         if (!cts.IsCancellationRequested && !task.IsCompleted)
         {
             _pendingDocumentInitializationTasks.Add(document.Id, taskAndTokenSource);
         }
     }
 }
예제 #53
0
        internal void AddDocument(IVisualStudioHostDocument document, bool isCurrentContext, bool hookupHandlers)
        {
            AssertIsForeground();

            // We do not want to allow message pumping/reentrancy when processing project system changes.
            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                lock (_gate)
                {
                    _documents.Add(document.Id, document);
                    _documentMonikers.Add(document.Key.Moniker, document);
                }

                if (_pushingChangesToWorkspaceHosts)
                {
                    this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentAdded(document.GetInitialState()));

                    if (document.IsOpen)
                    {
                        this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
                    }
                }

                if (hookupHandlers)
                {
                    document.Opened += s_documentOpenedEventHandler;
                    document.Closing += s_documentClosingEventHandler;
                    document.UpdatedOnDisk += s_documentUpdatedOnDiskEventHandler;
                }

                DocumentProvider.NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(document);

                if (!_pushingChangesToWorkspaceHosts && document.IsOpen)
                {
                    StartPushingToWorkspaceAndNotifyOfOpenDocuments();
                }
            }
        }
예제 #54
0
 private void CancelPendingDocumentInitializationTask(IVisualStudioHostDocument document)
 {
     lock (_gate)
     {
         CancelPendingDocumentInitializationTask_NoLock(document);
     }
 }
예제 #55
0
        internal void RemoveDocument(IVisualStudioHostDocument document)
        {
            AssertIsForeground();

            // We do not want to allow message pumping/reentrancy when processing project system changes.
            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                lock (_gate)
                {
                    _documents.Remove(document.Id);
                    _documentMonikers.Remove(document.Key.Moniker);
                }

                UninitializeDocument(document);
                OnDocumentRemoved(document.Key.Moniker);
            }
        }
예제 #56
0
 private void CancelPendingDocumentInitializationTask_NoLock(IVisualStudioHostDocument document)
 {
     // Remove pending initialization task for the document, if any, and dispose the cancellation token source.
     if (_pendingDocumentInitializationTasks.TryGetValue(document.Id, out var taskAndTokenSource))
     {
         taskAndTokenSource.CancellationTokenSource.Cancel();
         taskAndTokenSource.CancellationTokenSource.Dispose();
         _pendingDocumentInitializationTasks.Remove(document.Id);
     }
 }