Ejemplo n.º 1
0
        internal CodeModelProjectCache GetCodeModelCache()
        {
            Contract.ThrowIfNull(_vsProject);
            Contract.ThrowIfNull(_visualStudioWorkspace);

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

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

                    if (project != null)
                    {
                        _codeModelCache = new CodeModelProjectCache(_vsProject, _serviceProvider, project.LanguageServices, _visualStudioWorkspace);
                    }
                }

                return(_codeModelCache);
            }
        }