Example #1
0
        public void Subscribe()
        {
            // Fundamentally we have a Razor half of the world as as soon as the document is open - and then later
            // the C# half of the world will be initialized. This code is in general pretty tolerant of
            // unexpected /impossible states.
            //
            // We also want to successfully shut down if the buffer is something other than .cshtml.
            IVsHierarchy hierarchy          = null;
            string       projectPath        = null;
            var          isSupportedProject = false;

            if (_textBuffer.ContentType.IsOfType(RazorLanguage.ContentType) &&

                // We expect the document to have a hierarchy even if it's not a real 'project'.
                // However the hierarchy can be null when the document is in the process of closing.
                (hierarchy = _projectService.GetHierarchy(_textBuffer)) != null)
            {
                projectPath        = _projectService.GetProjectPath(hierarchy);
                isSupportedProject = _projectService.IsSupportedProject(hierarchy);
            }

            if (!isSupportedProject || projectPath == null)
            {
                return;
            }

            _isSupportedProject      = isSupportedProject;
            _projectPath             = projectPath;
            _project                 = _projectManager.GetProjectWithFilePath(projectPath);
            _projectManager.Changed += ProjectManager_Changed;

            OnContextChanged(_project);
        }
Example #2
0
        public void Subscribe()
        {
            _importDocumentManager.OnSubscribed(this);

            _workspaceEditorSettings.Changed += EditorSettingsManager_Changed;
            _projectManager.Changed          += ProjectManager_Changed;
            _importDocumentManager.Changed   += Import_Changed;

            _isSupportedProject = true;
            _project            = _projectManager.GetProjectWithFilePath(_projectPath);

            OnContextChanged(_project, ContextChangeKind.ProjectChanged);
        }