I got nerd-sniped. A Rubberduck user put up a feature request on the project’s repository, and I thought “we need this, yesterday”… so I did it, and the result crushed all the expectations I had – the prerelease build is here!
There are a few quirks – but rule of thumb, it’s fairly stable and works pretty well. Did you see it in action?
This feature rather impressively enhances the coding experience in the VBE – be it only with how it honors your Rubberduck/Smart Indenter settings to literally auto-indent code blocks as you type them.
Writing auto-completing VBA code, especially with auto-completing double quotes and parentheses, gives an entirely fresh new feel to the good old VBE… I’m sure you’re going to love it.
And in case you don’t, you could always cherry-pick which auto-completions you want to use, and which ones you want to disable:
These work with the current line (regardless of whether you’re typing code or a comment, or whether you’re inside a string literal), by automatically inserting a “closing” token as soon as you type an “opening” token – and immediately puts the caret between the two. These include (pipe character
| depicts caret position):
- String literals:
- Square brackets:
- Curly braces:
These work with the previous line, immediately after committing it: on top of the previous line’s indentation, a standard indent width (per indenter settings) is automatically added, and the caret is positioned exactly where you want it to be. These include (for now):
Select Case...End Select
On top of these standard blocks,
On Error Resume Next automatically completes to
...On Error GoTo 0.
Quirks & Edge Cases
It’s possible that parenthesis completion interferes with e.g.
Sub() statements (an additional opening parenthesis is sometimes added). This has been experienced and reproduced, but not consistently. If you use the feature and can reliably reproduce this glitch, please open an issue and share the repro steps with us!
On Error Resume Next will indent its body, but there currently isn’t any indenter setting for this: we need to add an indenter option to allow configuring whether this “block” should be indented or not.
Deleting or back-spacing auto-completed code may trigger the auto-complete again, once.
Line numbers are ignored, and an opening token found on the last line of a line-continuated comment will trigger a block auto-complete.
Lastly, care was taken to avoid completing already-completed blocks, however if you try hard enough to break it, you’ll be able to generate non-compilable code. Auto-completion cannot leverage the parser and only has a very limited string view of the current/committed line of code. The nice flipside of this limitation, is very nice performance and no delays in your typing.
None of these issues outweight the awesomeness of it, so all auto-completions are enabled by default.
4 thoughts on “Autocomplete Enhancements”
[…] few months ago I merrily announced the first Rubberduck feature that actively interfered with typing code in the VBE. It wasn’t […]
Is the Block Completion is supposed to be working now in version 184.108.40.20614? I just got the chance to read about it again and tried it but it didn’t work.
Hey Darren – the original block AC implementation was too buggy and got removed, pending a rewrite that has yet to happen – it’s next on my todo list though, just after pushing the fixes for the few annoying sef-closing pair bugs remaining.
LikeLiked by 1 person
Excited to see that “magic” vested back to Rubberduck. 🙂