Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access current code pane in Visual Studio Extension

Im writing a visual studio (2010) extension with a right click menu whilst in a code view. I want to be able to examine the current code from my menu item event handler but havent been able to find somewhere in the object model to do this.

How do i access the code in the current window in a visual studio extension?

EDIT

Heres the code i used to get the current document text

 DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE ;
 TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;

 var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);
like image 790
Not loved Avatar asked Jan 28 '12 00:01

Not loved


People also ask

How do I view code in Visual Studio?

You can open code into Visual Studio in the following ways: On the Visual Studio menu bar, choose File > Open > Folder, and then browse to the code location. On the context (right-click) menu of a folder containing code, choose the Open in Visual Studio command.

How do I see installed extensions in VS Code?

Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.

How do I access extensions in Visual Studio?

To open the Manage Extensions dialog, choose Extensions > Manage Extensions. Or, type Extensions in the search box and choose Manage Extensions. The pane on the left categorizes extensions by those that are installed, those available on Visual Studio Marketplace (Online), and those that have updates available.

Where is the status bar in VS Code?

The Status Bar sits at the bottom of the VS Code workbench and displays information and actions that relate to your workspace. Items are placed into two groups: Primary (left) and Secondary (right).


1 Answers

You may be looking for

Document doc = DTE.ActiveDocument;
TextDocument txt = doc.Object() as TextDocument;

You should then be able to edit work with the TextDocument as needed.

like image 75
Mark Smith Avatar answered Sep 20 '22 16:09

Mark Smith