Beispiel #1
0
 internal ExpressionAnalysis(VsProjectAnalyzer analyzer, string expression, ModuleAnalysis analysis, int index, ITrackingSpan span)
 {
     _expr = expression;
     _analysis = analysis;
     _index = index;
     _span = span;
     _analyzer = analyzer;
 }
Beispiel #2
0
        private void Parse(bool enqueOnly, CancellationToken cancel)
        {
            if (_tree == null) {
                return;
            }

            var oldParent = _myScope.ParentPackage;
            if (_filePath != null) {
                ProjectState.ModulesByFilename[_filePath] = _myScope;
            }

            if (oldParent != null) {
                // update us in our parent package
                oldParent.AddChildPackage(_myScope, _unit);
            } else if (_filePath != null) {
                // we need to check and see if our parent is a package for the case where we're adding a new
                // file but not re-analyzing our parent package.
                string parentFilename;
                if (Path.GetFileName(_filePath).Equals("__init__.py", StringComparison.OrdinalIgnoreCase)) {
                    // subpackage
                    parentFilename = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(_filePath)), "__init__.py");
                } else {
                    // just a module
                    parentFilename = Path.Combine(Path.GetDirectoryName(_filePath), "__init__.py");
                }

                ModuleInfo parentPackage;
                if (ProjectState.ModulesByFilename.TryGetValue(parentFilename, out parentPackage)) {
                    parentPackage.AddChildPackage(_myScope, _unit);
                }
            }

            _unit = new AnalysisUnit(_tree, _myScope.Scope);
            AnalysisLog.NewUnit(_unit);

            MyScope.Scope.Children.Clear();
            MyScope.Scope.ClearNodeScopes();
            MyScope.Scope.ClearNodeValues();

            // create new analysis object and add to the queue to be analyzed
            //var newAnalysis = new ModuleAnalysis(_unit);

            // collect top-level definitions first
            var walker = new OverviewWalker(this, _unit);
            _tree.Walk(walker);
            _myScope.Specialize();

            // It may be that we have analyzed some child packages of this package already, but because it wasn't analyzed,
            // the children were not registered. To handle this possibility, scan analyzed packages for children of this
            // package (checked by module name first, then sanity-checked by path), and register any that match.
            if (_filePath != null && _filePath.EndsWith("__init__.py")) {
                string pathPrefix = Path.GetDirectoryName(_filePath) + "\\";
                var children =
                    from pair in _projectState.ModulesByFilename
                    // Is the candidate child package in a subdirectory of our package?
                    let fileName = pair.Key
                    where fileName.StartsWith(pathPrefix)
                    let moduleName = pair.Value.Name
                    // Is the full name of the candidate child package qualified with the name of our package?
                    let lastDot = moduleName.LastIndexOf('.')
                    where lastDot > 0
                    let parentModuleName = moduleName.Substring(0, lastDot)
                    where parentModuleName == _myScope.Name
                    select pair.Value;
                foreach (var child in children) {
                    _myScope.AddChildPackage(child, _unit);
                }
            }

            _unit.Enqueue();

            if (!enqueOnly) {
                ((IGroupableAnalysisProject)_projectState).AnalyzeQueuedEntries(cancel);
            }

            // publish the analysis now that it's complete
            _currentAnalysis = new ModuleAnalysis(_unit, _unit.Scope);
        }