public override void DoCommand(object sender, EventArgs args) { var window = (IReplWindow)EnsureReplWindow(); IVsWindowFrame windowFrame = (IVsWindowFrame)((ToolWindowPane)window).Frame; string filename, dir; if (!CommonPackage.TryGetStartupFileAndDirectory(out filename, out dir)) { // TODO: Error reporting return; } ErrorHandler.ThrowOnFailure(windowFrame.Show()); window.Focus(); ((RemoteRubyEvaluator)window.Evaluator).Reset(); window.WriteLine(String.Format("Running {0}", filename)); string scopeName = Path.GetFileNameWithoutExtension(filename); // now execute the current file in the REPL var engine = ((RemoteRubyEvaluator)window.Evaluator).Engine; ThreadPool.QueueUserWorkItem( _ => { try { var src = engine.CreateScriptSourceFromFile(filename, StringUtils.DefaultEncoding, Scripting.SourceCodeKind.Statements); src.Compile().Execute(((RemoteRubyEvaluator)window.Evaluator).CurrentScope); } catch (Exception e) { window.WriteLine(String.Format("Exception: {0}", e)); } } ); }
private void QueryStatusMethod(object sender, EventArgs args) { var oleMenu = sender as OleMenuCommand; IWpfTextView textView; var rbProj = CommonPackage.GetStartupProject() as RubyProjectNode; if (rbProj != null) { // startup project, enabled in Start in REPL mode. oleMenu.Visible = true; oleMenu.Enabled = true; oleMenu.Supported = true; oleMenu.Text = "Execute Project in IronRuby Interactive"; } else if ((textView = CommonPackage.GetActiveTextView()) != null && textView.TextBuffer.ContentType == IronRubyToolsPackage.Instance.ContentType) { // enabled in Execute File mode... oleMenu.Visible = true; oleMenu.Enabled = true; oleMenu.Supported = true; oleMenu.Text = "Execute File in IronRuby Interactive"; } else { oleMenu.Visible = false; oleMenu.Enabled = false; oleMenu.Supported = false; } }
public override int?EditFilterQueryStatus(ref VisualStudio.OLE.Interop.OLECMD cmd, IntPtr pCmdText) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); var empty = activeView.Selection.IsEmpty; Intellisense.VsProjectAnalyzer analyzer; if (activeView != null && (analyzer = activeView.GetAnalyzerAtCaret(_serviceProvider)) != null) { if (activeView.Selection.IsEmpty || activeView.Selection.Mode == TextSelectionMode.Box || analyzer == null || !IsRealInterpreter(analyzer.InterpreterFactory)) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return(VSConstants.S_OK); }
public override async void DoCommand(object sender, EventArgs args) { var view = CommonPackage.GetActiveTextView(_serviceProvider); var analyzer = view?.GetAnalyzerAtCaret(_serviceProvider); if (analyzer == null) { // Can sometimes race with initializing the analyzer (probably // only in tests), so delay slightly until we get an analyzer for (int retries = 10; retries > 0 && analyzer == null; --retries) { await Task.Delay(10); view = CommonPackage.GetActiveTextView(_serviceProvider); analyzer = view?.GetAnalyzerAtCaret(_serviceProvider); } } var pythonCaret = view?.GetPythonCaret(); if (analyzer == null || !pythonCaret.HasValue) { Debug.Fail("Executed RemoveImportsCommand with invalid view"); return; } await analyzer.RemoveImportsAsync( view, pythonCaret.Value.Snapshot.TextBuffer, pythonCaret.Value.Position, _allScopes ); }
public override int?EditFilterQueryStatus(ref VisualStudio.OLE.Interop.OLECMD cmd, IntPtr pCmdText) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); if (activeView != null && activeView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { var analyzer = activeView.GetAnalyzer(_serviceProvider); if (activeView.Selection.IsEmpty || activeView.Selection.Mode == TextSelectionMode.Box || analyzer == null || !IsRealInterpreter(analyzer.InterpreterFactory)) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return(VSConstants.S_OK); }
public override async void DoCommand(object sender, EventArgs args) { var view = CommonPackage.GetActiveTextView(_serviceProvider); var analyzer = view.GetAnalyzer(_serviceProvider); await analyzer.RemoveImportsAsync(view.TextBuffer, view.Caret.Position.BufferPosition, _allScopes); }
public override int?EditFilterQueryStatus(ref VisualStudio.OLE.Interop.OLECMD cmd, IntPtr pCmdText) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); InterpreterConfiguration config; if ((config = activeView?.GetInterpreterConfigurationAtCaret(_serviceProvider)) != null) { if (activeView.Selection.Mode == TextSelectionMode.Box || config?.IsRunnable() != true) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return(VSConstants.S_OK); }
public override void DoCommand(object sender, EventArgs args) { if (!Utilities.SaveDirtyFiles()) { // Abort return; } // Launch with project context if there is one and it contains the active document // Fallback to using default python project var file = CommonPackage.GetActiveTextView(_serviceProvider).GetFilePath(); var pythonProjectNode = CommonPackage.GetStartupProject(_serviceProvider) as PythonProjectNode; if ((pythonProjectNode != null) && (pythonProjectNode.FindNodeByFullPath(file) == null)) { pythonProjectNode = null; } IPythonProject pythonProject = pythonProjectNode as IPythonProject ?? new DefaultPythonProject(_serviceProvider, file); var launcher = PythonToolsPackage.GetLauncher(_serviceProvider, pythonProject); try { launcher.LaunchFile(file, CommandId == CommonConstants.StartDebuggingCmdId); } catch (NoInterpretersException ex) { PythonToolsPackage.OpenNoInterpretersHelpPage(_serviceProvider, ex.HelpPage); } }
public HierarchyListener(IVsHierarchy hierarchy, CommonPackage package) { Utilities.ArgumentNotNull("hierarchy", hierarchy); Utilities.ArgumentNotNull("package", package); _hierarchy = hierarchy; _package = package; }
public override async void DoCommand(object sender, EventArgs args) { var view = CommonPackage.GetActiveTextView(_serviceProvider); var analyzer = view.GetAnalyzerAtCaret(_serviceProvider); var pythonCaret = view.GetPythonCaret().Value; // QueryStatus guarantees we have a valid caret await analyzer.RemoveImportsAsync(view, pythonCaret.Snapshot.TextBuffer, pythonCaret.Position, _allScopes); }
public override LibraryManager CreateLibraryManager(CommonPackage package) { if (_generoLibManager == null) { _generoLibManager = new GeneroLibraryManager((VSGeneroPackage)package); } return(_generoLibManager); }
private void QueryStatusRename(OLECMD[] prgCmds, int i) { IWpfTextView activeView = CommonPackage.GetActiveTextView(_serviceProvider); if (_textView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } }
public override void DoCommand(object sender, EventArgs args) { var webSite = GetSelectedAzureWebSite(); if (webSite == null) { throw new NotSupportedException(); } Uri debugUri; if (Uri.TryCreate(webSite.Uri, "/ptvsd", out debugUri)) { // Open the site's ptvsd page if it exists var req = WebRequest.CreateHttp(debugUri.AbsoluteUri); req.Method = "HEAD"; req.Accept = "text/html"; var dlgFactory = (IVsThreadedWaitDialogFactory)_serviceProvider.GetService(typeof(SVsThreadedWaitDialogFactory)); IVsThreadedWaitDialog2 dlg = null; if (dlgFactory != null && ErrorHandler.Succeeded(dlgFactory.CreateInstance(out dlg))) { if (ErrorHandler.Failed(dlg.StartWaitDialog( Strings.ProductTitle, Strings.DebugAttachGettingSiteInformation, null, null, null, 1, false, true ))) { dlg = null; } } try { req.GetResponse().Close(); } catch (WebException) { debugUri = null; } finally { if (dlg != null) { int dummy; dlg.EndWaitDialog(out dummy); } } } if (debugUri != null) { CommonPackage.OpenWebBrowser(_serviceProvider, debugUri.AbsoluteUri); } else { CommonPackage.OpenWebBrowser(_serviceProvider, "http://go.microsoft.com/fwlink/?LinkID=624026"); } }
private void UpdateStatusForIncompleteAnalysis() { var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar)); if (!IronPythonToolsPackage.Instance.Analyzer.IsAnalyzing) { statusBar.SetText("Python source analysis is not up to date"); } }
public void Initialize() { string filename, dir; if (CommonPackage.TryGetStartupFileAndDirectory(out filename, out dir)) { RemoteScriptFactory.SetCurrentDirectory(dir); } }
private static void EnsureGeneralPane() { if (!_createdGeneralPane) { var outWin = (IVsOutputWindow)CommonPackage.GetGlobalService(typeof(IVsOutputWindow)); var guid = VSConstants.GUID_OutWindowGeneralPane; outWin.CreatePane(ref guid, "General", 1, 0); _createdGeneralPane = true; } }
private void UpdateStatusForIncompleteAnalysis() { var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar)); var analyzer = _textView.GetAnalyzer(); if (analyzer != null && analyzer.IsAnalyzing) { statusBar.SetText("Node.js source analysis is not up to date"); } }
/// <summary> /// Publishes the project as configured by the user in the Publish option page. /// /// If async is true this function begins the publishing and returns w/o waiting for it to complete. No errors are reported. /// /// If async is false this function waits for the publish to finish and raises a PublishFailedException with an /// inner exception indicating the underlying reason for the publishing failure. /// /// Returns true if the publish was succeessfully started, false if the project is not configured for publishing /// </summary> public bool Publish(PublishProjectOptions publishOptions, bool async) { string publishUrl = publishOptions.DestinationUrl ?? GetProjectProperty(CommonConstants.PublishUrl); bool found = false; if (!String.IsNullOrWhiteSpace(publishUrl)) { var url = new Url(publishUrl); var publishers = CommonPackage.ComponentModel.GetExtensions <IProjectPublisher>(); foreach (var publisher in publishers) { if (publisher.Schema == url.Uri.Scheme) { var project = new PublishProject(this, publishOptions); Exception failure = null; var frame = new DispatcherFrame(); var thread = new System.Threading.Thread(x => { try { publisher.PublishFiles(project, url.Uri); project.Done(); frame.Continue = false; } catch (Exception e) { failure = e; project.Failed(e.Message); frame.Continue = false; } }); thread.Start(); found = true; if (!async) { Dispatcher.PushFrame(frame); if (failure != null) { throw new PublishFailedException(String.Format("Publishing of the project {0} failed", Caption), failure); } } break; } } if (!found) { var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar)); statusBar.SetText(String.Format("Publish failed: Unknown publish scheme ({0})", url.Uri.Scheme)); } } else { var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar)); statusBar.SetText(String.Format("Project is not configured for publishing in project properties.")); } return(found); }
public override void DoCommand(object sender, EventArgs args) { if (_useVSBrowser) { CommonPackage.OpenVsWebBrowser(_serviceProvider, _url); } else { CommonPackage.OpenWebBrowser(_url); } }
public PackageList(GObject obj,CommonPackage package) { CellList = obj.asList; var sel = from cellCom in CellList.GetChildren() select new PackageCell(cellCom.asCom); _Cells = sel.ToArray(); _Package = package; _Package.OnItemChanged += UpdateCell; CellList.numItems = _Package.Capacity; }
public override void DoCommand(object sender, EventArgs args) { if (!Utilities.SaveDirtyFiles()) { // Abort return; } // Launch with project context if there is one and it contains the active document // Fallback to using default python project var file = CommonPackage.GetActiveTextView(_serviceProvider).GetFilePath(); var sln = (IVsSolution)_serviceProvider.GetService(typeof(SVsSolution)); IEnumerable projects; try { projects = _serviceProvider.GetDTE().ActiveSolutionProjects as IEnumerable; } catch (COMException) { // ActiveSolutionProjects can fail if Solution Explorer has not been loaded projects = Enumerable.Empty <EnvDTE.Project>(); } var pythonProject = (projects == null ? null : projects.OfType <EnvDTE.Project>() .Select(p => p.GetPythonProject()) .FirstOrDefault(p => p != null && p.FindNodeByFullPath(file) != null) as IPythonProject) ?? new DefaultPythonProject(_serviceProvider, file); var launcher = PythonToolsPackage.GetLauncher(_serviceProvider, pythonProject); try { var launcher2 = launcher as IProjectLauncher2; if (launcher2 != null) { launcher2.LaunchFile( file, CommandId == CommonConstants.StartDebuggingCmdId, new LaunchFileProperties( null, PathUtils.GetParent(file), pythonProject.GetInterpreterFactory().Configuration.PathEnvironmentVariable, pythonProject.GetWorkingDirectory() ) ); } else { launcher.LaunchFile(file, CommandId == CommonConstants.StartDebuggingCmdId); } } catch (MissingInterpreterException ex) { MessageBox.Show(ex.Message, Strings.ProductTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (NoInterpretersException ex) { PythonToolsPackage.OpenNoInterpretersHelpPage(_serviceProvider, ex.HelpPage); } }
private static void OutputState(string state) { var outWin = (IVsOutputWindow)CommonPackage.GetGlobalService(typeof(IVsOutputWindow)); IVsOutputWindowPane pane; if (ErrorHandler.Succeeded(outWin.GetPane(VSConstants.GUID_OutWindowGeneralPane, out pane))) { pane.Activate(); pane.OutputString(state + Environment.NewLine); } }
public LibraryManager(CommonPackage/*!*/ package) { Contract.Assert(package != null); _package = package; _documents = new Dictionary<uint, TextLineEventListener>(); _library = new Library(new Guid(CommonConstants.LibraryGuid)); _library.LibraryCapabilities = (_LIB_FLAGS2)_LIB_FLAGS.LF_PROJECT; _files = new Dictionary<ModuleId, LibraryNode>(); var model = ((IServiceContainer)package).GetService(typeof(SComponentModel)) as IComponentModel; _adapterFactory = model.GetService<IVsEditorAdaptersFactoryService>(); // Register our library now so it'll be available for find all references RegisterLibrary(); }
public override void DoCommand(object sender, EventArgs args) { var pyProj = CommonPackage.GetStartupProject(_serviceProvider) as PythonProjectNode; var textView = CommonPackage.GetActiveTextView(_serviceProvider); VsProjectAnalyzer analyzer; string filename, dir = null; if (pyProj != null) { analyzer = pyProj.GetAnalyzer(); filename = pyProj.GetStartupFile(); dir = pyProj.GetWorkingDirectory(); } else if (textView != null) { var pyService = _serviceProvider.GetPythonToolsService(); analyzer = pyService.DefaultAnalyzer; filename = textView.GetFilePath(); } else { Debug.Fail("Should not be executing command when it is invisible"); return; } if (string.IsNullOrEmpty(filename)) { // TODO: Error reporting return; } if (string.IsNullOrEmpty(dir)) { dir = PathUtils.GetParent(filename); } var window = EnsureReplWindow(_serviceProvider, analyzer, pyProj); window.Show(true); // The interpreter may take some time to startup, do this off the UI thread. ThreadPool.QueueUserWorkItem(x => { window.InteractiveWindow.Evaluator.ResetAsync().WaitAndUnwrapExceptions(); window.InteractiveWindow.WriteLine(String.Format("Running {0}", filename)); string scopeName = Path.GetFileNameWithoutExtension(filename); ((PythonReplEvaluator)window.InteractiveWindow.Evaluator).ExecuteFile(filename); }); }
private void QueryStatusMethod(object sender, EventArgs args) { var oleMenu = sender as OleMenuCommand; if (oleMenu == null) { Debug.Fail("Unexpected command type " + sender == null ? "(null)" : sender.GetType().FullName); return; } var workspace = _serviceProvider.GetWorkspace(); var pyProj = CommonPackage.GetStartupProject(_serviceProvider) as PythonProjectNode; var textView = CommonPackage.GetActiveTextView(_serviceProvider); oleMenu.Supported = true; if (pyProj != null) { // startup project, so visible in Project mode oleMenu.Visible = true; oleMenu.Text = Strings.ExecuteInReplCommand_ExecuteProject; // Only enable if runnable oleMenu.Enabled = pyProj.GetInterpreterFactory().IsRunnable(); } else if (textView != null && textView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { // active file, so visible in File mode oleMenu.Visible = true; oleMenu.Text = Strings.ExecuteInReplCommand_ExecuteFile; // Only enable if runnable if (workspace != null) { oleMenu.Enabled = workspace.CurrentFactory.IsRunnable(); } else { var interpreterService = _serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); oleMenu.Enabled = interpreterService != null && interpreterService.DefaultInterpreter.IsRunnable(); } } else { // Python is not active, so hide the command oleMenu.Visible = false; oleMenu.Enabled = false; } }
public override int?EditFilterQueryStatus(ref VisualStudio.OLE.Interop.OLECMD cmd, IntPtr pCmdText) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); if (activeView != null && activeView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return(VSConstants.S_OK); }
public LibraryManager(CommonPackage package) { Contract.Assert(package != null); this._package = package; this._documents = new Dictionary<uint, TextLineEventListener>(); this._library = new Library(new Guid(CommonConstants.LibraryGuid)); this._library.LibraryCapabilities = (_LIB_FLAGS2)_LIB_FLAGS.LF_PROJECT; this._files = new Dictionary<ModuleId, LibraryNode>(); var model = ((IServiceContainer)package).GetService(typeof(SComponentModel)) as IComponentModel; this._adapterFactory = model.GetService<IVsEditorAdaptersFactoryService>(); // Register our library now so it'll be available for find all references RegisterLibrary(); }
private void QueryStatusExtractMethod(OLECMD[] prgCmds, int i) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); if (_textView.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) { if (_textView.Selection.IsEmpty || _textView.Selection.Mode == TextSelectionMode.Box || String.IsNullOrWhiteSpace(_textView.Selection.StreamSelectionSpan.GetText())) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); } else { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } } else { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } }
/// <summary> /// Open a file depending on the SubType property associated with the file item in the project file /// </summary> protected override void DoDefaultAction() { if ("WebBrowser".Equals(this.SubType, StringComparison.OrdinalIgnoreCase)) { CommonPackage.OpenVsWebBrowser(this.ProjectMgr.Site, this.Url); return; } var manager = this.GetDocumentManager() as FileDocumentManager; Utilities.CheckNotNull(manager, "Could not get the FileDocumentManager"); var viewGuid = Guid.Empty; manager.Open(false, false, viewGuid, out var frame, WindowFrameShowAction.Show); }
public override void DoCommand(object sender, EventArgs args) { var activeView = CommonPackage.GetActiveTextView(_serviceProvider); var project = activeView.TextBuffer.GetProject(_serviceProvider); var analyzer = activeView.GetAnalyzer(_serviceProvider); var repl = ExecuteInReplCommand.EnsureReplWindow(_serviceProvider, analyzer, project); repl.Show(true); PythonReplEvaluator eval = repl.InteractiveWindow.Evaluator as PythonReplEvaluator; eval.EnsureConnected(); repl.InteractiveWindow.Submit(GetActiveInputs(activeView, eval)); repl.Show(true); }
public override int?EditFilterQueryStatus(ref VisualStudio.OLE.Interop.OLECMD cmd, IntPtr pCmdText) { var view = CommonPackage.GetActiveTextView(_serviceProvider); var analyzer = view?.GetAnalyzerAtCaret(_serviceProvider); var pythonCaret = view?.GetPythonCaret(); if (view != null && analyzer != null && pythonCaret.HasValue) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return(VSConstants.S_OK); }
public JNavigateToItemProvider(IServiceProvider serviceProvider, IGlyphService glyphService, CommonPackage package) { _serviceProvider = serviceProvider; _glyphService = glyphService; _package = package; }