FrankS
FrankS

Reputation: 1

Programmatically collapse source code blocks from a Visual Studio extension

I've written a VS extension which modifies C# source files. The extension applies changes to the source code file which is currently open and visible in the IDE. One aspect of the extension is to insert #region and #endregion directives surrounding the inserted source lines. What I'd like to do from the extension is collapse that region of code in the visible editor window.

I've been searching around for days, and can't find any previous examples of how this can be done.

Any guidance would be greatly appreciated.

Upvotes: 0

Views: 45

Answers (1)

Sergey Vlasov
Sergey Vlasov

Reputation: 27890

You can import Microsoft.VisualStudio.Text.Outlining.IOutliningManagerService, call GetOutliningManager and then use TryCollapse.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.outlining.ioutliningmanager.trycollapse?view=visualstudiosdk-2022

Upvotes: 0

Related Questions