Exemplo n.º 1
0
        public override VisualStudioDocumentTracker Create(ITextBuffer textBuffer)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (!_textDocumentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                Debug.Fail("Text document should be available from the text buffer.");
                return(null);
            }

            var filePath = textDocument.FilePath;
            var project  = _projectService.GetHostProject(textBuffer);

            if (project == null)
            {
                Debug.Fail("Text buffer should belong to a project.");
                return(null);
            }

            var projectPath = _projectService.GetProjectPath(project);

            var tracker = new DefaultVisualStudioDocumentTracker(_foregroundDispatcher, filePath, projectPath, _projectManager, _editorSettingsManager, _workspace, textBuffer, _importDocumentManager);

            return(tracker);
        }
        public override bool TryGetProjectPath(ITextBuffer textBuffer, out string filePath)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            var project = _projectService.GetHostProject(textBuffer);

            if (project == null)
            {
                filePath = null;
                return(false);
            }

            filePath = _projectService.GetProjectPath(project);
            return(true);
        }
Exemplo n.º 3
0
        private bool IsSupportedProject(ITextBuffer textBuffer)
        {
            // Fundamentally we have a Razor half of the world 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.
            object project            = null;
            var    isSupportedProject = false;

            // 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.
            if ((project = _projectService.GetHostProject(textBuffer)) != null)
            {
                isSupportedProject = _projectService.IsSupportedProject(project);
            }

            return(isSupportedProject);
        }
Exemplo n.º 4
0
        public override bool TryGetProjectPath(ITextBuffer textBuffer, out string filePath)
        {
            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (_liveShareProjectPathProvider != null &&
                _liveShareProjectPathProvider.TryGetProjectPath(textBuffer, out filePath))
            {
                return(true);
            }

            var project = _projectService.GetHostProject(textBuffer);

            if (project is null)
            {
                filePath = null;
                return(false);
            }

            filePath = _projectService.GetProjectPath(project);
            return(true);
        }