示例#1
0
        public void SrcNotDir()
        {
            var root    = TestData.GetTestSpecificPath();
            var rootSrc = Path.Combine(root, "src");
            var fs      = Substitute.For <IFileSystem>();

            fs.DirectoryExists(rootSrc).Returns(false);
            AutoSearchPathFinder.Find(fs, root).Should().BeEmpty();
        }
        /// <summary>
        /// Gets the user's configured search paths, by python.analysis.searchPaths,
        /// python.autoComplete.extraPaths, PYTHONPATH, or _initParam's searchPaths.
        /// </summary>
        /// <param name="pythonSection">The python section of the user config.</param>
        /// <returns>An array of search paths.</returns>
        private ImmutableArray<string> GetUserConfiguredPaths(JToken pythonSection) {
            var paths = ImmutableArray<string>.Empty;
            var set = false;

            if (pythonSection != null) {
                var autoComplete = pythonSection["autoComplete"];
                var analysis = pythonSection["analysis"];

                // The values of these may not be null even if the value is "unset", depending on
                // what the client uses as a default. Use null as a default anyway until the
                // extension uses a null default (and/or extraPaths is dropped entirely).
                var autoCompleteExtraPaths = GetSetting<IReadOnlyList<string>>(autoComplete, "extraPaths", null);
                var analysisSearchPaths = GetSetting<IReadOnlyList<string>>(analysis, "searchPaths", null);
                var analysisUsePYTHONPATH = GetSetting(analysis, "usePYTHONPATH", true);
                var analayisAutoSearchPaths = GetSetting(analysis, "autoSearchPaths", true);

                if (analysisSearchPaths != null) {
                    set = true;
                    paths = analysisSearchPaths.ToImmutableArray();
                } else if (autoCompleteExtraPaths != null) {
                    set = true;
                    paths = autoCompleteExtraPaths.ToImmutableArray();
                }

                if (analysisUsePYTHONPATH) {
                    var pythonpath = Environment.GetEnvironmentVariable("PYTHONPATH");
                    if (pythonpath != null) {
                        var sep = _services.GetService<IOSPlatform>().IsWindows ? ';' : ':';
                        var pythonpathPaths = pythonpath.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                        if (pythonpathPaths.Length > 0) {
                            paths = paths.AddRange(pythonpathPaths);
                            set = true;
                        }
                    }
                }

                if (analayisAutoSearchPaths) {
                    var fs = _services.GetService<IFileSystem>();
                    var auto = AutoSearchPathFinder.Find(fs, _server.Root);
                    paths = paths.AddRange(auto);
                    set = true;
                }
            }

            if (set) {
                return paths;
            }

            var initPaths = _initParams?.initializationOptions?.searchPaths;
            if (initPaths != null) {
                return initPaths.ToImmutableArray();
            }

            return ImmutableArray<string>.Empty;
        }
示例#3
0
        public void SrcDirWithInitPy()
        {
            var root    = TestData.GetTestSpecificPath();
            var rootSrc = Path.Combine(root, "src");
            var fs      = Substitute.For <IFileSystem>();

            fs.DirectoryExists(rootSrc).Returns(true);
            fs.FileExists(Path.Combine(rootSrc, "__init__.py")).Returns(true);

            AutoSearchPathFinder.Find(fs, root).Should().BeEmpty();
        }
示例#4
0
        public void NullRoot()
        {
            var fs = Substitute.For <IFileSystem>();

            AutoSearchPathFinder.Find(fs, null).Should().BeEmpty();
        }