Exemple #1
0
        private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error)
        {
            var hostProject = _workspace.GetHostProject(_projectId);

            if (!hostProject.ContainsFile(error.bstrFileName))
            {
                return(null);
            }

            var hostDocument = hostProject.GetCurrentDocumentFromPath(error.bstrFileName);

            var line   = error.iLine;
            var column = error.iCol;

            if (hostDocument is ContainedDocument containedDocument)
            {
                var span = new VsTextSpan
                {
                    iStartLine  = line,
                    iStartIndex = column,
                    iEndLine    = line,
                    iEndIndex   = column,
                };

                var spans = new VsTextSpan[1];
                Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan(
                                                span,
                                                spans));

                line   = spans[0].iStartLine;
                column = spans[0].iStartIndex;
            }

            return(GetDiagnosticData(error, hostDocument.Id, line, column));
        }
        private Dictionary <IVsHierarchy, List <uint> > GetHierarchiesAndItemIDsFromDocumentIDs(VisualStudioWorkspaceImpl visualStudioWorkspace, IEnumerable <DocumentId> changedDocumentIDs)
        {
            var hierarchyToItemIDsMap = new Dictionary <IVsHierarchy, List <uint> >();

            foreach (var docID in changedDocumentIDs)
            {
                var project = visualStudioWorkspace.GetHostProject(docID.ProjectId);
                var itemID  = project.GetDocumentOrAdditionalDocument(docID).GetItemId();

                if (itemID == (uint)VSConstants.VSITEMID.Nil)
                {
                    continue;
                }

                List <uint> itemIDsForCurrentHierarchy;
                if (!hierarchyToItemIDsMap.TryGetValue(project.Hierarchy, out itemIDsForCurrentHierarchy))
                {
                    itemIDsForCurrentHierarchy = new List <uint>();
                    hierarchyToItemIDsMap.Add(project.Hierarchy, itemIDsForCurrentHierarchy);
                }

                if (!itemIDsForCurrentHierarchy.Contains(itemID))
                {
                    itemIDsForCurrentHierarchy.Add(itemID);
                }
            }

            return(hierarchyToItemIDsMap);
        }
Exemple #3
0
        private CodeModelProjectCache GetCodeModelCache()
        {
            Contract.ThrowIfNull(_projectId);
            Contract.ThrowIfNull(_visualStudioWorkspace);

            using (_guard.DisposableWait())
            {
                if (_codeModelCache == null)
                {
                    var workspaceProject = _visualStudioWorkspace.CurrentSolution.GetProject(_projectId);
                    var hostProject      = _visualStudioWorkspace.GetHostProject(_projectId);
                    if (workspaceProject == null && !hostProject.PushingChangesToWorkspace)
                    {
                        // if this project hasn't been pushed yet, push it now so that the user gets a useful experience here.
                        hostProject.StartPushingToWorkspaceAndNotifyOfOpenDocuments();

                        // re-check to see whether we now has the project in the workspace
                        workspaceProject = _visualStudioWorkspace.CurrentSolution.GetProject(_projectId);
                    }

                    if (workspaceProject != null)
                    {
                        _codeModelCache = new CodeModelProjectCache(_threadingContext, _projectId, _codeModelInstanceFactory, _serviceProvider, workspaceProject.LanguageServices, _visualStudioWorkspace);
                    }
                }

                return(_codeModelCache);
            }
        }
        public static bool TryGetImageListAndIndex(this VisualStudioWorkspaceImpl workspace, IVsImageService2 imageService, ProjectId id, out IntPtr imageList, out ushort index)
        {
            var hierarchy = workspace.GetHostProject(id)?.Hierarchy;

            if (hierarchy != null)
            {
                return(TryGetImageListAndIndex(hierarchy, imageService, VSConstants.VSITEMID_ROOT, out imageList, out index));
            }

            imageList = default(IntPtr);
            index     = 0;
            return(false);
        }
        private Dictionary<IVsHierarchy, List<uint>> GetHierarchiesAndItemIDsFromDocumentIDs(VisualStudioWorkspaceImpl visualStudioWorkspace, IEnumerable<DocumentId> changedDocumentIDs)
        {
            var hierarchyToItemIDsMap = new Dictionary<IVsHierarchy, List<uint>>();

            foreach (var docID in changedDocumentIDs)
            {
                var project = visualStudioWorkspace.GetHostProject(docID.ProjectId);
                var itemID = project.GetDocumentOrAdditionalDocument(docID).GetItemId();

                if (itemID == (uint)VSConstants.VSITEMID.Nil)
                {
                    continue;
                }

                List<uint> itemIDsForCurrentHierarchy;
                if (!hierarchyToItemIDsMap.TryGetValue(project.Hierarchy, out itemIDsForCurrentHierarchy))
                {
                    itemIDsForCurrentHierarchy = new List<uint>();
                    hierarchyToItemIDsMap.Add(project.Hierarchy, itemIDsForCurrentHierarchy);
                }

                if (!itemIDsForCurrentHierarchy.Contains(itemID))
                {
                    itemIDsForCurrentHierarchy.Add(itemID);
                }
            }

            return hierarchyToItemIDsMap;
        }