Esempio n. 1
0
        internal bool TryGetProjectState(string projectName, out ProjectReadOnlyReason reason)
        {
            // We used to keep track of project ids but Venus may have multiple project ids during debugging sessions,
            // causing EnC fail to recognize they belong to the same project. Therefore, instead of ids,
            // their public display name (which is shared between multiple projects in Venus) is compared.
            foreach (var pair in Projects.Where((p) => baseSolution.GetProject(p.Key)?.Name == projectName))
            {
                reason = pair.Value;
                return(true);
            }

            reason = ProjectReadOnlyReason.NotLoaded;
            return(false);
        }
Esempio n. 2
0
        public bool IsProjectReadOnly(ProjectId id, out SessionReadOnlyReason sessionReason, out ProjectReadOnlyReason projectReason)
        {
            if (_debuggingSession == null)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.None;
                return(false);
            }

            // run mode - all documents that belong to the workspace shall be read-only:
            var editSession = _editSession;

            if (editSession == null)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.Running;
                return(true);
            }

            // break mode and stopped at exception - all documents shall be read-only:
            if (editSession.StoppedAtException)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.StoppedAtException;
                return(true);
            }

            // normal break mode - if the document belongs to a project that hasn't entered the edit session it shall be read-only:
            if (editSession.Projects.TryGetValue(id, out projectReason))
            {
                sessionReason = SessionReadOnlyReason.None;
                return(projectReason != ProjectReadOnlyReason.None);
            }

            sessionReason = SessionReadOnlyReason.None;
            projectReason = ProjectReadOnlyReason.MetadataNotAvailable;
            return(true);
        }
        private void OnReadOnlyDocumentEditAttempt(
            DocumentId documentId,
            SessionReadOnlyReason sessionReason,
            ProjectReadOnlyReason projectReason)
        {
            if (sessionReason == SessionReadOnlyReason.StoppedAtException)
            {
                _debugEncNotify.NotifyEncEditAttemptedAtInvalidStopState();
                return;
            }

            var hostProject = _vsProject.VisualStudioWorkspace.GetHostProject(documentId.ProjectId) as AbstractRoslynProject;
            if (hostProject?.EditAndContinueImplOpt?._metadata != null)
            {
                var projectHierarchy = _vsProject.VisualStudioWorkspace.GetHierarchy(documentId.ProjectId);
                _debugEncNotify.NotifyEncEditDisallowedByProject(projectHierarchy);
                return;
            }

            // NotifyEncEditDisallowedByProject is broken if the project isn't built at the time the debugging starts (debugger bug 877586).

            string message;
            if (sessionReason == SessionReadOnlyReason.Running)
            {
                message = "Changes are not allowed while code is running.";
            }
            else
            {
                Debug.Assert(sessionReason == SessionReadOnlyReason.None);

                switch (projectReason)
                {
                    case ProjectReadOnlyReason.MetadataNotAvailable:
                        message = "Changes are not allowed if the project wasn't built when debugging started.";
                        break;

                    case ProjectReadOnlyReason.NotLoaded:
                        message = "Changes are not allowed if the assembly has not been loaded.";
                        break;

                    default:
                        throw ExceptionUtilities.UnexpectedValue(projectReason);
                }
            }

            _notifications.SendNotification(message, title: FeaturesResources.EditAndContinue, severity: NotificationSeverity.Error);
        }
        public bool IsProjectReadOnly(string projectName, out SessionReadOnlyReason sessionReason, out ProjectReadOnlyReason projectReason)
        {
            if (_debuggingSession == null)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.None;
                return false;
            }

            // run mode - all documents that belong to the workspace shall be read-only:
            var editSession = _editSession;
            if (editSession == null)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.Running;
                return true;
            }

            // break mode and stopped at exception - all documents shall be read-only:
            if (editSession.StoppedAtException)
            {
                projectReason = ProjectReadOnlyReason.None;
                sessionReason = SessionReadOnlyReason.StoppedAtException;
                return true;
            }

            // normal break mode - if the document belongs to a project that hasn't entered the edit session it shall be read-only:
            if (editSession.TryGetProjectState(projectName, out projectReason))
            {
                sessionReason = SessionReadOnlyReason.None;
                return projectReason != ProjectReadOnlyReason.None;
            }

            sessionReason = SessionReadOnlyReason.None;
            projectReason = ProjectReadOnlyReason.MetadataNotAvailable;
            return true;
        }
Esempio n. 5
0
        internal bool TryGetProjectState(string projectName, out ProjectReadOnlyReason reason)
        {
            // We used to keep track of project ids but Venus may have multiple project ids during debugging sessions,
            // causing EnC fail to recognize they belong to the same project. Therefore, instead of ids,
            // their public display name (which is shared between multiple projects in Venus) is compared.
            foreach (var pair in Projects.Where((p) => _baseSolution.GetProject(p.Key)?.Name == projectName))
            {
                reason = pair.Value;
                return true;
            }

            reason = ProjectReadOnlyReason.NotLoaded;
            return false;
        }