PowerShellEditorServices
PowerShellEditorServices copied to clipboard
Add document symbols for #region
PR Summary
Adds symbols for region-start, ex. #region abc123, to outline and symbol search.
Note This doesn't check if the region is actually closed as we don't care about the full range since a region can technically start/stop in the middle of a scriptblock.

PR Context
Fix PowerShell/vscode-powershell#3604
Waiting for #1886 as I'd rather get merge conflicts here 🙂
Heh, ok @fflaten things are so cleaned up now I think you can do this again (much more easily!)
Rewrote to use ReferenceTable for caching, but still a WIP. @andschwa: Does it make sense to use ReferenceTable here? It'll make it available for handlers incl. find all references. And it isn't something we'd need to track in the workspace.
Todo:
- [x] Test with full scriptrange (track endregion)
- How does outline behave when endregion occurs in the middle of a function/class etc?
- [x] Validate regex behavior against PowerShell ISE
- [ ] ~~Move out of ReferenceTable?~~
- [x] Ignore symbol in scenarios like highlight and hover?
Does it make sense to use ReferenceTable here?
I'd keep using it, it'll make everything easier. We can add "region" as a symbol type and just exclude them where appropriate.
Does it make sense to use ReferenceTable here?
I'd keep using it, it'll make everything easier. We can add "region" as a symbol type and just exclude them where appropriate.
Hm I see what you mean now, since it's not done via AST but simply RegEx, and is only useful for the current document...I'll ponder, I'm sure there's a good way to handle that.
[x] Test with full scriptrange (track endregion)
- How does outline behave when endregion occurs in the middle of a function/class etc?
It didn't break as I feared, but only wraps symbols with both start and end position inside. Ex.

Updated to include it and returning only regions with matching end just like folding. I've disabled hover, highlight (on click) and reference scanning.
Hopefully we'll get some feedback if it becomes too noisy in go to symbol or the outline-nesting. Breadcrumbs require the latter to work, so hopefully worth it.
Does it make sense to use ReferenceTable here?
I'd keep using it, it'll make everything easier. We can add "region" as a symbol type and just exclude them where appropriate.
I was wrong here 😆
Closing since I integrated this, thanks again so much for your work!