A few months ago I wrote about how I envisioned dealing with module and member attributes in the 2.1 cycle:
Annotation/Attributes: fixing these inspection, and the quick-fix that synchronizes annotations with module attributes and vice-versa, will finally expose VB module and member attributes to VBA code panes, using Rubberduck’s annotation syntax.
The idea was to use “magic comments” to annotate a module or a procedure with, for example, this:
'@Description("Does something.") Public Sub DoSomething() End Sub
And then since we know there’s a
DescriptionAnnotation here for
DoSomething, and we also know that there’s no
VB_Description attribute for that member because of how we parse VBA code… then we’d issue an inspection result saying “annotations and attributes aren’t synchronized”, and you’d run a quickfix and there you have it, a comment that inserts invisible code.
And, it “works”. But there’s a showstopper here: the VBE itself.
You see the code that’s in the editor is not all the code that’s actually in that file: the VBE is hiding the attributes. So the line positions we get from the VBIDE API aren’t the line positions we’d get from reading the complete code… and this complicates things… rather massively.
We have one parse pass on the exported code to pick up these attributes. Then one parser pass on the in-editor code to build our knowledge of the code as the user sees it.
So we have two
ModuleRewriter, each working independently on their own version of the same code. And when the code pane rewriter… rewrites, we run into an annoying VBE quirk I [annoyingly] had already experienced before:
I think that’s a VBE quirk – editing the signature of the method, whether manually or with Rubberduck, tends to obliterate the VB_Attributes (and the shortcut key is a VB_Attribute). — ThunderFrame
We need a “code pane pass” to avoid mangling the code with offset line positions, because the VBE is hiding the attributes.
What’s so important about these attributes anyway? Why bother?
Our resolver needs the critical metadata that’s hidden there. Without them, knowing the actual scope of a declaration is impossible. Nowhere else can we pick up a hint about a
VB_PredeclaredId attribute, or
VB_Exposed. Besides, Rubberduck knowing about
VB_Description attributes has very interesting implications, UX-wise. Even better once we handle line breaks:
Of course there’s a solution. We’ve been chatting about this solution for a long time now. There won’t be subclassed code panes. The VBE is literally fighting with everything it’s got, to keep its scrollbars in place and visible – it’s a better idea to pick one’s battles and drop that idea. So instead we’re going to abuse docked toolwindows and put our entire UI in a single such toolwindow – and that includes the current toolwindows/panels, …as well as the code panes client area.
Once we have our very own code pane user control, what happens in it is under our complete supervision, and we’re free to intervene at any point in the process of code being modified, in any conceivable way.
So the idea would be to bring the attributes themselves into the code panes (optionally hidden), and shave off an entire parser pass just like that. This pretty much makes the whole annotation+inspection+quickfix combo rather useless.
So instead of pursuing a lost cause, I’ve decided to drop my work on getting attributes to synchronize with annotations, and get on with the other 2.1 cycle targets: the attributes problem will just solve itself when we get there.
In the meantime I’d recommend to disable the
MissingAttribute inspections. Not that the inspections themselves are harmful, but the
SynchronizeModuleAttributes quickfix is: that quickfix is being decommissioned.