Example #1
0
        private IEnumerable <ModulePath> GetImportNames(Uri document)
        {
            var filePath = GetLocalPath(document);

            if (!string.IsNullOrEmpty(filePath))
            {
                if (!string.IsNullOrEmpty(_rootDir) && ModulePath.FromBasePathAndFile_NoThrow(_rootDir, filePath, out var mp))
                {
                    yield return(mp);
                }

                foreach (var sp in _analyzer.GetSearchPaths())
                {
                    if (ModulePath.FromBasePathAndFile_NoThrow(sp, filePath, out mp))
                    {
                        yield return(mp);
                    }
                }
            }

            if (document.Scheme == "python")
            {
                var path = Path.Combine(document.Host, document.AbsolutePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar));
                if (ModulePath.FromBasePathAndFile_NoThrow("", path, p => true, out var mp, out _, out _))
                {
                    yield return(mp);
                }
            }
        }
Example #2
0
 private void PythonAnalyzer_SearchPathsChanged(object sender, EventArgs e)
 {
     _searchPaths     = _state.GetSearchPaths();
     _searchPathDb    = null;
     _zipPackageCache = null;
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
Example #3
0
        private async Task <IReadOnlyDictionary <string, string> > GetUserSearchPathPackagesAsync(CancellationToken cancellationToken)
        {
            Log?.Log(TraceLevel.Verbose, "GetUserSearchPathPackagesAsync");
            var ussp = _userSearchPathPackages;

            if (ussp == null)
            {
                IReadOnlyList <string> usp;
                lock (_userSearchPathsLock) {
                    usp  = _userSearchPaths;
                    ussp = _userSearchPathPackages;
                }
                if (ussp != null || usp == null || !usp.Any())
                {
                    return(ussp);
                }

                ussp = await _factory.ModuleResolution.GetPackagesFromSearchPathsAsync(_analyzer.GetSearchPaths(), cancellationToken);

                lock (_userSearchPathsLock) {
                    if (_userSearchPathPackages == null)
                    {
                        _userSearchPathPackages = ussp;
                    }
                    else
                    {
                        ussp = _userSearchPathPackages;
                    }
                }
            }
            Log?.Log(TraceLevel.Verbose, "GetPackagesFromSearchPathsAsync", _userSearchPathPackages.Keys.Cast <object>().ToArray());
            return(ussp);
        }
Example #4
0
        private void PythonAnalyzer_SearchPathsChanged(object sender, EventArgs e)
        {
            _searchPaths     = _state.GetSearchPaths();
            _searchPathDb    = null;
            _zipPackageCache = null;

            BeginUpdateSearchPathPackages();
        }
Example #5
0
        private void PythonAnalyzer_SearchPathsChanged(object sender, EventArgs e)
        {
            lock (_searchPathDbLock) {
                _searchPaths     = _state.GetSearchPaths();
                _searchPathDb    = null;
                _zipPackageCache = null;
            }

            BeginUpdateSearchPathPackagesAsync().DoNotWait();
        }
Example #6
0
 private void Analyzer_SearchPathsChanged(object sender, EventArgs e)
 {
     lock (_userSearchPathsLock) {
         // Remove imported modules from search paths so we will
         // import them again.
         foreach (var name in _userSearchPathImported.MaybeEnumerate())
         {
             IPythonModule mod;
             _modules.TryRemove(name, out mod);
         }
         _userSearchPathImported = null;
         _userSearchPathPackages = null;
         _userSearchPaths        = _analyzer.GetSearchPaths();
     }
     ModuleNamesChanged?.Invoke(this, EventArgs.Empty);
 }
Example #7
0
        public void Initialize(PythonAnalyzer analyzer)
        {
            if (_analyzer != null)
            {
                return;
            }

            _analyzer = analyzer;
            if (analyzer != null)
            {
                lock (_userSearchPathsLock) {
                    _userSearchPaths = analyzer.GetSearchPaths();
                }
                analyzer.SearchPathsChanged += Analyzer_SearchPathsChanged;
                var bm = analyzer.BuiltinModule;
                if (!string.IsNullOrEmpty(bm?.Name))
                {
                    _modules[analyzer.BuiltinModule.Name] = analyzer.BuiltinModule.InterpreterModule;
                }
            }
        }
Example #8
0
        public void Initialize(PythonAnalyzer state)
        {
            if (_analyzer != null)
            {
                _analyzer.SearchPathsChanged -= Analyzer_SearchPathsChanged;
            }

            _analyzer = state;

            if (state != null)
            {
                lock (_userSearchPathsLock) {
                    _userSearchPaths = state.GetSearchPaths();
                }
                state.SearchPathsChanged += Analyzer_SearchPathsChanged;
                var bm = state.BuiltinModule;
                if (!string.IsNullOrEmpty(bm?.Name))
                {
                    _modules[state.BuiltinModule.Name] = state.BuiltinModule.InterpreterModule;
                }
            }
        }