Visual Studio中的折叠区域
本文关键字:折叠 区域 Studio Visual | 更新日期: 2023-09-27 18:21:25
我正在做一个Visual Studio扩展,它包含编辑器边距,它显示每个代码行的注释和按行号链接的数据。
当我的代码有折叠的区域(函数、代码块或区域)时,我会得到不正确的行号。
如何计算哪些线条塌陷?或者更简单地说,如何展开所有折叠的块并禁用折叠按钮?
我找到了解决方案:
Dim _outliningManager As Outlining.IOutliningManager
Dim _oldCollapsedRegions As List(Of ICollapsed)
'Getting access to ServiceProvider
<Import>
Dim ServiceProvider As SVsServiceProvider
'Getting IOutliningManagerService object
Dim componentModel As IComponentModel = ServiceProvider.GetService(GetType(SComponentModel))
Dim outliningManagerService As IOutliningManagerService = componentModel.GetService(Of IOutliningManagerService)()
'Creating IOutliningManager for current textView
If outliningManagerService IsNot Nothing Then
_outliningManager = outliningManagerService.GetOutliningManager(textView)
If _outliningManager IsNot Nothing Then AddHandler _outliningManager.RegionsCollapsed, AddressOf RegionCollapsed
End If
'Getting all regions and expand them
If _outliningManager IsNot Nothing Then
Dim snapshot = _textView.TextSnapshot
Dim snapshotSpan = New Microsoft.VisualStudio.Text.SnapshotSpan(snapshot, New Microsoft.VisualStudio.Text.Span(0, snapshot.Length))
_oldCollapsedRegions = _outliningManager.GetCollapsedRegions(snapshotSpan).ToList()
For Each reg In _oldCollapsedRegions
_outliningManager.Expand(reg)
Next
End If
'Blocking regions collapsed
Sub RegionCollapsed(sender As Object, e As RegionsCollapsedEventArgs)
If Me.Visibility = Windows.Visibility.Visible Then
For Each reg In e.CollapsedRegions
_outliningManager.Expand(reg)
Next
End If
End Sub
需要引用:microsoft.visionstudio.shell.invariable.10.0、microsoft.visualstudio.ComponentModelHost,当然还有microsoft.visualstudio.Text