How to: Support the Collapse to Definitions Command

The Collapse to Definitions command is used to automatically collapse language constructs. To locate the Collapse to Definitions command, on the Edit menu, point to Outlining. The language constructs that the command affects vary according to the development language. For more information, see How to: Outline and Hide Code.

The following demonstrates how to support this command for your language service.

To support the Collapse to Definitions command

  1. Implement IVsOutliningCapableLanguage on your language service object.

  2. Call AddOutlineRegions on the current outlining session object to add new outline regions.

Robust Programming

When a user selects Collapse To Definitions on the Outlining menu, the IDE calls CollapseToDefinitions on your language service.

When this method is called, the IDE passes in an IVsTextLines pointer and a pointer to the current outlining session. An IVsTextLines pointer is a pointer to the text buffer. An IVsOutliningSession object is a pointer to the current outlining session.

Use the pointer to IVsTextLines to specify the text to collapse based on the contents of the buffer and the outlining rules of your language. You can call the AddOutlineRegions method one time for multiple outline regions by specifying these regions in the rgOutlnReg parameter. The rgOutlnReg parameter is a NewOutlineRegion structure. This process lets you to specify whether a particular region is expanded or collapsed.

注意

Be careful about hiding new-line characters. You typically want to hide from the start of the first line to the last character of the last line in a section, leaving the final new-line character visible.

See Also

Concepts

How to: Provide Hidden Text Support

How to: Provide Expanded Outlining Support