/// <summary> /// Opens the find symbols dialog with a list of results. This is done by requesting /// that VS does a search against our library GUID. Our library then responds to /// that request by extracting the prvoided symbol list out and using that for the /// search results. /// </summary> private static void ShowFindSymbolsDialog(ExpressionAnalysis provider, IVsNavInfo symbols) { // ensure our library is loaded so find all references will go to our library //VSGeneroPackage.GetGlobalService(typeof(IGeneroLibraryManager)); // For some reason, using the GetGlobalService call was calling resulting in a call to an external package function, if it existed. // We want to keep the call to within this package. VSGeneroPackage.Instance.LoadLibraryManager(); if (provider != null && provider.Expression != "") { var findSym = (IVsFindSymbol)VSGeneroPackage.GetGlobalService(typeof(SVsObjectSearch)); VSOBSEARCHCRITERIA2 searchCriteria = new VSOBSEARCHCRITERIA2(); searchCriteria.eSrchType = VSOBSEARCHTYPE.SO_ENTIREWORD; searchCriteria.pIVsNavInfo = symbols; searchCriteria.grfOptions = (uint)_VSOBSEARCHOPTIONS2.VSOBSO_LISTREFERENCES; searchCriteria.szName = provider.Expression; Guid guid = Guid.Empty; // new Guid("{a5a527ea-cf0a-4abf-b501-eafe6b3ba5c6}") int hResult = findSym.DoSearch(new Guid(CommonConstants.LibraryGuid), new VSOBSEARCHCRITERIA2[] { searchCriteria }); ErrorHandler.ThrowOnFailure(hResult); } else { var statusBar = (IVsStatusbar)VSGeneroPackage.GetGlobalService(typeof(SVsStatusbar)); statusBar.SetText("The caret must be on valid expression to find all references."); } }
internal ITextBuffer GetBufferAt(string filePath) { var componentModel = (IComponentModel)VSGeneroPackage.GetGlobalService(typeof(SComponentModel)); var editorAdapterFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); IOleServiceProvider provider = VSGeneroPackage.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; var serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(provider); IVsUIHierarchy uiHierarchy; uint itemID; IVsWindowFrame windowFrame; if (VsShellUtilities.IsDocumentOpen( serviceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { IVsTextView view = VsShellUtilities.GetTextView(windowFrame); IVsTextLines lines; if (view.GetBuffer(out lines) == 0) { var buffer = lines as IVsTextBuffer; if (buffer != null) { return(editorAdapterFactoryService.GetDataBuffer(buffer)); } } } return(null); }
private void UpdateStatusForIncompleteAnalysis() { var statusBar = (IVsStatusbar)VSGeneroPackage.GetGlobalService(typeof(SVsStatusbar)); var analyzer = _textView.GetAnalyzer(); if (analyzer != null && analyzer.IsAnalyzing) { statusBar.SetText("Python source analysis is not up to date"); } }
private void QueryStatusRename(OLECMD[] prgCmds, int i) { IWpfTextView activeView = VSGeneroPackage.GetActiveTextView(); if (_textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentType4GL) || _textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentTypeINC) || _textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentTypePER)) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } }
internal static void GotoSource(this LocationInfo location) { if (location.Line > 0 && location.Column > 0) { VSGeneroPackage.NavigateTo( location.FilePath, Guid.Empty, location.Line - 1, location.Column - 1); } else { VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index); } }
int IVsTaskItem.NavigateTo() { try { if (Span.Start.Line == 1 && Span.Start.Column == 1 && Span.Start.Index != 0) { // we have just an absolute index, use that to naviagte VSGeneroPackage.NavigateTo(SourceFile, Guid.Empty, Span.Start.Index); } else { VSGeneroPackage.NavigateTo(SourceFile, Guid.Empty, Span.Start.Line - 1, Span.Start.Column - 1); } return(VSConstants.S_OK); } catch (DirectoryNotFoundException) { // This may happen when the error was in a file that's located inside a .zip archive. // Let's walk the path and see if it is indeed the case. for (var path = SourceFile; CommonUtils.IsValidPath(path); path = Path.GetDirectoryName(path)) { if (!File.Exists(path)) { continue; } var ext = Path.GetExtension(path); if (string.Equals(ext, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(ext, ".egg", StringComparison.OrdinalIgnoreCase)) { MessageBox.Show( "Opening source files contained in .zip archives is not supported", "Cannot open file", MessageBoxButtons.OK, MessageBoxIcon.Information ); return(VSConstants.S_FALSE); } } // If it failed for some other reason, let caller handle it. throw; } }
internal void RefactorRename() { var analyzer = _textView.GetAnalyzer(); if (analyzer.IsAnalyzing) { var dialog = new WaitForCompleteAnalysisDialog(analyzer); var res = dialog.ShowModal(); if (res != true) { // user cancelled dialog before analysis completed... return; } } new VariableRenamer(_textView, _functionProvider, _databaseProvider, _programFileProvider, _serviceProvider).RenameVariable( new RenameVariableUserInput(_serviceProvider), (IVsPreviewChangesService)VSGeneroPackage.GetGlobalService(typeof(SVsPreviewChangesService)) ); }
public override void DoCommand(object sender, EventArgs args) { // TODO: get the selected text in the code window and copy any extracted sql statements to the clipboard if (VSGeneroPackage.Instance.ActiveDocument != null) { EnvDTE.TextSelection sel = (EnvDTE.TextSelection)VSGeneroPackage.Instance.ActiveDocument.Selection; if (sel != null && sel.Text.Length > 0) { StringBuilder sb = new StringBuilder(); foreach (var fragment in SqlStatementExtractor.ExtractStatements(sel.Text)) { sb.AppendLine(fragment.GetText()); sb.AppendLine(); } var tempText = sb.ToString().Trim(); if (tempText.Length > 0) { SqlExtensions.SetSqlExtractionFile(VSGeneroPackage.Instance.ActiveDocument.Path); ITextBuffer buffer = null; if (_tempfilename == null || (buffer = GetBufferAt(_tempfilename)) == null) { _tempfilename = Path.GetTempPath() + "temp_sql_file.sql"; File.WriteAllText(_tempfilename, tempText); VSGeneroPackage.NavigateTo(_tempfilename, Guid.Empty, 0); } else { var edit = buffer.CreateEdit(); edit.Insert(buffer.CurrentSnapshot.Length, (buffer.CurrentSnapshot.LineCount > 0 ? "\n\n" : "") + tempText); edit.Apply(); } } } } }
private void QueryStatusExtractMethod(OLECMD[] prgCmds, int i) { var activeView = VSGeneroPackage.GetActiveTextView(); if (_textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentType4GL) || _textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentTypeINC) || _textView.TextBuffer.ContentType.IsOfType(VSGeneroConstants.ContentTypePER)) { 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); } }
internal static void GotoSource(this LocationInfo location, IServiceProvider serviceProvider, GeneroLanguageVersion languageVersion) { if (location.Line > 0 && location.Column > 0) { VSGeneroPackage.NavigateTo( location.FilePath, Guid.Empty, location.Line - 1, location.Column - 1); } else if (location.DefinitionURL != null) { var urlStr = location.GetUrlString(languageVersion); Uri definitionUrl; if (Uri.TryCreate(urlStr, UriKind.Absolute, out definitionUrl)) { if (serviceProvider != null) { IVsWebBrowsingService service = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; if (service != null) { if (VSGeneroPackage.Instance.AdvancedOptions4GL.OpenExternalBrowser) { __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow; VSPREVIEWRESOLUTION resolution = VSPREVIEWRESOLUTION.PR_Default; int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, definitionUrl.AbsoluteUri)); if (ErrorHandler.Succeeded(result)) { return; } } else { IVsWindowFrame ppFrame; int result = ErrorHandler.CallWithCOMConvention(() => service.Navigate(definitionUrl.AbsoluteUri, 0, out ppFrame)); if (ErrorHandler.Succeeded(result)) { return; } } } } // Fall back to Shell Execute, but only for http or https URIs if (definitionUrl.Scheme != "http" && definitionUrl.Scheme != "https") { return; } try { Process.Start(definitionUrl.AbsoluteUri); } catch (Win32Exception) { } catch (FileNotFoundException) { } } } else { VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index); } }
public GeneroLibraryManager(VSGeneroPackage /*!*/ package) : base(package) { _package = package; }
public ITextBuffer GetBufferForDocument(string filename) { return(VSGeneroPackage.GetBufferForDocument(_serviceProvider, filename)); }