public async Task ReloadAsync(CancellationToken cancellationToken = default) { foreach (var uri in Modules .Where(m => m.Value.Value?.Name != BuiltinModuleName) .Select(m => m.Value.Value?.Uri) .ExcludeDefault()) { GetRdt()?.UnlockDocument(uri); } // Preserve builtins, they don't need to be reloaded since interpreter does not change. var builtins = Modules[BuiltinModuleName]; Modules.Clear(); Modules[BuiltinModuleName] = builtins; PathResolver = new PathResolver(_interpreter.LanguageVersion); var addedRoots = new HashSet <string>(); addedRoots.UnionWith(PathResolver.SetRoot(Root)); InterpreterPaths = await GetSearchPathsAsync(cancellationToken); IEnumerable <string> userSearchPaths = Configuration.SearchPaths; InterpreterPaths = InterpreterPaths.Except(userSearchPaths, StringExtensions.PathsStringComparer).Where(p => !p.PathEquals(Root)); if (Root != null) { var underRoot = userSearchPaths.ToLookup(p => _fs.IsPathUnderRoot(Root, p)); userSearchPaths = underRoot[true]; InterpreterPaths = underRoot[false].Concat(InterpreterPaths); } _log?.Log(TraceEventType.Information, "Interpreter search paths:"); foreach (var s in InterpreterPaths) { _log?.Log(TraceEventType.Information, $" {s}"); } _log?.Log(TraceEventType.Information, "User search paths:"); foreach (var s in userSearchPaths) { _log?.Log(TraceEventType.Information, $" {s}"); } addedRoots.UnionWith(PathResolver.SetInterpreterSearchPaths(InterpreterPaths)); addedRoots.UnionWith(SetUserSearchPaths(userSearchPaths)); ReloadModulePaths(addedRoots); }
public ModulePath FindModule(string filePath) { var bestLibraryPath = string.Empty; foreach (var p in InterpreterPaths.Concat(UserPaths)) { if (PathEqualityComparer.Instance.StartsWith(filePath, p)) { if (p.Length > bestLibraryPath.Length) { bestLibraryPath = p; } } } return(ModulePath.FromFullPath(filePath, bestLibraryPath)); }