Example #1
0
        public async Task CreateSessionAsync()
        {
            var token = await _lock.ResetAsync();

            try {
                if (string.IsNullOrEmpty(_sessionProvider.Broker.Name))
                {
                    throw new RHostDisconnectedException();
                }

                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionId);
                }

                if (!Session.IsHostRunning)
                {
                    int timeout = _coreShell.IsUnitTestEnvironment ? 10000 : 3000;
                    await Session.EnsureHostStartedAsync(new RHostStartupInfo {
                        Name           = "IntelliSense",
                        CranMirrorName = RToolsSettings.Current.CranMirror,
                        CodePage       = RToolsSettings.Current.RCodePage
                    }, null, timeout);
                }
            } finally {
                token.Set();
            }
        }
        /// <summary>
        /// Starts intellisense session.
        /// </summary>
        public async Task StartSessionAsync(CancellationToken ct = default(CancellationToken))
        {
            var token = await _lock.ResetAsync(ct);

            try {
                if (!_sessionProvider.HasBroker)
                {
                    throw new RHostDisconnectedException();
                }

                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionNames.Intellisense);
                }

                if (!Session.IsHostRunning)
                {
                    int timeout  = _unitTests ? 10000 : 3000;
                    var settings = Services.GetService <IRSettings>();
                    await Session.EnsureHostStartedAsync(new RHostStartupInfo(settings.CranMirror, codePage : settings.RCodePage), null, timeout, ct);
                }
            } finally {
                token.Set();
            }
        }
Example #3
0
 public GridDataTest(IServiceContainer services, TestMethodFixture testMethod)
 {
     _services        = services;
     _sessionProvider = new RSessionProvider(services);
     _session         = _sessionProvider.GetOrCreate(testMethod.FileSystemSafeName);
     _dataSource      = new GridDataSource(_session);
 }
Example #4
0
        public ValuesTest(TestMethodFixture testMethod)
        {
            _testMethod      = testMethod.MethodInfo;
            _sessionProvider = new RSessionProvider(TestCoreServices.CreateReal());

            _session = _sessionProvider.GetOrCreate(Guid.NewGuid());
        }
Example #5
0
 public GridDataTest(TestMethodFixture testMethod, BrokerFixture broker)
 {
     _testMethod      = testMethod.MethodInfo;
     _broker          = broker;
     _sessionProvider = new RSessionProvider();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid(), _broker.BrokerConnector);
 }
Example #6
0
        public RInteractiveWorkflow(IRSessionProvider sessionProvider
                                    , IRHistoryProvider historyProvider
                                    , IRPackageManagerProvider packagesProvider
                                    , IRPlotManagerProvider plotsProvider
                                    , IActiveWpfTextViewTracker activeTextViewTracker
                                    , IDebuggerModeTracker debuggerModeTracker
                                    , ICoreShell coreShell
                                    , IRSettings settings
                                    , Action onDispose)
        {
            _activeTextViewTracker = activeTextViewTracker;
            _debuggerModeTracker   = debuggerModeTracker;
            _settings  = settings;
            _onDispose = onDispose;

            Shell       = coreShell;
            RSession    = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid);
            History     = historyProvider.CreateRHistory(this);
            Packages    = packagesProvider.CreateRPackageManager(sessionProvider, settings, this);
            Plots       = plotsProvider.CreatePlotManager(sessionProvider, settings, this);
            _operations = new RInteractiveWorkflowOperations(this, _debuggerModeTracker, Shell);

            _activeTextViewTracker.LastActiveTextViewChanged += LastActiveTextViewChanged;
            RSession.Disconnected += RSessionDisconnected;
        }
Example #7
0
 public BlobsTest(TestMethodFixture testMethod)
 {
     _testMethod      = testMethod.MethodInfo;
     _brokerConnector = new RHostBrokerConnector();
     _brokerConnector.SwitchToLocalBroker(nameof(BlobsTest));
     _sessionProvider = new RSessionProvider();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector);
 }
Example #8
0
        public RHostScript(IRSessionProvider sessionProvider, IRHostClientApp clientApp = null) {
            SessionProvider = sessionProvider;

            Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, clientApp ?? new RHostClientTestApp());
            Session.IsHostRunning.Should().BeFalse();

            Session.StartHostAsync(new RHostStartupInfo {
                Name = "RHostScript",
                RBasePath = RToolsSettings.Current.RBasePath,
                RHostCommandLineArguments = RToolsSettings.Current.RCommandLineArguments,
                CranMirrorName = RToolsSettings.Current.CranMirror
            }, 50000).Wait();
        }
Example #9
0
        public RHostScript(IRSessionProvider sessionProvider, IRHostClientApp clientApp = null)
        {
            SessionProvider = sessionProvider;

            Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, clientApp ?? new RHostClientTestApp());
            Session.IsHostRunning.Should().BeFalse();

            Session.StartHostAsync(new RHostStartupInfo {
                Name      = "RHostScript",
                RBasePath = RToolsSettings.Current.RBasePath,
                RHostCommandLineArguments = RToolsSettings.Current.RCommandLineArguments,
                CranMirrorName            = RToolsSettings.Current.CranMirror
            }, 50000).Wait();
        }
Example #10
0
        private async Task <IRSession> CreatePackageQuerySessionAsync()
        {
            var g       = Guid.NewGuid();
            var session = _sessionProvider.GetOrCreate(g);

            if (!session.IsHostRunning)
            {
                await session.StartHostAsync(new RHostStartupInfo {
                    Name           = "PkgMgr " + g.ToString(),
                    RBasePath      = _settings.RBasePath,
                    CranMirrorName = _settings.CranMirror,
                    CodePage       = _settings.RCodePage
                }, null, HostStartTimeout);
            }
            return(session);
        }
Example #11
0
        public RInteractiveWorkflow(IRSessionProvider sessionProvider
                                    , IConnectionManagerProvider connectionsProvider
                                    , IRHistoryProvider historyProvider
                                    , IRPackageManagerProvider packagesProvider
                                    , IRPlotManagerProvider plotsProvider
                                    , IActiveWpfTextViewTracker activeTextViewTracker
                                    , IDebuggerModeTracker debuggerModeTracker
                                    , ICoreShell coreShell
                                    , IRSettings settings
                                    , IWorkspaceServices wss
                                    , Action onDispose)
        {
            _activeTextViewTracker = activeTextViewTracker;
            _debuggerModeTracker   = debuggerModeTracker;
            _settings  = settings;
            _wss       = wss;
            _onDispose = onDispose;

            Shell     = coreShell;
            RSessions = sessionProvider;

            RSession    = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid);
            Connections = connectionsProvider.CreateConnectionManager(this);

            History     = historyProvider.CreateRHistory(this);
            Packages    = packagesProvider.CreateRPackageManager(settings, this);
            Plots       = plotsProvider.CreatePlotManager(settings, this, new FileSystem());
            _operations = new RInteractiveWorkflowOperations(this, _debuggerModeTracker, Shell);

            _activeTextViewTracker.LastActiveTextViewChanged += LastActiveTextViewChanged;
            RSession.Disconnected += RSessionDisconnected;

            _debuggerModeTracker.EnterBreakMode += DebuggerEnteredBreakMode;
            _debuggerModeTracker.LeaveBreakMode += DebuggerLeftBreakMode;

            _settings.PropertyChanged += OnSettingsChanged;

            _disposableBag = DisposableBag.Create <RInteractiveWorkflow>()
                             .Add(() => _settings.PropertyChanged           -= OnSettingsChanged)
                             .Add(() => _debuggerModeTracker.EnterBreakMode -= DebuggerEnteredBreakMode)
                             .Add(() => _debuggerModeTracker.LeaveBreakMode -= DebuggerLeftBreakMode)
                             .Add(() => _activeTextViewTracker.LastActiveTextViewChanged -= LastActiveTextViewChanged)
                             .Add(() => RSession.Disconnected -= RSessionDisconnected)
                             .Add(Operations)
                             .Add(Connections).
                             Add(_onDispose);
        }
Example #12
0
        public FilesCompletionProvider(string directoryCandidate)
        {
            if (directoryCandidate == null)
            {
                throw new ArgumentNullException(nameof(directoryCandidate));
            }

            EditorShell.Current.CompositionService.SatisfyImportsOnce(this);
            _directory = ExtractDirectory(directoryCandidate);

            if (_directory.StartsWithOrdinal("~\\"))
            {
                _directory = _directory.Substring(2);
                var session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid);
                _userDirectoryFetchingTask = session.GetRUserDirectoryAsync();
            }
        }
Example #13
0
        public RHostScript(IRSessionProvider sessionProvider, IRHostBrokerConnector brokerConnector, IRSessionCallback clientApp = null)
        {
            SessionProvider = sessionProvider;

            Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, brokerConnector);
            if (Session.IsHostRunning)
            {
                Session.StopHostAsync().Wait();
            }

            Session.StartHostAsync(new RHostStartupInfo {
                Name                      = "RHostScript",
                CranMirrorName            = RToolsSettings.Current.CranMirror,
                CodePage                  = RToolsSettings.Current.RCodePage,
                RHostCommandLineArguments = RToolsSettings.Current.LastActiveConnection.RCommandLineArguments
            }, clientApp ?? new RHostClientTestApp(), 50000).Wait();
        }
Example #14
0
        /// <summary>
        /// Starts intellisense session.
        /// </summary>
        public async Task StartSessionAsync(CancellationToken ct = default(CancellationToken))
        {
            var token = await _lock.ResetAsync(ct);

            try {
                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionNames.Intellisense);
                }

                if (!Session.IsHostRunning)
                {
                    int timeout  = _coreShell.IsUnitTestEnvironment ? 10000 : 3000;
                    var settings = _coreShell.GetService <IRToolsSettings>();
                    await Session.EnsureHostStartedAsync(new RHostStartupInfo(settings.CranMirror, codePage : settings.RCodePage), null, timeout);
                }
            } finally {
                token.Set();
            }
        }
Example #15
0
        public RInteractiveWorkflow(IRSessionProvider sessionProvider
                                    , IRHistoryProvider historyProvider
                                    , IActiveWpfTextViewTracker activeTextViewTracker
                                    , IDebuggerModeTracker debuggerModeTracker
                                    , IRHostClientApp hostClientApp
                                    , ICoreShell coreShell
                                    , IRSettings settings
                                    , Action onDispose)
        {
            _activeTextViewTracker = activeTextViewTracker;
            _debuggerModeTracker   = debuggerModeTracker;
            _settings  = settings;
            _coreShell = coreShell;
            _onDispose = onDispose;

            RSession    = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, hostClientApp);
            History     = historyProvider.CreateRHistory(this);
            _operations = new RInteractiveWorkflowOperations();

            _activeTextViewTracker.LastActiveTextViewChanged += LastActiveTextViewChanged;
            RSession.Disconnected += RSessionDisconnected;
        }
Example #16
0
        public async Task <string> HandleUrlAsync(string urlStr, CancellationToken ct = default(CancellationToken))
        {
            await InitializeAsync(ct);

            var session = _sessionProvider.GetOrCreate(remoteFileSession);
            await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 3000, ct);

            _session = session;

            Log.WriteLine(LogVerbosity.Minimal, MessageCategory.General, Resources.Info_StaticFileServerStarted.FormatInvariant(Listener.Prefixes.FirstOrDefault()));
            Console.WriteLine(Resources.Info_StaticFileServerStarted.FormatInvariant(Listener.Prefixes.FirstOrDefault()));

            string path = urlStr;

            if (urlStr.StartsWithIgnoreCase("file://"))
            {
                Uri ub = new Uri(urlStr);
                path = ub.LocalPath;
            }

            return(GetFileServerPath(path));
        }
        public RInteractiveWorkflow(IRSessionProvider sessionProvider
            , IRHistoryProvider historyProvider
            , IActiveWpfTextViewTracker activeTextViewTracker
            , IDebuggerModeTracker debuggerModeTracker
            , IRHostClientApp hostClientApp
            , ICoreShell coreShell
            , IRSettings settings
            , Action onDispose) {

            _activeTextViewTracker = activeTextViewTracker;
            _debuggerModeTracker = debuggerModeTracker;
            _settings = settings;
            _coreShell = coreShell;
            _onDispose = onDispose;

            RSession = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, hostClientApp);
            History = historyProvider.CreateRHistory(this);
            _operations = new RInteractiveWorkflowOperations();

            _activeTextViewTracker.LastActiveTextViewChanged += LastActiveTextViewChanged;
            RSession.Disconnected += RSessionDisconnected;
        }
Example #18
0
        public async Task R_LoadedPackageFunctionCompletion()
        {
            using (var script = await _editorHost.StartScript(_exportProvider, RContentTypeDefinition.ContentType))
                using (new RHostScript(_sessionProvider, _broker.BrokerConnector)) {
                    script.Type("c");
                    script.DoIdle(200);
                    var session = script.GetCompletionSession();
                    session.Should().NotBeNull();
                    script.DoIdle(500);

                    var list = session.SelectedCompletionSet.Completions.ToList();
                    var item = list.FirstOrDefault(x => x.DisplayText == "codoc");
                    item.Should().BeNull();

                    var rSession = _sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, _broker.BrokerConnector);
                    rSession.Should().NotBeNull();

                    await rSession.ExecuteAsync("library('tools')");

                    script.DoIdle(1000);

                    script.Type("{ESC}");
                    script.DoIdle(200);
                    script.Backspace();
                    script.Type("{ENTER}");
                    script.DoIdle(100);

                    script.Type("c");
                    script.DoIdle(500);
                    script.Backspace();

                    session = script.GetCompletionSession();
                    session.Should().NotBeNull();
                    list = session.SelectedCompletionSet.Completions.ToList();
                    item = list.FirstOrDefault(x => x.DisplayText == "codoc");
                    item.Should().NotBeNull();
                }
        }
Example #19
0
        public async Task CreateSessionAsync()
        {
            await _lock.WaitAsync();

            try {
                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionId, _brokerConnector);
                }

                if (!Session.IsHostRunning)
                {
                    int timeout = _coreShell.IsUnitTestEnvironment ? 10000 : 3000;
                    await Session.StartHostAsync(new RHostStartupInfo {
                        Name           = "IntelliSense",
                        CranMirrorName = RToolsSettings.Current.CranMirror,
                        CodePage       = RToolsSettings.Current.RCodePage
                    }, null, timeout);
                }
            } finally {
                _lock.Release();
            }
        }
Example #20
0
        public override async Task <string> HandleUrlAsync(string url, CancellationToken cancellationToken)
        {
            var remotingService = _services.GetService <IRemotingWebServer>();
            Uri uri             = new Uri(url);

            if (url.StartsWithIgnoreCase("http://"))
            {
                return(await remotingService.HandleRemoteWebUrlAsync(url, HttpClient.BaseAddress.ToString(), Name, _console, cancellationToken));
            }
            else if (uri.AbsoluteUri.StartsWithIgnoreCase("file://") || url.StartsWithIgnoreCase("/"))
            {
                var fs = _services.GetService <IFileSystem>();
                return(await remotingService.HandleRemoteStaticFileUrlAsync(url, _sessionProvider, _console, cancellationToken));
            }
            else if (!url.StartsWithIgnoreCase("http://") && _sessionProvider != null)
            {
                var fullpath = url;
                try {
                    var session = _sessionProvider.GetOrCreate("REPL");
                    if (!url.StartsWithIgnoreCase("http://") && await session.FileExistsAsync(url, cancellationToken))
                    {
                        fullpath = $"file:///{await session.NormalizePathAsync(url, cancellationToken)}";
                    }
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    // This is best effort to find the resource
                }
                var fs = _services.GetService <IFileSystem>();
                return(await remotingService.HandleRemoteStaticFileUrlAsync(fullpath, _sessionProvider, _console, cancellationToken));
            }
            else
            {
                _console.WriteError(string.Format(Resources.Error_RemoteUriNotSupported, url));
                return(null);
            }
        }
Example #21
0
        public RInteractiveWorkflow(IRSessionProvider sessionProvider
                                    , IConnectionManagerProvider connectionsProvider
                                    , IRHistoryProvider historyProvider
                                    , IRPackageManagerProvider packagesProvider
                                    , IRPlotManagerProvider plotsProvider
                                    , IActiveWpfTextViewTracker activeTextViewTracker
                                    , IDebuggerModeTracker debuggerModeTracker
                                    , IRHostBrokerConnector brokerConnector
                                    , ICoreShell coreShell
                                    , IRSettings settings
                                    , IWorkspaceServices wss
                                    , Action onDispose)
        {
            _activeTextViewTracker = activeTextViewTracker;
            _debuggerModeTracker   = debuggerModeTracker;
            _settings  = settings;
            _wss       = wss;
            _onDispose = onDispose;

            Shell           = coreShell;
            BrokerConnector = brokerConnector;

            RSession    = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, brokerConnector);
            Connections = connectionsProvider.CreateConnectionManager(this);

            History     = historyProvider.CreateRHistory(this);
            Packages    = packagesProvider.CreateRPackageManager(sessionProvider, settings, this);
            Plots       = plotsProvider.CreatePlotManager(settings, this);
            _operations = new RInteractiveWorkflowOperations(this, _debuggerModeTracker, Shell);

            _activeTextViewTracker.LastActiveTextViewChanged += LastActiveTextViewChanged;
            RSession.Disconnected += RSessionDisconnected;

            _debuggerModeTracker.EnterBreakMode += DebuggerEnteredBreakMode;
            _debuggerModeTracker.LeaveBreakMode += DebuggerLeftBreakMode;
        }
        /// <summary>
        /// Starts intellisense session.
        /// </summary>
        public async Task StartSessionAsync(CancellationToken ct = default)
        {
            var token = await _lock.ResetAsync(ct);

            try {
                if (!_sessionProvider.HasBroker)
                {
                    throw new RHostDisconnectedException();
                }

                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionNames.Intellisense);
                }

                if (!Session.IsHostRunning)
                {
                    var timeout = _unitTests ? 10000 : 3000;
                    await Session.EnsureHostStartedAsync(new RHostStartupInfo(), null, null, timeout, ct);
                }
            } finally {
                token.Set();
            }
        }
Example #23
0
        /// <summary>
        /// Starts intellisense session.
        /// </summary>
        public async Task StartSessionAsync()
        {
            var token = await _lock.ResetAsync();

            try {
                if (!_sessionProvider.HasBroker)
                {
                    throw new RHostDisconnectedException();
                }

                if (Session == null)
                {
                    Session = _sessionProvider.GetOrCreate(SessionNames.Intellisense);
                }

                if (!Session.IsHostRunning)
                {
                    int timeout = _coreShell.IsUnitTestEnvironment ? 10000 : 3000;
                    await Session.EnsureHostStartedAsync(new RHostStartupInfo(RToolsSettings.Current.CranMirror, codePage : RToolsSettings.Current.RCodePage), null, timeout);
                }
            } finally {
                token.Set();
            }
        }
Example #24
0
 public DebugReplTest(TestMethodFixture testMethod) {
     _testMethod = testMethod.MethodInfo;
     _sessionProvider = new RSessionProvider();
     _session = _sessionProvider.GetOrCreate(Guid.NewGuid(), new RHostClientTestApp());
 }
Example #25
0
 public BreakpointsTest(IServiceContainer services, TestMethodFixture testMethod)
 {
     _sessionProvider = new RSessionProvider(services);
     _session         = _sessionProvider.GetOrCreate(testMethod.FileSystemSafeName);
 }
Example #26
0
 public DebugReplTest(CoreServicesFixture coreServices, TestMethodFixture testMethod)
 {
     _sessionProvider = new RSessionProvider(coreServices);
     _session         = _sessionProvider.GetOrCreate(testMethod.FileSystemSafeName);
 }
Example #27
0
 public ViewersTest()
 {
     _sessionProvider = VsAppShell.Current.ExportProvider.GetExportedValue <IRSessionProvider>();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid());
     _aggregator      = VsAppShell.Current.ExportProvider.GetExportedValue <IObjectDetailsViewerAggregator>();
 }
Example #28
0
 public REnvironmentProviderTest(TestMethodFixture testMethod)
 {
     _testMethod      = testMethod.MethodInfo;
     _sessionProvider = new RSessionProvider();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid());
 }
Example #29
0
 public BlobsTest(TestMethodFixture testMethod) {
     _testMethod = testMethod.MethodInfo;
     _sessionProvider = new RSessionProvider(TestCoreServices.CreateReal());
     _session = _sessionProvider.GetOrCreate(Guid.NewGuid());
 }
Example #30
0
 public ValuesTest(TestMethodFixture testMethod)
 {
     _testMethod      = testMethod.MethodInfo;
     _sessionProvider = new RSessionProvider();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid(), new RHostClientTestApp());
 }
Example #31
0
 public DebugReplTest(TestMethodFixture testMethod)
 {
     _testMethod      = testMethod.MethodInfo;
     _sessionProvider = new RSessionProvider();
     _session         = _sessionProvider.GetOrCreate(Guid.NewGuid());
 }
Example #32
0
 public ValuesTest(IServiceContainer services, IRemoteBroker remoteBroker, TestMethodFixture testMethod)
 {
     _remoteBroker    = remoteBroker;
     _sessionProvider = new RSessionProvider(services);
     _session         = _sessionProvider.GetOrCreate(testMethod.FileSystemSafeName);
 }
 public static IRSession GetInteractiveWindowRSession(this IRSessionProvider provider)
 {
     return(provider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, RHostClientApp.Instance));
 }
Example #34
0
 public static IRSession GetInteractiveWindowRSession(this IRSessionProvider provider)
 {
     return(provider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid));
 }