Beispiel #1
0
 public LoadWorkspaceCommand(IApplicationShell appShell, IRInteractiveWorkflow interactiveWorkflow, IProjectServiceAccessor projectServiceAccessor) :
     base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdLoadWorkspace) {
     _appShell = appShell;
     _interactiveWorkflow = interactiveWorkflow;
     _rSession = interactiveWorkflow.RSession;
     _projectServiceAccessor = projectServiceAccessor;
 }
Beispiel #2
0
 public SessionCommand(IRSession session, Guid group, int id) :
     base(group, id) {
     if (session == null) {
         throw new ArgumentNullException(nameof(session));
     }
     RSession = session;
 }
        public VariableGridHost() {
            InitializeComponent();

            _aggregator = VsAppShell.Current.ExportProvider.GetExportedValue<IObjectDetailsViewerAggregator>();
            _rSession = VsAppShell.Current.ExportProvider.GetExportedValue<IRInteractiveWorkflowProvider>().GetOrCreate().RSession;
            _rSession.Mutated += RSession_Mutated;
        }
        public PlotContentProvider(IRSession session) {
            _lastPixelWidth = -1;
            _lastPixelHeight = -1;

            _rSession = session;
            _rSession.Connected += RSession_Connected;
        }
Beispiel #5
0
        internal RValueInfo(
            IRSession session,
            string environmentExpression,
            string expression,
            string name,
            string representation,
            RChildAccessorKind accessorKind,
            string typeName,
            IReadOnlyList<string> classes,
            int? length,
            int? attributeCount,
            int? slotCount,
            int? nameCount,
            IReadOnlyList<int> dim,
            RValueFlags flags,
            bool canCoerceToDataFrame
        ) : base(session, environmentExpression, expression, name) {

            Representation = representation;
            AccessorKind = accessorKind;
            TypeName = typeName;
            Classes = classes;
            Length = length;
            AttributeCount = attributeCount;
            SlotCount = slotCount;
            NameCount = nameCount;
            Dim = dim;
            Flags = flags;
            CanCoerceToDataFrame = canCoerceToDataFrame;
        }
 public GoToDefinitionCommand(ITextView textView, ITextBuffer textBuffer, IObjectViewer objectViewer, IRSession session) :
    base(textView, new CommandId(typeof(VSConstants.VSStd97CmdID).GUID,
         (int)VSConstants.VSStd97CmdID.GotoDefn), needCheckout: false) {
     _textBuffer = textBuffer;
     _objectViewer = objectViewer;
     _session = session;
 }
 public void Dispose() {
     if (_session != null) {
         _session.Disposed -= OnSessionDisposed;
         _session.Dispose();
         _session = null;
     }
 }
 public void Dispose() {
     if (_session != null) {
         _session.Connected -= OnSessionConnected;
         _session.DirectoryChanged -= OnCurrentDirectoryChanged;
     }
     _session = null;
 }
 private void OnSessionDisposed(object sender, EventArgs e) {
     if (Session != null) {
         Session.Mutated -= OnSessionMutated;
         Session.Disposed -= OnSessionDisposed;
         Session = null;
     }
 }
Beispiel #10
0
 private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage, IApplicationShell appShell) {
     using (var fts = new DataTransferSession(session, fs)) {
         string currentStatusText = string.Empty;
         uint cookie = 0;
         IVsStatusbar statusBar = null;
         appShell.DispatchOnUIThread(() => {
             statusBar = appShell.GetGlobalService<IVsStatusbar>(typeof(SVsStatusbar));
             statusBar.GetText(out currentStatusText);
             statusBar.Progress(ref cookie, 1, "", 0, 0);
         });
         
         try {
             // TODO: progress and cancellation handling
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
             var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
             var publishResult = await session.EvaluateAsync<ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
             await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
         } finally {
             appShell.DispatchOnUIThread(() => {
                 statusBar?.Progress(ref cookie, 0, "", 0, 0);
                 statusBar?.SetText(currentStatusText);
             });
         }
     }
 }
Beispiel #11
0
 private void ConnectToSession() {
     if (Session == null) {
         Session = Workflow.RSession;
         Session.Mutated += OnSessionMutated;
         Session.Disposed += OnSessionDisposed;
         SessionMutated();
     }
 }
 private void ConnectToSession() {
     if (Session == null) {
         Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid, null);
         Session.Mutated += OnSessionMutated;
         Session.Disposed += OnSessionDisposed;
         SessionMutated();
     }
 }
Beispiel #13
0
        internal RActiveBindingInfo(IRSession session, string environmentExpression, string expression, string name, JObject json)
            : this(session, environmentExpression, expression, name, (IRValueInfo)null) {

            JObject bindingResultJson = json.Value<JObject>(FieldNames.ComputedValue);
            if (bindingResultJson != null) {
                ComputedValue = new RValueInfo(session, environmentExpression, expression, name, bindingResultJson);
            }
        }
 public RInteractiveEvaluator(IRSession session, IRHistory history, ICoreShell coreShell, IRSettings settings) {
     History = history;
     Session = session;
     Session.Output += SessionOnOutput;
     Session.Disconnected += SessionOnDisconnected;
     Session.BeforeRequest += SessionOnBeforeRequest;
     _coreShell = coreShell;
     _settings = settings;
 }
Beispiel #15
0
 private async Task LoadWorkspace(IRSession session, string file) {
     try {
         await session.LoadWorkspaceAsync(file);
     } catch (RException ex) {
         var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat, file, ex.Message);
         VsAppShell.Current.ShowErrorMessage(message);
     } catch (OperationCanceledException) {
     }
 }
Beispiel #16
0
        internal RExecutionTracer(IRSession session) {
            if (session == null) {
                throw new ArgumentNullException(nameof(session));
            }

            Session = session;
            Session.Connected += RSession_Connected;
            Session.BeforeRequest += RSession_BeforeRequest;
            Session.AfterRequest += RSession_AfterRequest;
        }
Beispiel #17
0
        public void Dispose() {
            if (!_disposeToken.TryMarkDisposed()) {
                return;
            }

            if (_rSession != null) {
                _rSession.Mutated -= RSession_Mutated;
                _rSession = null;
            }
        }
Beispiel #18
0
        public RSessionCallback(IInteractiveWindow interactiveWindow, IRSession session, IRSettings settings, ICoreShell coreShell, IFileSystem fileSystem) {
            _interactiveWindow = interactiveWindow;
            _session = session;
            _settings = settings;
            _coreShell = coreShell;
            _fileSystem = fileSystem;

            var workflowProvider = _coreShell.ExportProvider.GetExportedValue<IRInteractiveWorkflowProvider>();
            _workflow = workflowProvider.GetOrCreate();
        }
Beispiel #19
0
        internal RStackFrame(IRSession session, int index, RStackFrame callingFrame, JObject jFrame) {
            Session = session;
            Index = index;
            CallingFrame = callingFrame;

            FileName = jFrame.Value<string>("filename");
            LineNumber = jFrame.Value<int?>("line_number");
            Call = jFrame.Value<string>("call");
            EnvironmentName = jFrame.Value<string>("env_name");
        }
Beispiel #20
0
 public async Task PublishAsync(IRSession session, IApplicationShell appShell,  IFileSystem fs, string inputFilePath, string outputFilePath, PublishFormat publishFormat, Encoding encoding) {
     try {
         await RMarkdownRenderAsync(session, fs, inputFilePath, outputFilePath, GetDocumentTypeString(publishFormat), encoding.CodePage, appShell);
     } catch (IOException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (RException ex) {
         await appShell.ShowErrorMessageAsync(ex.Message);
     } catch (OperationCanceledException) {
     } 
 }
Beispiel #21
0
        internal RStackFrame(IRSession session, int index, RStackFrame callingFrame, JObject jFrame)
        {
            Session      = session;
            Index        = index;
            CallingFrame = callingFrame;

            FileName        = jFrame.Value <string>("filename");
            LineNumber      = jFrame.Value <int?>("line_number");
            Call            = jFrame.Value <string>("call");
            EnvironmentName = jFrame.Value <string>("env_name");
        }
Beispiel #22
0
        private async Task ExecuteAndCaptureOutputAsync(IRSession session, string expression, CancellationToken cancellationToken)
        {
            _output = new StringBuilder();
            _errors = new StringBuilder();

            try {
                using (var inter = await session.BeginInteractionAsync(true, cancellationToken)) {
                    await inter.RespondAsync(expression);
                }
            } catch (OperationCanceledException) { }
        }
Beispiel #23
0
        public PackageIndex(IRInteractiveWorkflowProvider interactiveWorkflowProvider, ICoreShell shell, IIntellisenseRSession host, IFunctionIndex functionIndex)
        {
            _shell         = shell;
            _host          = host;
            _functionIndex = functionIndex;

            _interactiveSession = interactiveWorkflowProvider.GetOrCreate().RSession;

            _interactiveSession.PackagesInstalled += OnPackagesChanged;
            _interactiveSession.PackagesRemoved   += OnPackagesChanged;
        }
Beispiel #24
0
 public async Task PublishAsync(IRSession session, ICoreShell coreShell, IFileSystem fs, string inputFilePath, string outputFilePath, PublishFormat publishFormat, Encoding encoding)
 {
     try {
         await RMarkdownRenderAsync(session, fs, inputFilePath, outputFilePath, GetDocumentTypeString(publishFormat), encoding.CodePage);
     } catch (IOException ex) {
         coreShell.ShowErrorMessage(ex.Message);
     } catch (RException ex) {
         coreShell.ShowErrorMessage(ex.Message);
     } catch (OperationCanceledException) {
     }
 }
        private async Task LoadWorkspace(IRSession session, string file) {
            REvaluationResult result;
            using (var evaluation = await session.BeginEvaluationAsync()) {
                result = await evaluation.LoadWorkspace(file);
            }

            if (result.Error != null) {
                var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat, file, result.Error);
                VsAppShell.Current.ShowErrorMessage(message);
            }
        }
Beispiel #26
0
        public InterruptRCommand(IRInteractiveWorkflow interactiveWorkflow, IDebuggerModeTracker debuggerModeTracker) {
            _interactiveWorkflow = interactiveWorkflow;
            _session = interactiveWorkflow.RSession;
            _debuggerModeTracker = debuggerModeTracker;

            _session.Connected += OnConnected;
            _session.Disconnected += OnDisconnected;

            _session.BeforeRequest += OnBeforeRequest;
            _session.AfterRequest += OnAfterRequest;
        }
Beispiel #27
0
        public RSessionCallback(IInteractiveWindow interactiveWindow, IRSession session, IRSettings settings, ICoreShell coreShell, IFileSystem fileSystem)
        {
            _interactiveWindow = interactiveWindow;
            _session           = session;
            _settings          = settings;
            _coreShell         = coreShell;
            _fileSystem        = fileSystem;

            var workflowProvider = _coreShell.GetService <IRInteractiveWorkflowProvider>();

            _workflow = workflowProvider.GetOrCreate();
        }
Beispiel #28
0
        private async Task ExportToImageAsync(IRSession session, string format, string filePath, int widthInPixels, int heightInPixels, int resolution)
        {
            string script = String.Format(@"
device_id <- rtvs:::graphics.ide.getactivedeviceid()
rtvs:::export_to_image(device_id, rtvs:::graphics.ide.getactiveplotid(device_id), {0}, {1}, {2}, {3})
", format, widthInPixels, heightInPixels, resolution);
            var    blobid = await session.EvaluateAsync <ulong>(script, REvaluationKind.Normal);

            using (DataTransferSession dts = new DataTransferSession(session, new FileSystem())) {
                await dts.FetchFileAsync(new RBlobInfo(blobid), filePath, true, null, CancellationToken.None);
            }
        }
Beispiel #29
0
        public InterruptRCommand(IRInteractiveWorkflow interactiveWorkflow, IDebuggerModeTracker debuggerModeTracker)
        {
            _interactiveWorkflow = interactiveWorkflow;
            _session             = interactiveWorkflow.RSession;
            _debuggerModeTracker = debuggerModeTracker;

            _session.Connected    += OnConnected;
            _session.Disconnected += OnDisconnected;

            _session.BeforeRequest += OnBeforeRequest;
            _session.AfterRequest  += OnAfterRequest;
        }
        public RSessionCallback(IInteractiveWindow interactiveWindow, IRSession session, IRSettings settings, IServiceContainer services, IFileSystem fileSystem)
        {
            _interactiveWindow = interactiveWindow;
            _session           = session;
            _settings          = settings;
            _services          = services;
            _fileSystem        = fileSystem;

            var workflowProvider = _services.GetService <IRInteractiveWorkflowProvider>();

            _workflow = workflowProvider.GetOrCreate();
        }
Beispiel #31
0
        public async Task InitializeAsync(IRSessionCallback clientApp = null)
        {
            _clientApp = clientApp ?? _clientApp;

            Session = SessionProvider.GetOrCreate(SessionNames.InteractiveWindow);
            if (Session.IsHostRunning)
            {
                await Session.StopHostAsync();
            }

            await Session.StartHostAsync(new RHostStartupInfo(), _clientApp ?? new RHostClientTestApp(), 50000);
        }
Beispiel #32
0
 private async Task LoadWorkspace(IRSession session, string file)
 {
     using (var evaluation = await session.BeginEvaluationAsync()) {
         try {
             await evaluation.LoadWorkspaceAsync(file);
         } catch (RException ex) {
             var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat, file, ex.Message);
             VsAppShell.Current.ShowErrorMessage(message);
         } catch (OperationCanceledException) {
         }
     }
 }
        public PlotManagerWindowPane(IRPlotManager plotManager, IRSession session, IRSettings settings, ICoreShell coreShell)
        {
            _plotManager = plotManager;
            _session     = session;
            _settings    = settings;
            _coreShell   = coreShell;

            // this value matches with icmdShowPlotWindow's Icon in VSCT file
            BitmapImageMoniker = KnownMonikers.LineChart;
            Caption            = Resources.PlotWindowCaption;
            ToolBar            = new CommandID(RGuidList.RCmdSetGuid, RPackageCommandId.plotWindowToolBarId);
        }
Beispiel #34
0
        internal RExecutionTracer(IRSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            Session                = session;
            Session.Connected     += RSession_Connected;
            Session.BeforeRequest += RSession_BeforeRequest;
            Session.AfterRequest  += RSession_AfterRequest;
        }
Beispiel #35
0
        public async Task InitializeProjectFromDiskAsync()
        {
            await Project.CreateInMemoryImport();

            _fileWatcher.Start();

            await _threadHandling.SwitchToUIThread();

            // Make sure R package is loaded
            VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);

            // Verify project is not on a network share and give warning if it is
            CheckRemoteDrive(_projectDirectory);

            _workflow = _coreShell.GetService <IRInteractiveWorkflowVisualProvider>().GetOrCreate();
            _session  = _workflow.RSession;
            _history  = _workflow.History;

            if (_workflow.ActiveWindow == null)
            {
                var window = await _workflow.GetOrCreateVisualComponentAsync();

                window.Container.Show(focus: true, immediate: false);
            }

            try {
                await _session.HostStarted;
            } catch (Exception) {
                return;
            }

            _workflow.RSessions.BeforeDisposed += BeforeRSessionsDisposed;

            // TODO: need to compute the proper paths for remote, but they might not even exist if the project hasn't been deployed.
            // https://github.com/Microsoft/RTVS/issues/2223
            if (!_session.IsRemote)
            {
                var  rdataPath            = Path.Combine(_projectDirectory, DefaultRDataName);
                bool loadDefaultWorkspace = _coreShell.FileSystem().FileExists(rdataPath) && await GetLoadDefaultWorkspace(rdataPath);

                if (loadDefaultWorkspace)
                {
                    await _session.LoadWorkspaceAsync(rdataPath);
                }
                await _session.SetWorkingDirectoryAsync(_projectDirectory);

                _settings.WorkingDirectory = _projectDirectory;
            }

            _history.TryLoadFromFile(Path.Combine(_projectDirectory, DefaultRHistoryName));
            CheckSurveyNews();
        }
Beispiel #36
0
        public static async Task <string> GetRUserDirectoryAsync(this IRSession session, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (session.IsHostRunning)
            {
                await TaskUtilities.SwitchToBackgroundThread();

                try {
                    return(await RSessionEvaluationCommands.GetRUserDirectoryAsync(session, cancellationToken));
                } catch (RException) {
                } catch (OperationCanceledException) { }
            }
            return(null);
        }
Beispiel #37
0
        public void Dispose()
        {
            if (!_disposeToken.TryMarkDisposed())
            {
                return;
            }

            if (_rSession != null)
            {
                _rSession.Mutated -= RSession_Mutated;
                _rSession          = null;
            }
        }
Beispiel #38
0
        private RHostSession(IRSession session)
        {
            _session = session;

            _session.Connected    += OnSessionConnected;
            _session.Disconnected += OnSessionDisconnected;
            _session.Output       += OnSessionOutput;

            _disposableBag = DisposableBag.Create <RHostSession>()
                             .Add(() => _session.Output       -= OnSessionOutput)
                             .Add(() => _session.Connected    -= OnSessionConnected)
                             .Add(() => _session.Disconnected -= OnSessionDisconnected);
        }
Beispiel #39
0
        private async Task <REvaluationResult> EvaluateAsyncAsync(string expression)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            IRSession         rSession = GetRSession();
            REvaluationResult result;

            using (var evaluator = await rSession.BeginEvaluationAsync()) {
                result = await evaluator.EvaluateAsync(expression, REvaluationKind.Mutating);
            }

            return(result);
        }
Beispiel #40
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();
        }
Beispiel #41
0
        private async Task <REvaluationResult> CallIconvListAsync()
        {
            await TaskUtilities.SwitchToBackgroundThread();

            IRSession         rSession = GetRSession();
            REvaluationResult result;

            using (var evaluator = await rSession.BeginEvaluationAsync()) {
                result = await evaluator.EvaluateAsync("as.list(iconvlist())", REvaluationKind.Json);
            }

            return(result);
        }
Beispiel #42
0
 public RInteractiveEvaluator(IRSession session, IRHistory history, IConnectionManager connections, ICoreShell coreShell, IRSettings settings)
 {
     History                = history;
     Session                = session;
     Session.Output        += SessionOnOutput;
     Session.Disconnected  += SessionOnDisconnected;
     Session.BeforeRequest += SessionOnBeforeRequest;
     Session.AfterRequest  += SessionOnAfterRequest;
     _connections           = connections;
     _coreShell             = coreShell;
     _settings              = settings;
     _evaluatorRequest      = new CountdownDisposable();
 }
Beispiel #43
0
        private async Task <IRSession> StartSessionAsync(CancellationToken ct)
        {
            _session = _session ?? _workflow.RSessions.GetOrCreate("VSCR_Output");

            if (!_session.IsHostRunning)
            {
                await _session.EnsureHostStartedAsync(new RHostStartupInfo(isInteractive : true), _sessionCallback, 3000, ct);

                await _session.SetVsGraphicsDeviceAsync();
            }

            return(_session);
        }
Beispiel #44
0
        public static async Task <string> GetRWorkingDirectoryAsync(this IRSession session)
        {
            if (session.IsHostRunning)
            {
                await TaskUtilities.SwitchToBackgroundThread();

                try {
                    return(await session.GetWorkingDirectoryAsync());
                } catch (RException) {
                } catch (OperationCanceledException) {
                }
            }
            return(null);
        }
Beispiel #45
0
        internal RActiveBindingInfo(IRSession session, string environmentExpression, string expression, string name, JObject json)
            : base(session, environmentExpression, expression, name)
        {
            JObject bindingResultJson = json.Value <JObject>(FieldNames.ComputedValue);

            if (bindingResultJson == null)
            {
                ComputedValue = null;
            }
            else
            {
                ComputedValue = new RValueInfo(session, environmentExpression, expression, name, bindingResultJson);
            }
        }
Beispiel #46
0
 public RInteractiveEvaluator(IRSessionProvider sessionProvider, IRSession session, IRHistory history, IConnectionManager connections, ICoreShell coreShell, IRSettings settings, IConsole console) {
     History = history;
     Session = session;
     Session.Output += SessionOnOutput;
     Session.Disconnected += SessionOnDisconnected;
     Session.BeforeRequest += SessionOnBeforeRequest;
     Session.AfterRequest += SessionOnAfterRequest;
     _sessionProvider = sessionProvider;
     _connections = connections;
     _coreShell = coreShell;
     _settings = settings;
     _console = console;
     _evaluatorRequest = new CountdownDisposable();
 }
Beispiel #47
0
        public VariableGridHost(IServiceContainer services)
        {
            InitializeComponent();

            _services          = services;
            _rSession          = _services.GetService <IRInteractiveWorkflowProvider>().GetOrCreate().RSession;
            _rSession.Mutated += RSession_Mutated;

            _disposableBag
            .Add(() => _rSession.Mutated -= RSession_Mutated)
            .Add(DeleteCachedVariable);

            FocusManager.SetFocusedElement(this, VariableGrid);
        }
Beispiel #48
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();
        }
Beispiel #49
0
        public static async Task <string> GetRUserDirectoryAsync(this IRSession session)
        {
            if (session.IsHostRunning)
            {
                await TaskUtilities.SwitchToBackgroundThread();

                try {
                    using (var evaluation = await session.BeginEvaluationAsync()) {
                        return(await evaluation.GetRUserDirectory());
                    }
                } catch (OperationCanceledException) { }
            }
            return(null);
        }
        public HelpWindowVisualComponent() {
            _session = VsAppShell.Current.ExportProvider.GetExportedValue<IRSessionProvider>().GetInteractiveWindowRSession();
            _session.Disconnected += OnRSessionDisconnected;

            _windowContentControl = new ContentControl();
            Control = _windowContentControl;

            var c = new Controller();
            c.AddCommandSet(GetCommands());
            Controller = c;

            CreateBrowser();
            VSColorTheme.ThemeChanged += OnColorThemeChanged;
        }
Beispiel #51
0
        private async Task LoadWorkspace(IRSession session, string file)
        {
            REvaluationResult result;

            using (var evaluation = await session.BeginEvaluationAsync()) {
                result = await evaluation.LoadWorkspace(file);
            }

            if (result.Error != null)
            {
                var message = string.Format(CultureInfo.CurrentCulture, Resources.LoadWorkspaceFailedMessageFormat, file, result.Error);
                VsAppShell.Current.ShowErrorMessage(message);
            }
        }
        private async Task UpdateList()
        {
            if (_updating)
            {
                return;
            }

            try {
                _updating = true;
                // May be null in tests
                IRSession session = Workflow.RSession;
                if (session.IsHostRunning)
                {
                    var stackFrames = await session.TracebackAsync();

                    var globalStackFrame = stackFrames.FirstOrDefault(s => s.IsGlobal);
                    if (globalStackFrame != null)
                    {
                        const REvaluationResultProperties properties =
                            ExpressionProperty |
                            AccessorKindProperty |
                            TypeNameProperty |
                            ClassesProperty |
                            LengthProperty |
                            SlotCountProperty |
                            AttributeCountProperty |
                            DimProperty |
                            FlagsProperty;
                        var evaluation = await globalStackFrame.TryEvaluateAndDescribeAsync("base::environment()", "Global Environment", properties, RValueRepresentations.Str());

                        var e = new RSessionDataObject(evaluation, _coreShell.Services);  // root level doesn't truncate children and return every variables

                        _topLevelVariables.Clear();

                        var children = await e.GetChildrenAsync();

                        if (children != null)
                        {
                            foreach (var x in children)
                            {
                                _topLevelVariables[x.Name] = x; // TODO: BUGBUG: this doesn't address removed variables
                            }
                        }
                    }
                }
            } catch (REvaluationException) { } finally {
                _updating = false;
            }
        }
Beispiel #53
0
        public async Task InitializeProjectFromDiskAsync()
        {
            await Project.CreateInMemoryImport();

            _fileWatcher.Start();

            // Force REPL window up and continue only when it is shown
            await _threadHandling.SwitchToUIThread();

            // Make sure R package is loaded
            VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);

            // Verify project is not on a network share and give warning if it is
            CheckRemoteDrive(_projectDirectory);

            _workflow = _workflowProvider.GetOrCreate();
            _session  = _workflow.RSession;
            _history  = _workflow.History;

            if (_workflow.ActiveWindow == null)
            {
                var window = await _workflow.GetOrCreateVisualComponent(_componentContainerFactory);

                window.Container.Show(true);
            }

            try {
                await _session.HostStarted;
            } catch (Exception) {
                return;
            }

            var  rdataPath            = Path.Combine(_projectDirectory, DefaultRDataName);
            bool loadDefaultWorkspace = _fileSystem.FileExists(rdataPath) && await GetLoadDefaultWorkspace(rdataPath);

            using (var evaluation = await _session.BeginEvaluationAsync()) {
                if (loadDefaultWorkspace)
                {
                    await evaluation.LoadWorkspace(rdataPath);
                }

                await evaluation.SetWorkingDirectory(_projectDirectory);
            }

            _toolsSettings.WorkingDirectory = _projectDirectory;
            _history.TryLoadFromFile(Path.Combine(_projectDirectory, DefaultRHistoryName));

            CheckSurveyNews();
        }
        public WorkingDirectoryCommand(IRInteractiveWorkflow interactiveWorkflow) :
            base(new[] {
                new CommandId(RGuidList.RCmdSetGuid, RPackageCommandId.icmdGetDirectoryList),
                new CommandId(RGuidList.RCmdSetGuid, RPackageCommandId.icmdSetWorkingDirectory)
            }, false) {

            _interactiveWorkflow = interactiveWorkflow;
            _session = interactiveWorkflow.RSession;
            _session.Connected += OnSessionConnected;
            _session.DirectoryChanged += OnCurrentDirectoryChanged;

            if (InitializationTask == null && _session.IsHostRunning) {
                InitializationTask = UpdateRUserDirectoryAsync();
            }
        }
Beispiel #55
0
        public async Task InitializeAsync(IRSessionCallback clientApp = null) {
            _clientApp = clientApp ?? _clientApp;

            Session = SessionProvider.GetOrCreate(SessionGuids.InteractiveWindowRSessionGuid);
            if (Session.IsHostRunning) {
                await Session.StopHostAsync();
            }

            await Session.StartHostAsync(new RHostStartupInfo {
                Name = "RHostScript",
                CranMirrorName = RToolsSettings.Current.CranMirror,
                CodePage = RToolsSettings.Current.RCodePage,
                RHostCommandLineArguments = RToolsSettings.Current.LastActiveConnection.RCommandLineArguments
            }, _clientApp ?? new RHostClientTestApp(), 50000);
        }
Beispiel #56
0
        public WorkingDirectoryCommand(IRInteractiveWorkflow interactiveWorkflow) :
            base(new[] {
            new CommandId(RGuidList.RCmdSetGuid, RPackageCommandId.icmdGetDirectoryList),
            new CommandId(RGuidList.RCmdSetGuid, RPackageCommandId.icmdSetWorkingDirectory)
        }, false)
        {
            _interactiveWorkflow       = interactiveWorkflow;
            _session                   = interactiveWorkflow.RSession;
            _session.Connected        += OnSessionConnected;
            _session.DirectoryChanged += OnCurrentDirectoryChanged;

            if (InitializationTask == null && _session.IsHostRunning)
            {
                InitializationTask = UpdateRUserDirectoryAsync();
            }
        }
        public HelpWindowVisualComponent()
        {
            _session = VsAppShell.Current.ExportProvider.GetExportedValue <IRSessionProvider>().GetInteractiveWindowRSession();
            _session.Disconnected += OnRSessionDisconnected;

            _windowContentControl = new ContentControl();
            Control = _windowContentControl;

            var c = new Controller();

            c.AddCommandSet(GetCommands());
            Controller = c;

            CreateBrowser();
            VSColorTheme.ThemeChanged += OnColorThemeChanged;
        }
Beispiel #58
0
        public static async Task<IGridData<string>> GetGridDataAsync(IRSession rSession, string expression, GridRange? gridRange, ISortOrder sortOrder = null) {
            await TaskUtilities.SwitchToBackgroundThread();

            string rows = gridRange?.Rows.ToRString();
            string columns = gridRange?.Columns.ToRString();
            string rowSelector = (sortOrder != null && !sortOrder.IsEmpty) ? sortOrder.GetRowSelector() : "";
            string expr = Invariant($"rtvs:::grid_data({expression}, {rows}, {columns}, {rowSelector})");

            try {
                return await rSession.EvaluateAsync<GridData>(expr, REvaluationKind.Normal);
            } catch (RException ex) {
                var message = Invariant($"Grid data evaluation failed:{Environment.NewLine}{ex.Message}");
                await VsAppShell.Current.Services.Log.WriteAsync(LogVerbosity.Normal, MessageCategory.Error, message);
                return null;
            }
        }
Beispiel #59
0
        public PackageIndex(IRInteractiveWorkflowProvider interactiveWorkflowProvider, ICoreShell shell, IIntellisenseRSession host, IFunctionIndex functionIndex) {
            _shell = shell;
            _host = host;
            _functionIndex = functionIndex;

            _workflow = interactiveWorkflowProvider.GetOrCreate();

            _interactiveSession = _workflow.RSession;
            _interactiveSession.Connected += OnSessionConnected;
            _interactiveSession.PackagesInstalled += OnPackagesChanged;
            _interactiveSession.PackagesRemoved += OnPackagesChanged;

            _workflow.RSessions.BrokerStateChanged += OnBrokerStateChanged;

            if (_workflow.RSession.IsHostRunning) {
                BuildIndexAsync().DoNotWait();
            }
        }
        public async Task<DebugSession> GetDebugSessionAsync(IRSession session, CancellationToken cancellationToken = default(CancellationToken)) {
            DebugSession debugSession;

            await _sem.WaitAsync(cancellationToken).ConfigureAwait(false);
            try {
                if (!_debugSessions.TryGetValue(session, out debugSession)) {
                    debugSession = new DebugSession(session);
                    await debugSession.InitializeAsync(cancellationToken).ConfigureAwait(false);
                    _debugSessions.Add(session, debugSession);
                }

                session.Disposed += Session_Disposed;
            } finally {
                _sem.Release();
            }

            return debugSession;
        }