示例#1
0
        public override bool TryResolvePotentialProject(string documentFilePath, out ProjectSnapshot projectSnapshot)
        {
            if (documentFilePath == null)
            {
                throw new ArgumentNullException(nameof(documentFilePath));
            }

            _foregroundDispatcher.AssertForegroundThread();

            var normalizedDocumentPath = _filePathNormalizer.Normalize(documentFilePath);
            var projects = _projectSnapshotManagerAccessor.Instance.Projects;

            for (var i = 0; i < projects.Count; i++)
            {
                if (projects[i].FilePath == _miscellaneousHostProject.FilePath)
                {
                    // We don't resolve documents to belonging to the miscellaneous project.
                    continue;
                }

                var projectDirectory = _filePathNormalizer.GetDirectory(projects[i].FilePath);
                if (normalizedDocumentPath.StartsWith(projectDirectory, FilePathComparison.Instance))
                {
                    projectSnapshot = projects[i];
                    return(true);
                }
            }

            projectSnapshot = null;
            return(false);
        }
示例#2
0
        public override bool TryResolveProject(string documentFilePath, out ProjectSnapshot projectSnapshot, bool enforceDocumentInProject = true)
        {
            if (documentFilePath == null)
            {
                throw new ArgumentNullException(nameof(documentFilePath));
            }

            _foregroundDispatcher.AssertForegroundThread();

            var normalizedDocumentPath = _filePathNormalizer.Normalize(documentFilePath);
            var projects = _projectSnapshotManagerAccessor.Instance.Projects;

            for (var i = 0; i < projects.Count; i++)
            {
                projectSnapshot = projects[i];

                if (projectSnapshot.FilePath == _miscellaneousHostProject.FilePath)
                {
                    if (enforceDocumentInProject &&
                        IsDocumentInProject(projectSnapshot, documentFilePath))
                    {
                        return(true);
                    }

                    continue;
                }

                var projectDirectory = _filePathNormalizer.GetDirectory(projectSnapshot.FilePath);
                if (normalizedDocumentPath.StartsWith(projectDirectory, FilePathComparison.Instance) &&
                    (!enforceDocumentInProject || IsDocumentInProject(projectSnapshot, documentFilePath)))
                {
                    return(true);
                }
            }

            projectSnapshot = null;
            return(false);