public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, bool signUpForFileChangeNotification) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this.EditorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>(); this.ContentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); // In the CodeSense scenario we will receive file change notifications from the native // Language Services, so we don't want to sign up for them ourselves. if (signUpForFileChangeNotification) { _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); } var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } int installed; Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed)); IsRoslynPackageInstalled = installed != 0; var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
public static IWpfTextViewHost GetCurrentViewHost(IServiceProvider serviceProvider) { IVsTextManager txtMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); if (txtMgr == null) { return(null); } IVsTextView vTextView = null; int mustHaveFocus = 1; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView); IVsUserData userData = vTextView as IVsUserData; if (userData == null) { return(null); } object holder; Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; userData.GetData(ref guidViewHost, out holder); return(holder as IWpfTextViewHost); }
private CocoJumperWordSearchCommand(AsyncPackage package, OleMenuCommandService commandService, IVsTextManager textManager, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEventAggregator eventAggregator) : base(package, commandService, textManager, editorAdaptersFactoryService, eventAggregator, CommandSet, CommandId) { }
private void OpenDocumentAndNavigateTo(string path, int startLine, int startColumn, int?endLine = null, int?endColumn = null) { IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (openDoc == null) { return; } Guid logicalView = VSConstants.LOGVIEWID_Code; IVsWindowFrame frame; try { Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; IVsUIHierarchy hier; uint itemid; openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame); } catch (Exception) { return; } object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the VsTextBuffer VsTextBuffer buffer = docData as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; try { bufferProvider.GetTextBuffer(out lines); } catch (Exception) { return; } buffer = lines as VsTextBuffer; Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer"); } } IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; if (mgr == null) { return; } mgr.NavigateToLineAndColumn(buffer, ref logicalView, startLine - 1, startColumn - 1, (endLine ?? startLine) - 1, (endColumn ?? startColumn) - 1); }
private static void OpenDocument(string filename, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame) { IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager)); IVsUIShellOpenDocument uiShellOpenDocument = Instance.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsUIHierarchy hierarchy; uint itemid; try { VsShellUtilities.OpenDocument( Instance, filename, Guid.Empty, out hierarchy, out itemid, out pWindowFrame, out viewAdapter); } catch (Exception ex) { viewAdapter = null; pWindowFrame = null; if (Instance != null) { Instance.ShowDialog("Error opening file", string.Format("Error opening file {0}: \n{1}", filename, ex.Message)); } } }
public static void NavigateTo(this IServiceProvider serviceProvider, string fileName, int startLine, int startColumn) { Guid logicalViewGuid = new Guid(LogicalViewID.TextView); IVsUIHierarchy hierarchy; uint itemId; IVsWindowFrame frame; bool isOpened = VsShellUtilities.IsDocumentOpen(serviceProvider, fileName, logicalViewGuid, out hierarchy, out itemId, out frame); if (!isOpened) { try { VsShellUtilities.OpenDocument(serviceProvider, fileName, logicalViewGuid, out hierarchy, out itemId, out frame); } catch (Exception) { // TODO: write error to output return; } } frame.Show(); IVsTextLines textBuffer; VsShellUtilities.GetTextView(frame).GetBuffer(out textBuffer); IVsTextManager manager = serviceProvider.GetService <IVsTextManager, SVsTextManager>(); manager.NavigateToLineAndColumn(textBuffer, logicalViewGuid, startLine, startColumn, startLine, startColumn); }
private IWpfTextView GetTextView() { IVsTextManager textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); IVsTextView textView; textManager.GetActiveView(1, null, out textView); return GetEditorAdaptersFactoryService().GetWpfTextView(textView); }
public FormatDocumentOnBeforeSave(DTE dte, RunningDocumentTable runningDocumentTable, IVsTextManager txtMngr, SettingsPage settingsPage) { _runningDocumentTable = runningDocumentTable; _txtMngr = txtMngr; _dte = dte; _settingsPage = settingsPage; }
public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, bool signUpForFileChangeNotification) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this.EditorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); this.ContentTypeRegistryService = componentModel.GetService <IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService <ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); // In the CodeSense scenario we will receive file change notifications from the native // Language Services, so we don't want to sign up for them ourselves. if (signUpForFileChangeNotification) { _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); } var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); int installed; Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed)); IsRoslynPackageInstalled = installed != 0; var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
/// <summary> /// Initializes objects used to access opened document's buffer /// </summary> protected void InitializeVariables() { currentDocument = VisualLocalizerPackage.Instance.DTE.ActiveDocument; if (currentDocument == null) { throw new Exception("No selected document"); } if (currentDocument.ReadOnly) { throw new Exception("Cannot perform this operation - active document is readonly"); } bool fileOpened; currentCodeModel = currentDocument.ProjectItem.GetCodeModel(false, false, out fileOpened); textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager)); if (textManager == null) { throw new Exception("Cannot consume IVsTextManager service"); } int hr = textManager.GetActiveView(1, null, out textView); Marshal.ThrowExceptionForHR(hr); hr = textView.GetBuffer(out textLines); Marshal.ThrowExceptionForHR(hr); hr = textLines.GetUndoManager(out undoManager); Marshal.ThrowExceptionForHR(hr); }
IWpfTextViewHost GetCurrentViewHost() { // code to get access to the editor's currently selected text cribbed from // http://msdn.microsoft.com/en-us/library/dd884850.aspx IVsTextManager txtMgr = (IVsTextManager)this.ServiceProvider.GetService(typeof(SVsTextManager)); if (txtMgr == null) { return(null); } IVsTextView vTextView = null; int mustHaveFocus = 1; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView); IVsUserData userData = vTextView as IVsUserData; if (userData == null) { return(null); } else { IWpfTextViewHost viewHost; object holder; Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; userData.GetData(ref guidViewHost, out holder); viewHost = (IWpfTextViewHost)holder; return(viewHost); } }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private void MenuItemCallback(object sender, EventArgs e) { //<Snippet37> IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); IVsTextView vTextView = null; int mustHaveFocus = 1; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView); //</Snippet37> //<Snippet38> IVsUserData userData = vTextView as IVsUserData; if (userData == null) { Console.WriteLine("No text view is currently open"); return; } IWpfTextViewHost viewHost; object holder; Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; userData.GetData(ref guidViewHost, out holder); viewHost = (IWpfTextViewHost)holder; //</Snippet38> //<Snippet39> Connector.Execute(viewHost); //</Snippet39> }
public LanguagePreferences(PythonToolsService service, Guid languageGuid) { _service = service; _service.Site.AssertShellIsInitialized(); _textMgr = (IVsTextManager)service.Site.GetService(typeof(SVsTextManager)); if (_textMgr == null) { throw new NotSupportedException(""); } var langPrefs = new LANGPREFERENCES[1]; langPrefs[0].guidLang = languageGuid; ErrorHandler.ThrowOnFailure(_textMgr.GetUserPreferences(null, null, langPrefs, null)); _preferences = langPrefs[0]; var guid = typeof(IVsTextManagerEvents2).GUID; IConnectionPoint connectionPoint = null; (_textMgr as IConnectionPointContainer)?.FindConnectionPoint(ref guid, out connectionPoint); if (connectionPoint != null) { connectionPoint.Advise(this, out _cookie); } }
public override bool ShowMethod(EventDescription eventDescription, string methodName) { CodeDomDocDataAdapter adapter = GetDocDataAdapterForXSharpFile(); List <CodeTypeMember> methodsToShow = GetHandlersFromActiveFile(methodName); if (methodsToShow == null || methodsToShow.Count < 1) { return(false); } Point point = new Point(); if (methodsToShow[0] != null) { //We can't navigate to every method, so just take the first one in the list. object pt = methodsToShow[0].UserData[typeof(Point)]; if (pt != null) { point = (Point)pt; } } //Get IVsTextManager to navigate to the code IVsTextManager mgr = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; Guid logViewCode = VSConstants.LOGVIEWID_Code; return(ErrorHandler.Succeeded(mgr.NavigateToLineAndColumn(adapter.DocData.Buffer, ref logViewCode, point.Y - 1, point.X, point.Y - 1, point.X))); }
/// <summary> /// Open the file and jump to a line (and optional column) /// </summary> public static void OpenAndNavigateTo(string fileName, int line, int column = 0) { IVsUIShellOpenDocument uishellOpenDocument = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (uishellOpenDocument != null) { Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider; IVsWindowFrame frame; IVsUIHierarchy hierarchy; uint itemId; Guid logicalView = VSConstants.LOGVIEWID_Code; if (ErrorHandler.Succeeded(uishellOpenDocument.OpenDocumentViaProject(fileName, ref logicalView, out serviceProvider, out hierarchy, out itemId, out frame))) { object document; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out document); VsTextBuffer buffer = document as VsTextBuffer; if (buffer == null) { IVsTextBufferProvider bufferProvider = document as IVsTextBufferProvider; if (bufferProvider != null) { IVsTextLines lines; ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); buffer = lines as VsTextBuffer; } } if (buffer != null) { IVsTextManager textManager = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; textManager.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column); } } } }
public ThemeOptionsControl(IThemeAwareDialog child) { InitializeComponent(); Child = child; Control control = child as Control; Debug.Assert(Child != null); Debug.Assert(control != null); tableContent.Controls.Add(control); tableContent.SetColumn(control, 0); tableContent.SetRow(control, 1); control.Dock = DockStyle.Fill; ServiceProvider provider = ServiceProvider.GlobalProvider; Service = provider.GetService(typeof(SIndentGuide)) as IndentGuideService; Child.Service = Service; TextManagerService = (IVsTextManager)provider.GetService(typeof(SVsTextManager)); IComponentModel componentModel = (IComponentModel)provider.GetService(typeof(SComponentModel)); EditorAdapters = componentModel .GetService <IVsEditorAdaptersFactoryService>(); ActiveThemeChanged += ActiveTheme_Changed; }
private void InitializeDTE() { IVsShell shellService; this.textManager = (IVsTextManager)GetService(typeof(SVsTextManager)); this.textManager = (IVsTextManager)GetService(typeof(SVsTextManager)); this.dte2 = this.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)) as EnvDTE80.DTE2; if (componentModel == null) { componentModel = (IComponentModel)GetService(typeof(SComponentModel)); } if (this.dte2 == null) // The IDE is not yet fully initialized { shellService = GetService(typeof(SVsShell)) as IVsShell; this.dteInitializer = new DteInitializer(shellService, this.InitializeDTE); } else { this.dteInitializer = null; } }
public MyExtension(DTE dte, IVsTextManager txtMngr) { this.txtMngr = txtMngr; this.dte = dte; commandEvents = dte.Events.CommandEvents; commandEvents.BeforeExecute += commandEvents_BeforeExecute; }
internal static void NavigateTo(string view, Guid docViewGuidType, int line, int col) { IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager)); var model = Instance.GetService(typeof(SComponentModel)) as IComponentModel; var adapter = model.GetService <IVsEditorAdaptersFactoryService>(); IVsTextView viewAdapter; IVsUIShellOpenDocument uiShellOpenDocument = Instance.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IVsUIHierarchy hierarchy; uint itemid; IVsWindowFrame pWindowFrame; VsShellUtilities.OpenDocument( Instance, view, Guid.Empty, out hierarchy, out itemid, out pWindowFrame, out viewAdapter); ErrorHandler.ThrowOnFailure(pWindowFrame.Show()); // Set the cursor at the beginning of the declaration. ErrorHandler.ThrowOnFailure(viewAdapter.SetCaretPos(line, col)); // Make sure that the text is visible. viewAdapter.CenterLines(line, 1); /*TextSpan visibleSpan = new TextSpan(); * visibleSpan.iStartLine = line; * visibleSpan.iStartIndex = col; * visibleSpan.iEndLine = line; * visibleSpan.iEndIndex = col + 1;*/ //ErrorHandler.ThrowOnFailure(viewAdapter.EnsureSpanVisible(visibleSpan)); }
public ActiveTextViewProvider( IVsTextManager textManager, IVsEditorAdaptersFactoryService editorAdapterFactory) { _textManager = textManager ?? throw new System.ArgumentNullException(nameof(textManager)); _editorAdapterFactory = editorAdapterFactory ?? throw new System.ArgumentNullException(nameof(editorAdapterFactory)); }
internal static async Task <SyntaxNode> GetSelectedSyntaxNode(IVsTextManager textManager) { int startPosition, endPosition; string filePath; if (textManager.TryFindDocumentAndPosition(out filePath, out startPosition, out endPosition)) { Document document; try { document = WorkspaceHelpers.GetDocument(filePath); } catch (NullReferenceException ex) { StatusBar.ShowStatus($"Error accessing the document. Try building the solution."); return(null); } var root = await document.GetSyntaxRootAsync(); var element = root.FindNode(new Microsoft.CodeAnalysis.Text.TextSpan(startPosition, endPosition - startPosition)); return(element); } else { StatusBar.ShowStatus("To use generator preview, please navigate to C# code."); return(null); } }
public ThemeOptionsControl(IThemeAwareDialog child) { InitializeComponent(); Child = child; var control = child as Control; Debug.Assert(Child != null); Debug.Assert(control != null); tableContent.Controls.Add(control); tableContent.SetColumn(control, 0); tableContent.SetRow(control, 1); control.Dock = DockStyle.Fill; var provider = ServiceProvider.GlobalProvider; Service = provider.GetService(typeof(SIndentGuide)) as IndentGuideService; Child.Service = (IIndentGuide)Service; TextManagerService = (IVsTextManager)provider.GetService(typeof(SVsTextManager)); var componentModel = (IComponentModel)provider.GetService(typeof(SComponentModel)); EditorAdapters = (IVsEditorAdaptersFactoryService)componentModel .GetService<IVsEditorAdaptersFactoryService>(); ActiveThemeChanged += ActiveTheme_Changed; }
public static bool GetActiveDocumentCursorScreenPos(out System.Windows.Point oPoint, bool bNextLine) { IVsTextManager oTextMgr = (IVsTextManager)((IServiceProvider)Common.Instance.Package).GetService(typeof(SVsTextManager)); if (oTextMgr != null) { IVsTextView oTextViewCurrent; oTextMgr.GetActiveView(1, null, out oTextViewCurrent); int iLine, iCol; oTextViewCurrent.GetCaretPos(out iLine, out iCol); if (bNextLine) { ++iLine; } Microsoft.VisualStudio.OLE.Interop.POINT[] pts = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; oTextViewCurrent.GetPointOfLineColumn(iLine, iCol, pts); RECT oViewRect = new RECT(); GetWindowRect(oTextViewCurrent.GetWindowHandle(), ref oViewRect); oPoint = new System.Windows.Point(oViewRect.Left + pts[0].x, oViewRect.Top + pts[0].y); return(true); } oPoint = new System.Windows.Point(); return(false); }
/// <summary> /// Creates a document provider. /// </summary> /// <param name="projectContainer">Project container for the documents.</param> /// <param name="serviceProvider">Service provider</param> /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param> public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, VisualStudioDocumentTrackingService documentTrackingService) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this._documentTrackingServiceOpt = documentTrackingService; this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this._editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>(); this._contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site) { this.site = new ServiceProvider(site); // register our independent view with the IVsTextManager so that it knows // the user is working with a view over the text buffer. this will trigger // the text buffer to prompt the user whether to reload the file if it is // edited outside of the development Environment. IVsTextManager textManager = (IVsTextManager)this.site.QueryService(VsConstants.SID_SVsTextManager, typeof(IVsTextManager)); if (textManager != null) { IVsWindowPane windowPane = (IVsWindowPane)this; textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer); } //register with ComponentManager for Idle processing this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager)); if (componentID == 0) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime | (uint)OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal | (uint)OLECADVF.olecadvfRedrawOff | (uint)OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; this.componentManager.FRegisterComponent(this, crinfo, out this.componentID); } return(0); }
/// <summary> /// Creates a document provider. /// </summary> /// <param name="serviceProvider">Service provider</param> /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param> public DocumentProvider( VisualStudioProjectTracker projectTracker, IServiceProvider serviceProvider, VisualStudioDocumentTrackingService documentTrackingService) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectTracker = projectTracker; this._documentTrackingServiceOpt = documentTrackingService; this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this._editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); this._contentTypeRegistryService = componentModel.GetService <IContentTypeRegistryService>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
public LintErrorProvider(IServiceProvider serviceProvider) : base(serviceProvider) { ServiceProvider = serviceProvider; Environment = ServiceProvider.GetService <DTE, DTE2>(); TextManager = ServiceProvider.GetService <VsTextManagerClass, IVsTextManager>(); }
/// <summary> /// Initializes a new instance of the <see cref="JSLintErrorListProvider"/> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> public JSLintErrorListProvider(IServiceProvider serviceProvider) : base(serviceProvider) { this.serviceProvider = serviceProvider; this.environment = this.serviceProvider.GetService<DTE, DTE2>(); this.textManager = this.serviceProvider.GetService<VsTextManagerClass, IVsTextManager>(); }
public TextManagerPropertiesProvider(IVsTextManager textManager, IVsEditorAdaptersFactoryService editorAdaptersFactory) { _textManagerLazy = new Lazy <IVsTextManager>(() => textManager); _editorAdapersFactoryLazy = new Lazy <IVsEditorAdaptersFactoryService>(() => editorAdaptersFactory); _textViewLazy = new Lazy <IVsTextView>(GetActiveView); _snapshotPointLazy = new Lazy <SnapshotPoint>(GetSnaphotPoint); }
public BookmarksController(IDialControllerHost host, IVsTextManager textManager) : base(host, textManager) { _host = host; _commands = host.DTE.Commands; _events = host.DTE.Events.WindowEvents; _events.WindowActivated += WindowActivated; }
static public IWpfTextViewHost GetViewHost(this IVsTextManager txtMgr) { object holder; Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; txtMgr.GetUserData().GetData(ref guidViewHost, out holder); return((IWpfTextViewHost)holder); }
/// <summary> /// Initializes a new instance of the <see cref="JSLintErrorListProvider"/> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> public JSLintErrorListProvider(IServiceProvider serviceProvider) : base(serviceProvider) { this.serviceProvider = serviceProvider; this.environment = this.serviceProvider.GetService <DTE, DTE2>(); this.textManager = this.serviceProvider.GetService <VsTextManagerClass, IVsTextManager>(); }
/// <summary>Gets the native text view from the currently active document.</summary> public async Task <IVsTextView> GetCurrentNativeTextViewAsync() { IVsTextManager textManager = await VS.GetRequiredServiceAsync <SVsTextManager, IVsTextManager>(); ErrorHandler.ThrowOnFailure(textManager.GetActiveView(1, null, out IVsTextView activeView)); return(activeView); }
private DuplicateLineCommand(IVsTextManager vsTextManager) : base((sender, args) => DuplicateLine(vsTextManager), new CommandID(PackageGuids.guidVSXpandPackageCmdSet, PackageIds.cmdidDouplicateLine)) { var dteCommand = Options.OptionClass.Instance.DteCommands.FirstOrDefault(command => command.Command == GetType().Name); BindCommand(dteCommand); this.EnableForActiveFile(); }
internal TextManager( IVsAdapter adapter, SVsServiceProvider serviceProvider) { _adapter = adapter; _serviceProvider = serviceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _table = new RunningDocumentTable(_serviceProvider); }
public TextManagerEventAdapter(IVsTextManager textManager) { if (textManager == null) throw new ArgumentNullException("textManager"); var cpContainer = textManager as IConnectionPointContainer; Guid riid = typeof(IVsTextManagerEvents).GUID; cpContainer.FindConnectionPoint(ref riid, out _connectionPoint); _connectionPoint.Advise(this, out _connectionCookie); }
public SaveEventsService( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, ICommandHandlerServiceFactory commandHandlerServiceFactory, SVsServiceProvider serviceProvider) { _editorAdaptersFactoryService = editorAdaptersFactoryService; _commandHandlerServiceFactory = commandHandlerServiceFactory; _runningDocumentTable = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); }
internal VsVimHost( ITextBufferUndoManagerProvider undoManagerProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, SVsServiceProvider serviceProvider) { _undoManagerProvider = undoManagerProvider; _editorAdaptersFactoryService = editorAdaptersFactoryService; _dte = (_DTE)serviceProvider.GetService(typeof(_DTE)); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); }
internal VsAdapter( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, SVsServiceProvider serviceProvider) { _editorAdaptersFactoryService = editorAdaptersFactoryService; _editorOptionsFactoryService = editorOptionsFactoryService; _serviceProvider = serviceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _table = new RunningDocumentTable(_serviceProvider); _uiShell = _serviceProvider.GetService<SVsUIShell, IVsUIShell>(); }
internal TextManager( IVsAdapter adapter, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferFactoryService textBufferFactoryService, SVsServiceProvider serviceProvider) { _vsAdapter = adapter; _serviceProvider = serviceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _textDocumentFactoryService = textDocumentFactoryService; _textBufferFactoryService = textBufferFactoryService; _table = new RunningDocumentTable(_serviceProvider); }
public TextInformationManager(IServiceProvider serviceProvider, IComponentModel componentModel) { this.serviceProvider = serviceProvider; this.componentModel = componentModel; fontAndColorStorage = (IVsFontAndColorStorage) serviceProvider.GetService(typeof (SVsFontAndColorStorage)); fontAndColorUtilities = fontAndColorStorage as IVsFontAndColorUtilities; fontAndColorCache = (IVsFontAndColorCacheManager)serviceProvider.GetService(typeof(SVsFontAndColorCacheManager)); textManager = (IVsTextManager) serviceProvider.GetService(typeof (SVsTextManager)); editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>(); textStructureNavigatorSelectorService = componentModel.GetService<ITextStructureNavigatorSelectorService>(); classicationFormatMapService = componentModel.GetService<IClassificationFormatMapService>(); classificationAggregatorService = componentModel.GetService<IClassifierAggregatorService>(); }
public WindowWatcher(DTE2 application) { if (application == null) throw new ArgumentNullException("application"); _application = application; _textViews = new Dictionary<IVsTextView, TextView>(); _textManager = GetTextManager(application); _textManagerEvents = new TextManagerEventAdapter(_textManager); _textManagerEvents.ViewRegistered += new EventHandler<ViewRegistrationEventArgs>(ViewRegisteredHandler); _textManagerEvents.ViewUnregistered += new EventHandler<ViewRegistrationEventArgs>(ViewUnregisteredHandler); }
internal TextManager( IVsAdapter adapter, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferFactoryService textBufferFactoryService, ISharedService sharedService, SVsServiceProvider serviceProvider) { _vsAdapter = adapter; _serviceProvider = serviceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _textDocumentFactoryService = textDocumentFactoryService; _textBufferFactoryService = textBufferFactoryService; _runningDocumentTable = _serviceProvider.GetService<SVsRunningDocumentTable, IVsRunningDocumentTable>(); _sharedService = sharedService; }
internal VsAdapter( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, IIncrementalSearchFactoryService incrementalSearchFactoryService, SVsServiceProvider serviceProvider) { _incrementalSearchFactoryService = incrementalSearchFactoryService; _editorAdaptersFactoryService = editorAdaptersFactoryService; _editorOptionsFactoryService = editorOptionsFactoryService; _serviceProvider = serviceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _table = new RunningDocumentTable(_serviceProvider); _uiShell = _serviceProvider.GetService<SVsUIShell, IVsUIShell>(); _monitorSelection = _serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>(); }
internal VsAdapter( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, IIncrementalSearchFactoryService incrementalSearchFactoryService, IPowerToolsUtil powerToolsUtil, SVsServiceProvider vsServiceProvider) { _incrementalSearchFactoryService = incrementalSearchFactoryService; _editorAdaptersFactoryService = editorAdaptersFactoryService; _editorOptionsFactoryService = editorOptionsFactoryService; _serviceProvider = vsServiceProvider; _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>(); _table = new RunningDocumentTable(_serviceProvider); _uiShell = _serviceProvider.GetService<SVsUIShell, IVsUIShell>(); _monitorSelection = _serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>(); _powerToolsUtil = powerToolsUtil; _visualStudioVersion = vsServiceProvider.GetVisualStudioVersion(); }
public MiscellaneousFilesWorkspace( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IMetadataAsSourceFileService fileTrackingMetadataAsSourceService, SaveEventsService saveEventsService, VisualStudioWorkspace visualStudioWorkspace, SVsServiceProvider serviceProvider) : base(visualStudioWorkspace.Services.HostServices, WorkspaceKind.MiscellaneousFiles) { _editorAdaptersFactoryService = editorAdaptersFactoryService; _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService; _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie); _metadataReferences = ImmutableArray.CreateRange(CreateMetadataReferences()); _documentProvider = new RoslynDocumentProvider(this, serviceProvider); saveEventsService.StartSendingSaveEvents(); }
/// <summary> /// Gets the active IWpfTextView, if one exists. /// </summary> /// <returns>The active IWpfTextView, or null if no such IWpfTextView exists.</returns> private static IWpfTextView GetActiveTextView(IVsTextManager textManager) { IWpfTextView view = null; IVsTextView vTextView = null; textManager.GetActiveView( fMustHaveFocus: 1 , pBuffer: null , ppView: out vTextView); IVsUserData userData = vTextView as IVsUserData; if (null != userData) { IWpfTextViewHost viewHost; object holder; Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; userData.GetData(ref guidViewHost, out holder); viewHost = (IWpfTextViewHost)holder; view = viewHost.TextView; } return view; }
/// <summary> /// Obtains caret position and file name associated with /// current selection in the editor (supplied via textManager) /// </summary> /// <param name="textManager">Instance of IVsTextManager taken from the Package</param> public static bool TryFindDocumentAndPosition(IVsTextManager textManager, out string filePath, out int selectionStart, out int selectionEnd) { IWpfTextView view = GetActiveTextView(textManager); if (view == null) { // We couldn't get the ITextDocument filePath = null; selectionStart = -1; selectionEnd = -1; return false; } ITextBuffer sourceBuffer = view.TextBuffer; selectionStart = view.Selection.Start.Position.Position; selectionEnd = view.Selection.End.Position.Position; //caretPosition = view.Caret.Position.BufferPosition; //Check if this is an elision buffer //If so, we need to take a look at the actual source buffer var elisionBuffer = sourceBuffer as IElisionBuffer; if (elisionBuffer != null) { //sourceBuffer = elisionBuffer.SourceBuffer; //caretPosition = elisionBuffer.CurrentSnapshot.MapToSourceSnapshot(caretPosition); } // See what file are we in var textDocument = (ITextDocument)sourceBuffer.Properties.GetProperty(typeof(ITextDocument)); // Pass the path and position back to RoslynModule filePath = textDocument.FilePath; if (filePath == "Temp.txt") { return false; } return true; }
/// <summary> /// Gets the language preferences. /// </summary> public LanguagePreferences(ServiceProvider site, Guid langSvc, string editorName) { this.site = site; this.textMgr = (IVsTextManager)site.QueryService(VsConstants.SID_SVsTextManager, typeof(IVsTextManager)); this.langSvc = langSvc; this.user = true; this.editorName = editorName; Init(); }
public FieldConverter(IVsTextManager txtMgr) { this.txtMgr = txtMgr; }
internal void Init( _DTE dte, IVsTextManager textManager) { _dte = dte; _textManager = textManager; }
public AutoPropertyConverter(IVsTextManager txtMgr) { this.txtMgr = txtMgr; }
internal void OnServiceProvider(Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp) { Init(sp.GetService<SDTE, EnvDTE.DTE>(), _textManager = sp.GetService<SVsTextManager, IVsTextManager>()); }
public TextBufferEventListener(IComponentModel compModel, IVsTextLines textLines, IVsTextManager textMgr, IVsCodeWindow window) { _textLines = textLines; _compModel = compModel; _textMgr = textMgr; _window = window; var cpc = textLines as IConnectionPointContainer; var bufferEventsGuid = typeof(IVsTextBufferDataEvents).GUID; cpc.FindConnectionPoint(ref bufferEventsGuid, out _cp); _cp.Advise(this, out _cookie); }
private void init() { DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE; manager = Package.GetGlobalService(typeof(SVsTextManager)) as IVsTextManager; this.MouseMove += new EventHandler<MouseEventArgs>(GestureNativeWindow_MouseMove); this.MouseUp += new EventHandler<CancelableMouseEventArgs>(GestureNativeWindow_MouseUp); this.MouseDown += new EventHandler<CancelableMouseEventArgs>(GestureNativeWindow_MouseDown); }
public virtual void Dispose() { textMgr = null; site = null; }
public DocumentFormatter(IVsTextManager txtMngr, DTE dte) { this.txtMngr = txtMngr; this.dte = dte; }
/// <summary> /// Gets the language preferences. /// </summary> public LanguagePreferences(IServiceProvider site, Guid langSvc, string editorName) { this.site = site; this.textMgr = (IVsTextManager)site.GetService(typeof(SVsTextManager)); this.langSvc = langSvc; this.user = true; this.editorName = editorName; Init(); }