Ejemplo n.º 1
0
        public VisualStudioProjectTracker(IServiceProvider serviceProvider)
        {
            _projectMap = new Dictionary<ProjectId, AbstractProject>();
            _projectPathToIdMap = new Dictionary<string, ProjectId>(StringComparer.OrdinalIgnoreCase);

            _serviceProvider = serviceProvider;
            _workspaceHosts = new List<WorkspaceHostState>(capacity: 1);

            _vsSolution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));

            uint solutionEventsCookie;
            _vsSolution.AdviseSolutionEvents(this, out solutionEventsCookie);
            _solutionEventsCookie = solutionEventsCookie;

            // It's possible that we're loading after the solution has already fully loaded, so see if we missed the event
            var shellMonitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));

            uint fullyLoadedContextCookie;
            if (ErrorHandler.Succeeded(shellMonitorSelection.GetCmdUIContextCookie(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, out fullyLoadedContextCookie)))
            {
                int fActive;
                if (ErrorHandler.Succeeded(shellMonitorSelection.IsCmdUIContextActive(fullyLoadedContextCookie, out fActive)) && fActive != 0)
                {
                    _solutionLoadComplete = true;
                }
            }
        }
Ejemplo n.º 2
0
        public static bool TryGetBufferFromMoniker(
            this IVsRunningDocumentTable4 runningDocumentTable,
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            string moniker,
            [NotNullWhen(true)] out ITextBuffer?textBuffer
            )
        {
            textBuffer = null;
            if (!runningDocumentTable.IsFileOpen(moniker))
            {
                return(false);
            }

            var cookie = runningDocumentTable.GetDocumentCookie(moniker);

            if (!runningDocumentTable.IsDocumentInitialized(cookie))
            {
                return(false);
            }

            return(TryGetBuffer(
                       runningDocumentTable,
                       editorAdaptersFactoryService,
                       cookie,
                       out textBuffer
                       ));
        }
Ejemplo n.º 3
0
        public VisualStudioProjectTracker(IServiceProvider serviceProvider, HostWorkspaceServices workspaceServices)
            : base(assertIsForeground: true)
        {
            _projectMap         = new Dictionary <ProjectId, AbstractProject>();
            _projectPathToIdMap = new Dictionary <string, ProjectId>(StringComparer.OrdinalIgnoreCase);

            _serviceProvider   = serviceProvider;
            _workspaceHosts    = new List <WorkspaceHostState>(capacity: 1);
            _workspaceServices = workspaceServices;

            _vsSolution           = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            _vsSolution.AdviseSolutionEvents(this, out var solutionEventsCookie);
            _solutionEventsCookie = solutionEventsCookie;

            // It's possible that we're loading after the solution has already fully loaded, so see if we missed the event
            var shellMonitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));

            if (ErrorHandler.Succeeded(shellMonitorSelection.GetCmdUIContextCookie(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, out var fullyLoadedContextCookie)))
            {
                if (ErrorHandler.Succeeded(shellMonitorSelection.IsCmdUIContextActive(fullyLoadedContextCookie, out var fActive)) && fActive != 0)
                {
                    _solutionLoadComplete = true;
                }
            }
        }
        public VisualStudioEditorDocumentManager(
            ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
            JoinableTaskContext joinableTaskContext,
            FileChangeTrackerFactory fileChangeTrackerFactory,
            IVsRunningDocumentTable runningDocumentTable,
            IVsEditorAdaptersFactoryService editorAdaptersFactory)
            : base(projectSnapshotManagerDispatcher, joinableTaskContext, fileChangeTrackerFactory)
        {
            if (runningDocumentTable is null)
            {
                throw new ArgumentNullException(nameof(runningDocumentTable));
            }

            if (editorAdaptersFactory is null)
            {
                throw new ArgumentNullException(nameof(editorAdaptersFactory));
            }

            if (fileChangeTrackerFactory is null)
            {
                throw new ArgumentNullException(nameof(fileChangeTrackerFactory));
            }

            _runningDocumentTable  = (IVsRunningDocumentTable4)runningDocumentTable;
            _editorAdaptersFactory = editorAdaptersFactory;

            _documentsByCookie = new Dictionary <uint, List <DocumentKey> >();
            _cookiesByDocument = new Dictionary <DocumentKey, uint>();
        }
Ejemplo n.º 5
0
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            bool signUpForFileChangeNotification)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer                 = projectContainer;
            this.RunningDocumentTable         = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this.EditorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            this.ContentTypeRegistryService   = componentModel.GetService <IContentTypeRegistryService>();
            _textUndoHistoryRegistry          = componentModel.GetService <ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            // In the CodeSense scenario we will receive file change notifications from the native
            // Language Services, so we don't want to sign up for them ourselves.
            if (signUpForFileChangeNotification)
            {
                _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
            }

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            int installed;

            Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed));
            IsRoslynPackageInstalled = installed != 0;

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable;

            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
        public RunningDocumentTableEventTracker(
            IThreadingContext threadingContext,
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IVsRunningDocumentTable runningDocumentTable,
            IRunningDocumentTableEventListener listener
            )
        {
            Contract.ThrowIfNull(threadingContext);
            Contract.ThrowIfNull(editorAdaptersFactoryService);
            Contract.ThrowIfNull(runningDocumentTable);
            Contract.ThrowIfNull(listener);

            _foregroundAffinitization = new ForegroundThreadAffinitizedObject(
                threadingContext,
                assertIsForeground: false
                );
            _runningDocumentTable         = (IVsRunningDocumentTable4)runningDocumentTable;
            _editorAdaptersFactoryService = editorAdaptersFactoryService;
            _listener = listener;

            // Advise / Unadvise for the RDT is free threaded past 16.0
            ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(
                this,
                out _runningDocumentTableEventsCookie
                );
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a document provider.
        /// </summary>
        /// <param name="projectContainer">Project container for the documents.</param>
        /// <param name="serviceProvider">Service provider</param>
        /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param>
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            VisualStudioDocumentTrackingService documentTrackingService)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this._documentTrackingServiceOpt = documentTrackingService;
            this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this._editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this._contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
Ejemplo n.º 8
0
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            bool signUpForFileChangeNotification)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this.EditorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this.ContentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            // In the CodeSense scenario we will receive file change notifications from the native
            // Language Services, so we don't want to sign up for them ourselves.
            if (signUpForFileChangeNotification)
            {
                _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
            }

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            int installed;
            Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed));
            IsRoslynPackageInstalled = installed != 0;

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a document provider.
        /// </summary>
        /// <param name="serviceProvider">Service provider</param>
        /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param>
        public DocumentProvider(
            VisualStudioProjectTracker projectTracker,
            IServiceProvider serviceProvider,
            VisualStudioDocumentTrackingService documentTrackingService)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectTracker = projectTracker;
            this._documentTrackingServiceOpt   = documentTrackingService;
            this._runningDocumentTable         = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this._editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            this._contentTypeRegistryService   = componentModel.GetService <IContentTypeRegistryService>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));

            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable;

            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
Ejemplo n.º 10
0
 private OpenFileTracker(VisualStudioWorkspaceImpl workspace, IVsRunningDocumentTable4 runningDocumentTable, IComponentModel componentModel)
 {
     _workspace = workspace;
     _foregroundAffinitization     = new ForegroundThreadAffinitizedObject(workspace._threadingContext, assertIsForeground: true);
     _runningDocumentTable         = runningDocumentTable;
     _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
     _asyncOperationListener       = componentModel.GetService <IAsynchronousOperationListenerProvider>().GetListener(FeatureAttribute.Workspace);
 }
Ejemplo n.º 11
0
        public static bool IsDocumentInitialized(
            this IVsRunningDocumentTable4 runningDocTable,
            uint docCookie
            )
        {
            var flags = runningDocTable.GetDocumentFlags(docCookie);

            return((flags & (uint)_VSRDTFLAGS4.RDT_PendingInitialization) == 0);
        }
Ejemplo n.º 12
0
 public VisualStudioDocumentNavigationService(
     IThreadingContext threadingContext,
     SVsServiceProvider serviceProvider,
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
     : base(threadingContext)
 {
     _serviceProvider = serviceProvider;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _runningDocumentTable         = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
 }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        public static bool TryGetBuffer(this IVsRunningDocumentTable4 runningDocumentTable, IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
                                        uint docCookie, [NotNullWhen(true)] out ITextBuffer?textBuffer)
        {
            textBuffer = null;

            if (runningDocumentTable.GetDocumentData(docCookie) is IVsTextBuffer bufferAdapter)
            {
                textBuffer = editorAdaptersFactoryService.GetDocumentBuffer(bufferAdapter);
                return(textBuffer != null);
            }

            return(false);
        }
 public VisualStudioDocumentNavigationService(
     IThreadingContext threadingContext,
     SVsServiceProvider serviceProvider,
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     Lazy <SourceGeneratedFileManager> sourceGeneratedFileManager /* lazy to avoid circularities */)
     : base(threadingContext)
 {
     _serviceProvider = serviceProvider;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _runningDocumentTable         = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
     _threadingContext             = threadingContext;
     _sourceGeneratedFileManager   = sourceGeneratedFileManager;
 }
Ejemplo n.º 16
0
        public static bool TryGetBuffer(this IVsRunningDocumentTable4 runningDocumentTable, IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
                                        uint docCookie, [NotNullWhen(true)] out ITextBuffer?textBuffer)
        {
            textBuffer = null;

            // The cast from dynamic to object doesn't change semantics, but avoids loading the dynamic binder
            // which saves us JIT time in this method and an assembly load.
            if ((object)runningDocumentTable.GetDocumentData(docCookie) is IVsTextBuffer bufferAdapter)
            {
                textBuffer = editorAdaptersFactoryService.GetDocumentBuffer(bufferAdapter);
                return(textBuffer != null);
            }

            return(false);
        }
Ejemplo n.º 17
0
        public static bool TryGetCookieForInitializedDocument(this IVsRunningDocumentTable4 runningDocTable, string moniker, out uint docCookie)
        {
            docCookie = VSConstants.VSCOOKIE_NIL;

            if (runningDocTable != null && runningDocTable.IsMonikerValid(moniker))
            {
                var foundDocCookie = runningDocTable.GetDocumentCookie(moniker);

                if (runningDocTable.IsDocumentInitialized(foundDocCookie))
                {
                    docCookie = foundDocCookie;
                    return(true);
                }
            }

            return(false);
        }
        public DocumentMonitor(CommentTaskProvider provider)
        {
            this.provider = provider;

            this.docTable             = new RunningDocumentTable(this.provider.ServiceProvider);
            this.docTable4            = (IVsRunningDocumentTable4)this.provider.ServiceProvider.GetService(typeof(SVsRunningDocumentTable));
            this.docTableAdviseCookie = this.docTable.Advise(this);

            // Creating these components without going through MEF is documented in MSDN under
            // "Using Visual Studio Editor Services in a Non-MEF Component" in the article "Adapting
            // Legacy Code to the New Editor" https://msdn.microsoft.com/en-us/library/dd885359.aspx.
            this.componentModel  = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            this.adapterFactory  = this.componentModel.GetService <IVsEditorAdaptersFactoryService>();
            this.documentFactory = this.componentModel.GetService <ITextDocumentFactoryService>();

            this.documentFactory.TextDocumentCreated  += this.DocumentFactory_TextDocumentCreated;
            this.documentFactory.TextDocumentDisposed += this.DocumentFactory_TextDocumentDisposed;
        }
Ejemplo n.º 19
0
        public MiscellaneousFilesWorkspace(
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IMetadataAsSourceFileService fileTrackingMetadataAsSourceService,
            SaveEventsService saveEventsService,
            VisualStudioWorkspace visualStudioWorkspace,
            SVsServiceProvider serviceProvider) :
            base(visualStudioWorkspace.Services.HostServices, "MiscellaneousFiles")
        {
            _editorAdaptersFactoryService        = editorAdaptersFactoryService;
            _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService;
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            _textManager          = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie);

            _metadataReferences = ImmutableArray.CreateRange(CreateMetadataReferences());
            _documentProvider   = new RoslynDocumentProvider(this, serviceProvider);
            saveEventsService.StartSendingSaveEvents();
        }
Ejemplo n.º 20
0
        public MiscellaneousFilesWorkspace(
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IMetadataAsSourceFileService fileTrackingMetadataAsSourceService,
            SaveEventsService saveEventsService,
            VisualStudioWorkspace visualStudioWorkspace,
            SVsServiceProvider serviceProvider) :
            base(visualStudioWorkspace.Services.HostServices, WorkspaceKind.MiscellaneousFiles)
        {
            _editorAdaptersFactoryService = editorAdaptersFactoryService;
            _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService;
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie);

            _metadataReferences = ImmutableArray.CreateRange(CreateMetadataReferences());
            _documentProvider = new RoslynDocumentProvider(this, serviceProvider);
            saveEventsService.StartSendingSaveEvents();
        }
Ejemplo n.º 21
0
        public MiscellaneousFilesWorkspace(
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IMetadataAsSourceFileService fileTrackingMetadataAsSourceService,
            SaveEventsService saveEventsService,
            VisualStudioWorkspace visualStudioWorkspace,
            SVsServiceProvider serviceProvider) :
            base(visualStudioWorkspace.Services.HostServices, WorkspaceKind.MiscellaneousFiles)
        {
            _foregroundThreadAffinitization = new ForegroundThreadAffinitizedObject(assertIsForeground: true);

            _editorAdaptersFactoryService        = editorAdaptersFactoryService;
            _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService;
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            _textManager          = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie);

            _metadataReferences = ImmutableArray.CreateRange(CreateMetadataReferences());
            _documentProvider   = new DocumentProvider(this, serviceProvider, documentTrackingService: null);
            saveEventsService.StartSendingSaveEvents();
        }
Ejemplo n.º 22
0
        private IEnumerable <ITextBuffer> GetDocumentTextBuffers(DocumentLoad documentLoad)
        {
            var list = new List <ITextBuffer>();

            foreach (var docCookie in _runningDocumentTable.GetRunningDocumentCookies())
            {
                if (documentLoad == DocumentLoad.RespectLazy && isLazyLoaded(docCookie))
                {
                    continue;
                }

                if (_vsAdapter.GetTextBufferForDocCookie(docCookie).TryGetValue(out ITextBuffer buffer))
                {
                    list.Add(buffer);
                }
            }

            return(list);

            bool isLazyLoaded(uint documentCookie)
            {
                try
                {
                    if (_runningDocumentTable4 is null)
                    {
                        _runningDocumentTable4 = _serviceProvider.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable4>();
                    }

                    var flags = (_VSRDTFLAGS4)_runningDocumentTable4.GetDocumentFlags(documentCookie);
                    return(0 != (flags & _VSRDTFLAGS4.RDT_PendingInitialization));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 23
0
        public VisualStudioEditorDocumentManager(
            ForegroundDispatcher foregroundDispatcher,
            FileChangeTrackerFactory fileChangeTrackerFactory,
            IVsRunningDocumentTable runningDocumentTable,
            IVsEditorAdaptersFactoryService editorAdaptersFactory)
            : base(foregroundDispatcher, fileChangeTrackerFactory)
        {
            if (runningDocumentTable == null)
            {
                throw new ArgumentNullException(nameof(runningDocumentTable));
            }

            if (editorAdaptersFactory == null)
            {
                throw new ArgumentNullException(nameof(editorAdaptersFactory));
            }

            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (fileChangeTrackerFactory == null)
            {
                throw new ArgumentNullException(nameof(fileChangeTrackerFactory));
            }

            _runningDocumentTable  = (IVsRunningDocumentTable4)runningDocumentTable;
            _editorAdaptersFactory = editorAdaptersFactory;

            var hr = runningDocumentTable.AdviseRunningDocTableEvents(new RunningDocumentTableEventSink(this), out _);

            Marshal.ThrowExceptionForHR(hr);

            _documentsByCookie = new Dictionary <uint, List <DocumentKey> >();
            _cookiesByDocument = new Dictionary <DocumentKey, uint>();
        }
Ejemplo n.º 24
0
 public VsRunningDocTableEvents(IVsRunningDocumentTable4 runningDocumentTable, IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
 {
     _runningDocumentTable         = runningDocumentTable;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
 }
Ejemplo n.º 25
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable);
 }
Ejemplo n.º 26
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();

            uint docCookie;

            if (!runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie))
            {
                return(null);
            }

            IVsHierarchy hierarchy;
            uint         itemid;

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

            return(hierarchy);
        }
Ejemplo n.º 27
0
        private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();

            return(GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy);
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 29
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     // runningDocumentTable might be null for tests.
     return(runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable));
 }
        public RunningDocumentInfo(IVsRunningDocumentTable rdt, uint docCookie)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();

            Validate.IsNotNull(rdt, "rdt");
            _rdt  = rdt;
            _rdt4 = rdt as IVsRunningDocumentTable4;

            DocCookie    = docCookie;
            _flags       = 0;
            _readLocks   = 0;
            _editLocks   = 0;
            _moniker     = null;
            _hierarchy   = null;
            _itemId      = 0;
            _docData     = null;
            _projectGuid = Guid.Empty;
            _shouldRequestHierarchyItem = false;
            _shouldRequestDocData       = false;

            if ((_rdt4 != null) && _rdt4.IsCookieValid(docCookie))
            {
                _flags       = _rdt4.GetDocumentFlags(docCookie);
                _readLocks   = _rdt4.GetDocumentReadLockCount(docCookie);
                _editLocks   = _rdt4.GetDocumentEditLockCount(docCookie);
                _moniker     = _rdt4.GetDocumentMoniker(docCookie);
                _projectGuid = _rdt4.GetDocumentProjectGuid(docCookie);

                // if the hierarchy has been initialized we can get the hierarchy/itemId now;
                // otherwise wait until they're needed so we don't prematurely load the project
                if (IsHierarchyInitialized)
                {
                    _rdt4.GetDocumentHierarchyItem(DocCookie, out _hierarchy, out _itemId);
                }
                else
                {
                    _shouldRequestHierarchyItem = true;
                }

                // if the document has been initialized we can get the and docdata now;
                // otherwise wait until it's needed so we don't prematurely initialize the document
                if (IsDocumentInitialized)
                {
                    _docData = _rdt4.GetDocumentData(DocCookie);
                }
                else
                {
                    _shouldRequestDocData = true;
                }
            }
            else
            {
                IntPtr docData = IntPtr.Zero;

                try
                {
                    _rdt.GetDocumentInfo(docCookie, out _flags, out _readLocks, out _editLocks,
                                         out _moniker, out _hierarchy, out _itemId, out docData);

                    if (docData != IntPtr.Zero)
                    {
                        _docData = Marshal.GetObjectForIUnknown(docData);
                    }
                }
                finally
                {
                    if (docData != IntPtr.Zero)
                    {
                        Marshal.Release(docData);
                    }
                }
            }
        }
Ejemplo n.º 31
0
 public static bool IsFileOpen(
     this IVsRunningDocumentTable4 runningDocumentTable,
     string fileName
     ) => runningDocumentTable.IsMonikerValid(fileName);
Ejemplo n.º 32
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     return(document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable));
 }
Ejemplo n.º 33
0
 public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
 {
     // runningDocumentTable might be null for tests.
     return runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable);
 }
 public RunningDocumentTableEventSink(SolutionEventsBatchScopeCreator scopeCreator, IVsRunningDocumentTable runningDocumentTable)
 {
     _scopeCreator         = scopeCreator;
     _runningDocumentTable = (IVsRunningDocumentTable4)runningDocumentTable;
 }
Ejemplo n.º 35
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);
 }
Ejemplo n.º 36
0
        public AbstractProject(
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            MiscellaneousFilesWorkspace miscellaneousFilesWorkspaceOpt,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt)
        {
            Contract.ThrowIfNull(projectSystemName);

            _language = language;
            this.ServiceProvider = serviceProvider;
            _hierarchy = hierarchy;

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));

            this.DisplayName = _projectSystemName;
            _projectSystemName = projectSystemName;
            this.ProjectTracker = projectTracker;
            _miscellaneousFilesWorkspaceOpt = miscellaneousFilesWorkspaceOpt;
            _visualStudioWorkspaceOpt = visualStudioWorkspaceOpt;
            _hostDiagnosticUpdateSourceOpt = hostDiagnosticUpdateSourceOpt;

            UpdateProjectDisplayNameAndFilePath();

            if (_filePathOpt != null)
            {
                _version = VersionStamp.Create(File.GetLastWriteTimeUtc(_filePathOpt));
            }
            else
            {
                _version = VersionStamp.Create();
            }

            _id = this.ProjectTracker.GetOrCreateProjectIdForPath(_filePathOpt ?? _projectSystemName, _projectSystemName);
            if (reportExternalErrorCreatorOpt != null)
            {
                _externalErrorReporter = reportExternalErrorCreatorOpt(_id);
            }

            if (visualStudioWorkspaceOpt != null)
            {
                this.EditAndContinueImplOpt = new VsENCRebuildableProjectImpl(this);
            }

            ConnectHierarchyEvents();

            SetIsWebstite(hierarchy);
        }
Ejemplo n.º 37
0
        private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable)
        {
            AssertIsForeground();

            return GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy;
        }