private async Task ResetInteractiveAsync( IVsInteractiveWindow vsInteractiveWindow, ImmutableArray <string> referencePaths, ImmutableArray <string> referenceSearchPaths, ImmutableArray <string> sourceSearchPaths, ImmutableArray <string> namespacesToImport, string projectDirectory, IWaitContext waitContext) { // First, open the repl window. var engine = (InteractiveEvaluator)vsInteractiveWindow.InteractiveWindow.Evaluator; // If the user hits the cancel button on the wait indicator, then we want to stop the // build. waitContext.CancellationToken.Register(() => _dte.ExecuteCommand("Build.Cancel"), useSynchronizationContext: true); // First, start a build await BuildProject().ConfigureAwait(true); // Then reset the REPL waitContext.Message = ServicesVSResources.ResettingInteractive; await vsInteractiveWindow.InteractiveWindow.Operations.ResetAsync(initialize : false).ConfigureAwait(true); // Now send the reference paths we've collected to the repl. await engine.SetPathsAsync(referenceSearchPaths, sourceSearchPaths, projectDirectory).ConfigureAwait(true); await vsInteractiveWindow.InteractiveWindow.SubmitAsync(new[] { referencePaths.Select(_createReference).Join("\r\n"), namespacesToImport.Select(_createImport).Join("\r\n") }).ConfigureAwait(true); }
public IVsInteractiveWindow Open(bool focus) { _vsImmediateWindow = _vsImmediateWindow ?? Create(); _vsImmediateWindow.Show(focus); return _vsImmediateWindow; }
public void Create(int instanceId) { var evaluator = CreateInteractiveEvaluator(_vsServiceProvider, _classifierAggregator, _contentTypeRegistry, _vsWorkspace); Debug.Assert(_vsInteractiveWindow == null); // ForceCreate means that the window should be created if the persisted layout indicates that it is visible. _vsInteractiveWindow = _vsInteractiveWindowFactory.Create(Id, instanceId, Title, evaluator, __VSCREATETOOLWIN.CTW_fForceCreate); _vsInteractiveWindow.SetLanguage(LanguageServiceGuid, evaluator.ContentType); if (_vsInteractiveWindow is ToolWindowPane interactiveWindowPane) { evaluator.OnBeforeReset += is64bit => interactiveWindowPane.Caption = Title + (is64bit ? " (64-bit)" : " (32-bit)"); } var window = _vsInteractiveWindow.InteractiveWindow; window.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.SuggestionMarginId, true); void closeEventDelegate(object sender, EventArgs e) { window.TextView.Closed -= closeEventDelegate; LogCloseSession(evaluator.SubmissionCount); evaluator.Dispose(); } // the tool window now owns the engine: window.TextView.Closed += closeEventDelegate; // vsWindow.AutoSaveOptions = true; // fire and forget: window.InitializeAsync(); LogSession(LogMessage.Window, LogMessage.Create); }
public IVsInteractiveWindow Open(bool focus) { _vsImmediateWindow = _vsImmediateWindow ?? Create(); _vsImmediateWindow.Show(focus); return(_vsImmediateWindow); }
public void Create(int instanceId) { var evaluator = CreateInteractiveEvaluator(_vsServiceProvider, _classifierAggregator, _contentTypeRegistry, _vsWorkspace); Debug.Assert(this._vsInteractiveWindow == null); // ForceCreate means that the window should be created if the persisted layout indicates that it is visible. _vsInteractiveWindow = _vsInteractiveWindowFactory.Create(Id, instanceId, Title, evaluator, __VSCREATETOOLWIN.CTW_fForceCreate); _vsInteractiveWindow.SetLanguage(LanguageServiceGuid, evaluator.ContentType); var window = _vsInteractiveWindow.InteractiveWindow; window.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.SuggestionMarginId, true); EventHandler closeEventDelegate = null; closeEventDelegate = (sender, e) => { window.TextView.Closed -= closeEventDelegate; InteractiveWindow.InteractiveWindow intWindow = window as InteractiveWindow.InteractiveWindow; LogCloseSession(intWindow.LanguageBufferCounter); evaluator.Dispose(); }; // the tool window now owns the engine: window.TextView.Closed += closeEventDelegate; // vsWindow.AutoSaveOptions = true; // fire and forget: window.InitializeAsync(); LogSession(LogMessage.Window, LogMessage.Create); }
public void Create(int instanceId) { var evaluator = CreateInteractiveEvaluator( _vsServiceProvider, _classifierAggregator, _contentTypeRegistry, _vsWorkspace ); Debug.Assert(_vsInteractiveWindow == null); // ForceCreate means that the window should be created if the persisted layout indicates that it is visible. _vsInteractiveWindow = _vsInteractiveWindowFactory.Create( Id, instanceId, Title, evaluator, __VSCREATETOOLWIN.CTW_fForceCreate ); _vsInteractiveWindow.SetLanguage(LanguageServiceGuid, evaluator.ContentType); if (_vsInteractiveWindow is ToolWindowPane interactiveWindowPane) { evaluator.OnBeforeReset += platform => interactiveWindowPane.Caption = Title + platform switch { InteractiveHostPlatform.Desktop64 => " (.NET Framework " + ServicesVSResources.Bitness64 + ")", InteractiveHostPlatform.Desktop32 => " (.NET Framework " + ServicesVSResources.Bitness32 + ")", InteractiveHostPlatform.Core => " (.NET Core)", _ => throw ExceptionUtilities.Unreachable }; } var window = _vsInteractiveWindow.InteractiveWindow; window.TextView.Options.SetOptionValue( DefaultTextViewHostOptions.SuggestionMarginId, true ); void closeEventDelegate(object sender, EventArgs e) { window.TextView.Closed -= closeEventDelegate; LogCloseSession(evaluator.SubmissionCount); evaluator.Dispose(); } // the tool window now owns the engine: window.TextView.Closed += closeEventDelegate; // vsWindow.AutoSaveOptions = true; // fire and forget: window.InitializeAsync(); LogSession(LogMessage.Window, LogMessage.Create); }
public static InteractiveWindowEvents TryGet(IVsInteractiveWindow window) { InteractiveWindowEvents events; if (window.InteractiveWindow.Properties.TryGetProperty(typeof(InteractiveWindowEvents), out events) && !(events?.IsDisposed ?? true)) { return events; } return null; }
public IVsInteractiveWindow OpenOrCreateWindow(int id) { if (this.window == null) { this.window = CreateReplWindow(id); } return(this.window); }
public static InteractiveWindowEvents GetOrCreate(IVsInteractiveWindow window) { return window.InteractiveWindow.Properties.GetOrCreateSingletonProperty(typeof(InteractiveWindowEvents), () => { var frame = (window as ToolWindowPane)?.Frame as IVsWindowFrame2; if (frame == null) { return null; } return new InteractiveWindowEvents(frame, window); }); }
public static InteractiveWindowEvents TryGet(IVsInteractiveWindow window) { InteractiveWindowEvents events; if (window.InteractiveWindow.Properties.TryGetProperty(typeof(InteractiveWindowEvents), out events) && !(events?.IsDisposed ?? true)) { return(events); } return(null); }
public static InteractiveWindowEvents GetOrCreate(IVsInteractiveWindow window) { return(window.InteractiveWindow.Properties.GetOrCreateSingletonProperty(typeof(InteractiveWindowEvents), () => { var frame = (window as ToolWindowPane)?.Frame as IVsWindowFrame2; if (frame == null) { return null; } return new InteractiveWindowEvents(frame, window); })); }
public void OnWindowUsed(IVsInteractiveWindow window) { if (window == null) { throw new ArgumentNullException(nameof(window)); } lock (_windows) { _lruWindows.Remove(window); _lruWindows.Add(window); } }
internal void Execute(IVsInteractiveWindow vsInteractiveWindow, string title) { var hierarchyPointer = default(IntPtr); var selectionContainerPointer = default(IntPtr); try { uint itemid; IVsMultiItemSelect multiItemSelectPointer; Marshal.ThrowExceptionForHR(_monitorSelection.GetCurrentSelection( out hierarchyPointer, out itemid, out multiItemSelectPointer, out selectionContainerPointer)); if (hierarchyPointer != IntPtr.Zero) { List<string> references, referenceSearchPaths, sourceSearchPaths, namespacesToImport; string projectDirectory; GetProjectProperties(hierarchyPointer, out references, out referenceSearchPaths, out sourceSearchPaths, out namespacesToImport, out projectDirectory); // Now, we're going to do a bunch of async operations. So create a wait // indicator so the user knows something is happening, and also so they cancel. var waitIndicator = _componentModel.GetService<IWaitIndicator>(); var waitContext = waitIndicator.StartWait(title, ServicesVSResources.BuildingProject, allowCancel: true); var resetInteractiveTask = ResetInteractiveAsync( vsInteractiveWindow, references.ToImmutableArray(), referenceSearchPaths.ToImmutableArray(), sourceSearchPaths.ToImmutableArray(), namespacesToImport.ToImmutableArray(), projectDirectory, waitContext); // Once we're done resetting, dismiss the wait indicator and focus the REPL window. resetInteractiveTask.SafeContinueWith( _ => { waitContext.Dispose(); // We have to set focus to the Interactive Window *after* the wait indicator is dismissed. vsInteractiveWindow.Show(focus: true); }, TaskScheduler.FromCurrentSynchronizationContext()); } } finally { SafeRelease(hierarchyPointer); SafeRelease(selectionContainerPointer); } }
public IVsInteractiveWindow Open(int instanceId, bool focus) { // TODO: we don't support multi-instance yet Debug.Assert(instanceId == 0); if (_vsInteractiveWindow == null) { _vsInteractiveWindow = Create(instanceId); } _vsInteractiveWindow.Show(focus); return(_vsInteractiveWindow); }
internal void Execute(IVsInteractiveWindow vsInteractiveWindow, string title) { var hierarchyPointer = default(IntPtr); var selectionContainerPointer = default(IntPtr); try { uint itemid; IVsMultiItemSelect multiItemSelectPointer; Marshal.ThrowExceptionForHR(_monitorSelection.GetCurrentSelection( out hierarchyPointer, out itemid, out multiItemSelectPointer, out selectionContainerPointer)); if (hierarchyPointer != IntPtr.Zero) { List <string> references, referenceSearchPaths, sourceSearchPaths, namespacesToImport; string projectDirectory; GetProjectProperties(hierarchyPointer, out references, out referenceSearchPaths, out sourceSearchPaths, out namespacesToImport, out projectDirectory); // Now, we're going to do a bunch of async operations. So create a wait // indicator so the user knows something is happening, and also so they cancel. var waitIndicator = _componentModel.GetService <IWaitIndicator>(); var waitContext = waitIndicator.StartWait(title, ServicesVSResources.BuildingProject, allowCancel: true); var resetInteractiveTask = ResetInteractiveAsync( vsInteractiveWindow, references.ToImmutableArray(), referenceSearchPaths.ToImmutableArray(), sourceSearchPaths.ToImmutableArray(), namespacesToImport.ToImmutableArray(), projectDirectory, waitContext); // Once we're done resetting, dismiss the wait indicator and focus the REPL window. resetInteractiveTask.SafeContinueWith( _ => { waitContext.Dispose(); // We have to set focus to the Interactive Window *after* the wait indicator is dismissed. vsInteractiveWindow.Show(focus: true); }, TaskScheduler.FromCurrentSynchronizationContext()); } } finally { SafeRelease(hierarchyPointer); SafeRelease(selectionContainerPointer); } }
private IVsInteractiveWindow CreateReplWindow(int replId) { if (replId < 0) { replId = this.curId++; } if (this.window != null) { Debug.Fail("Should not create a window when we already have a window."); } this.window = CreateReplWindowInternal(this.GetReplEvaluator(), replId, Resources.InteractiveWindowTitle, Guids.TypeScriptLanguageInfo); this.window.InteractiveWindow.TextView.Closed += (s, e) => { this.window = null; }; return(this.window); }
public ReplWindowProxy WaitForInteractiveWindow(string title, ReplWindowProxySettings settings = null) { var iwp = GetService <IComponentModel>(typeof(SComponentModel))?.GetService <InteractiveWindowProvider>(); IVsInteractiveWindow window = null; for (int retries = 20; retries > 0 && window == null; --retries) { System.Threading.Thread.Sleep(100); window = iwp?.AllOpenWindows.FirstOrDefault(w => ((ToolWindowPane)w).Caption == title); } if (window == null) { Trace.TraceWarning( "Failed to find {0} in {1}", title, string.Join(", ", iwp?.AllOpenWindows.Select(w => ((ToolWindowPane)w).Caption) ?? Enumerable.Empty <string>()) ); return(null); } return(new ReplWindowProxy(this, window.InteractiveWindow, (ToolWindowPane)window, settings ?? new ReplWindowProxySettings())); }
private async Task ResetInteractiveAsync( IVsInteractiveWindow vsInteractiveWindow, ImmutableArray<string> referencePaths, ImmutableArray<string> referenceSearchPaths, ImmutableArray<string> sourceSearchPaths, ImmutableArray<string> namespacesToImport, string projectDirectory, IWaitContext waitContext) { // First, open the repl window. var engine = (InteractiveEvaluator)vsInteractiveWindow.InteractiveWindow.Evaluator; // If the user hits the cancel button on the wait indicator, then we want to stop the // build. waitContext.CancellationToken.Register(() => _dte.ExecuteCommand("Build.Cancel"), useSynchronizationContext: true); // First, start a build await BuildProject().ConfigureAwait(true); // Then reset the REPL waitContext.Message = ServicesVSResources.ResettingInteractive; await vsInteractiveWindow.InteractiveWindow.Operations.ResetAsync(initialize: false).ConfigureAwait(true); // Now send the reference paths we've collected to the repl. await engine.SetPathsAsync(referenceSearchPaths, sourceSearchPaths, projectDirectory).ConfigureAwait(true); await vsInteractiveWindow.InteractiveWindow.SubmitAsync(new[] { referencePaths.Select(_createReference).Join("\r\n"), namespacesToImport.Select(_createImport).Join("\r\n") }).ConfigureAwait(true); }
private Task ResetInteractiveAsync( IVsInteractiveWindow vsInteractiveWindow, List <string> referencePaths, List <string> referenceSearchPaths, List <string> sourceSearchPaths, List <string> namespacesToImport, string projectDirectory, IWaitContext waitContext) { // First, open the repl window. var engine = (InteractiveEvaluator)vsInteractiveWindow.InteractiveWindow.Evaluator; var uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); // If the user hits the cancel button on the wait indicator, then we want to stop the // build. waitContext.CancellationToken.Register(() => _dte.ExecuteCommand("Build.Cancel"), useSynchronizationContext: true); // First, start a build. var buildTask = BuildProject(); // Then reset the repl. var resetTask = buildTask.SafeContinueWithFromAsync(_ => { waitContext.Message = ServicesVSResources.ResettingInteractive; return(vsInteractiveWindow.InteractiveWindow.Operations.ResetAsync(initialize: false)); }, waitContext.CancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, uiTaskScheduler); // Now send the reference paths we've collected to the repl. var submitReferencesTask = resetTask.SafeContinueWith( _ => { // TODO (tomat): In general, these settings should be applied again when we auto-reset. engine.SetInitialPaths( referenceSearchPaths.ToArray(), sourceSearchPaths.ToArray(), projectDirectory); vsInteractiveWindow.InteractiveWindow.SubmitAsync(new[] { // TODO(DustinCa): Update these to be language agnostic. referencePaths.Select(_createReference).Join("\r\n"), namespacesToImport.Select(_createImport).Join("\r\n") }); }, waitContext.CancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, uiTaskScheduler); return(submitReferencesTask); //// TODO (tomat): Ideally we should check if the imported namespaces are available in #r'd assemblies. //// We should wait until #r submission is finished and then query for existing namespaces. ////if (namespacesToImport.IsEmpty()) ////{ //// return submitReferencesTask; ////} ////var submitReferencesAndUsingsTask = submitReferencesTask.SafeContinueWith( //// _ => //// { //// var compilation = engine.GetPreviousSubmissionProject().GetCompilation(waitContext.CancellationToken); //// replWindow.Submit(new[] //// { //// (from ns in namespacesToImport //// where compilation.GlobalNamespace.GetMembers(ns, waitContext.CancellationToken).Any() //// select string.Format("using {0};", ns)).Join("\r\n") //// }); //// }, //// waitContext.CancellationToken, //// TaskContinuationOptions.OnlyOnRanToCompletion, //// uiTaskScheduler); //// return submitReferencesAndUsingsTask; }
public InteractiveWindowInfo(IVsInteractiveWindow replWindow, string replId) { Window = replWindow; Id = replId; }
private InteractiveWindowEvents(IVsWindowFrame2 frame, IVsInteractiveWindow window) { _frame = frame; _window = window; ErrorHandler.ThrowOnFailure(frame.Advise(this, out _cookie)); }
public void Create(int instanceId) { var evaluator = CreateInteractiveEvaluator(_vsServiceProvider, _classifierAggregator, _contentTypeRegistry, _vsWorkspace); Debug.Assert(_vsInteractiveWindow == null); // ForceCreate means that the window should be created if the persisted layout indicates that it is visible. _vsInteractiveWindow = _vsInteractiveWindowFactory.Create(Id, instanceId, Title, evaluator, __VSCREATETOOLWIN.CTW_fForceCreate); _vsInteractiveWindow.SetLanguage(LanguageServiceGuid, evaluator.ContentType); var window = _vsInteractiveWindow.InteractiveWindow; window.TextView.Options.SetOptionValue(DefaultTextViewHostOptions.SuggestionMarginId, true); EventHandler closeEventDelegate = null; closeEventDelegate = (sender, e) => { window.TextView.Closed -= closeEventDelegate; LogCloseSession(evaluator.SubmissionCount); evaluator.Dispose(); }; // the tool window now owns the engine: window.TextView.Closed += closeEventDelegate; // vsWindow.AutoSaveOptions = true; // fire and forget: window.InitializeAsync(); LogSession(LogMessage.Window, LogMessage.Create); }
public IVsInteractiveWindow Open(int instanceId, bool focus) { // TODO: we don't support multi-instance yet Debug.Assert(instanceId == 0); if (_vsInteractiveWindow == null) { _vsInteractiveWindow = Create(instanceId); } _vsInteractiveWindow.Show(focus); return _vsInteractiveWindow; }
internal static IVsInteractiveWindow GetVsInteractiveWindow(IInteractiveWindow window) { IVsInteractiveWindow wnd = null; return((window?.Properties.TryGetProperty(VsInteractiveWindowKey, out wnd) ?? false) ? wnd : null); }
private Task ResetInteractiveAsync( IVsInteractiveWindow vsInteractiveWindow, List<string> referencePaths, List<string> referenceSearchPaths, List<string> sourceSearchPaths, List<string> namespacesToImport, string projectDirectory, IWaitContext waitContext) { // First, open the repl window. var engine = (InteractiveEvaluator)vsInteractiveWindow.InteractiveWindow.Evaluator; var uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); // If the user hits the cancel button on the wait indicator, then we want to stop the // build. waitContext.CancellationToken.Register(() => _dte.ExecuteCommand("Build.Cancel"), useSynchronizationContext: true); // First, start a build. var buildTask = BuildProject(); // Then reset the repl. var resetTask = buildTask.SafeContinueWithFromAsync(_ => { waitContext.Message = ServicesVSResources.ResettingInteractive; return vsInteractiveWindow.InteractiveWindow.Operations.ResetAsync(initialize: false); }, waitContext.CancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, uiTaskScheduler); // Now send the reference paths we've collected to the repl. var submitReferencesTask = resetTask.SafeContinueWith( _ => { // TODO (tomat): In general, these settings should be applied again when we auto-reset. engine.SetInitialPaths( referenceSearchPaths.ToArray(), sourceSearchPaths.ToArray(), projectDirectory); vsInteractiveWindow.InteractiveWindow.Submit(new[] { // TODO(DustinCa): Update these to be language agnostic. referencePaths.Select(_createReference).Join("\r\n"), namespacesToImport.Select(_createImport).Join("\r\n") }); }, waitContext.CancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, uiTaskScheduler); return submitReferencesTask; //// TODO (tomat): Ideally we should check if the imported namespaces are available in #r'd assemblies. //// We should wait until #r submission is finished and then query for existing namespaces. ////if (namespacesToImport.IsEmpty()) ////{ //// return submitReferencesTask; ////} ////var submitReferencesAndUsingsTask = submitReferencesTask.SafeContinueWith( //// _ => //// { //// var compilation = engine.GetPreviousSubmissionProject().GetCompilation(waitContext.CancellationToken); //// replWindow.Submit(new[] //// { //// (from ns in namespacesToImport //// where compilation.GlobalNamespace.GetMembers(ns, waitContext.CancellationToken).Any() //// select string.Format("using {0};", ns)).Join("\r\n") //// }); //// }, //// waitContext.CancellationToken, //// TaskContinuationOptions.OnlyOnRanToCompletion, //// uiTaskScheduler); //// return submitReferencesAndUsingsTask; }