rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Bracket matcher/finder and auto-completion #4033

Closed LukeHSC closed 6 years ago

LukeHSC commented 6 years ago

hi,
a bracket matcher/ finder and auto-completion would be great.

bracket matcher

auto-completion

retailcoder commented 6 years ago

💯 Agreed, would be awesome.

However the VBIDE API exposes exactly zero code pane events, so autocompletion needs to be implemented in (or more precisely invoked by) the VBENativeServices.VbeEventCallback method.

This has been on the roadmap since forever 😄

We need to think of a neat API that makes it easy to use the same "hook" to later implement similar/related features, i.e. "insert [this code] when [this token] is typed in the editor". I can see a matching closing brace automatically inserted relatively easily - whether it's a (, a {, or a [.

Highlighting brackets, or anything involving how code is rendered in the VBE, is out of the question though... for now. Ultimately we will be replacing the entire code pane client area with our own editor, and then sky's pretty much the limit... as long as the VBE isn't in break mode, but that's another discussion!

I think we can implement the hooks without having to wait for our own code panes.

Thanks for the feedback!

LukeHSC commented 6 years ago

that would be great, at least find matching brace … even better find matching IF / ENDIF and FOR/ENDFOR !

retailcoder commented 6 years ago

So, uh, I totally got nerd-sniped, and got something like a skeleton of an autocompletion feature. needs refactoring and polishing and then a settings UI to enable/disable them, but anyway at this point I have ( autocompleting to (), " autocompleting to "", then [ to ] and { to }, and If True Then\n autocompleting the End If on the next line (unindented), so... I need some sleep :octocat:

retailcoder commented 6 years ago

PR under way, watch for a pre-release build when it gets merged!

retailcoder commented 6 years ago

@LukeHSC merged! let me know what you think! 😃

LukeHSC commented 6 years ago

Hi Mathieu

Sorry for being daft …

I loaded “v2.2.0.3347-pre” which uninstalled my older version, which is fine

I don’t see where on the new version the ‘bracket matching ’ is ?

Regards, Luke

LukeHSC commented 6 years ago

sorry found it … by accident when I typed a ‘(‘ it auto closed it with ‘)’. Nice!

As a suggestion on the RD toobar, how about having a global turn ON/OFF button for Autocomplete?. I found that it was not easy to delete one of the ‘(‘ without it not deleting and forcing the ‘)’ again. So I left the ‘()’ and cut and pasted the code in between that. That may be a good thing long term tho.

Regards, Luke

retailcoder commented 6 years ago

@LukeHSC I like the idea of a toggle on the toolbar (although, that toolbar is getting rather wide by now), however do note that backspacing/deleting is currently broken and only effectively works when the left-most character is removed - I'm giving up on trying to devise a fix using the current VBE messenging hook; I'll swap the hooking for an actual keyhook tonight, that way I can know what key was pressed, and reliably fire when a key is actually pressed, instead of filtering caret messages. Autocompletion will definitely work exactly as intended by v2.3 "green" release!

LukeHSC commented 6 years ago

PS: would be nice to have a ‘matching bracket ’ finder (and IF/END etc finder) !

LukeHSC commented 6 years ago

super.

BTW my RD toolbar only has ‘Refresh’ on it ?

BTW2 – love the toolbar when I am on a function and tells me where in the overall VBA it is being used .

And … sorry a bit of a hate … the Code Explorer on my projects takes about 1.5 to 4 mins to refresh, have to do everytime I open the project as I noted before. I wouldn’t think my dinky code is that complex (?) . I have about 12 forms (each form may have between 5 to 10 cmd’s) , about 24 modules and a maybe a couple classes. I do appreciate that it must take a lot of parsing to sort it all tho.

retailcoder commented 6 years ago

Would be nice indeed, but we won't have that in the VBE's native code panes, for several reasons:

Once we get to hijack the code panes themselves with our own WPF/AvalonEdit editor, we'll definitely look into implementing this. I have something like ReSharper's tooling in mind.

As for parser/resolver performance, it depends on a lot of things. Feel free to open a new issue and include the complete log for the initial parse of that project (initial parse takes the longest).

retailcoder commented 6 years ago

@LukeHSC note, we've just identified a bug that may cause the resolver to basically fail to resolve everything defined in a referenced library - if that's the case then MANY exceptions would be thrown (and logged), and this could very well make the whole parsing/resolving much slower than normal (and inspections might be raising a bunch of false positives too, so firing many more results than they normally would -> more peformance & memory pressure)... does pre-release 2.2.3310 perform better by any chance?

LukeHSC commented 6 years ago

Hi Mathieu

I am running as of last night

Version 2.2.6730.21818

OS: Microsoft Windows NT 10.0.14393.0, x64

Host Product: Microsoft Office 2016 x86

Host Version: 16.0.9330.2087

Host Executable: MSACCESS.EXE

I am a bit confused with the GitHub version nums as I had downloaded and installed “Rubberduck.Setup.2.2.0.3347-pre.exe”

I would say the refresh is about the same? I just reopened my ACCDB and did a refresh on the Code Explorer, takes 1.5 mins

retailcoder commented 6 years ago

Yeah there's a known issue about the "about" box showing the version# from the wrong assembly, following the split of Rubberduck.Main and Rubberduck.Core; the correct/intended version is only shown on the splash form at startup.

If you're referencing libraries that you're not using, removing them could help with performance a bit. Otherwise, watching logs for exceptions can indicate problems. Note that only the initial parse should take a while, subsequent parses only process what needs to be processed, so you can make the best use of caching by refreshing whenever you've changed anything in a module - other modules wouldn't be affected. Global variables and other identifiers referenced in modules outside where they're declared also invalidate caching of all involved modules when they're changed.

LukeHSC commented 6 years ago

hi Mathieu

Been working coding this AM with the autocomplete on, for most part seems ok, few glitches , i.e. re-autocompleting brackets if I go to edit them or backspace over them.

Biggest issue just now, I went to copy and paste a variable after a ‘[‘ bracket and RD made this:

I sent to turn off the autocomplete for RD but it does not want to turn off? I sent to Settings, unticked the ‘Close Square Brackets’ pressed Ok. But still autocompletes square brackets. I went back to settings and it is turned back on? Same thing with the ‘(‘ ; when I got the ‘[‘ all fixed up then the ‘(‘ repeated too much and not able to turn that off in RD settings either.

Tried several times on the Settings and now it is saving the setup (no autocomplete for ‘(‘ or ‘[‘ while I fixed up the issue in the screenshot above)

Regards, Luke

LukeHSC commented 6 years ago

PS:

I seem to have broken RD completely. Tried to go to Settings (to turn off autocomplete) but it keeps crashing each time:

Tried 4 times, same. Am removing this version and going back to previos , will wait on the stable release of autocomplete

Regards,

Luke

From: Luke A Burlet Luke.Burlet@HSConsultants.net.au Sent: Thursday, 7 June 2018 9:50 AM To: 'rubberduck-vba/Rubberduck' reply@reply.github.com; 'rubberduck-vba/Rubberduck' Rubberduck@noreply.github.com Cc: 'LukeHSC' luke@hsconsultants.net.au; 'Mention' mention@noreply.github.com Subject: RE: [rubberduck-vba/Rubberduck] Bracket matcher/finder and auto-completion (#4033)

hi Mathieu

Been working coding this AM with the autocomplete on, for most part seems ok, few glitches , i.e. re-autocompleting brackets if I go to edit them or backspace over them.

Biggest issue just now, I went to copy and paste a variable after a ‘[‘ bracket and RD made this:

I sent to turn off the autocomplete for RD but it does not want to turn off? I sent to Settings, unticked the ‘Close Square Brackets’ pressed Ok. But still autocompletes square brackets. I went back to settings and it is turned back on? Same thing with the ‘(‘ ; when I got the ‘[‘ all fixed up then the ‘(‘ repeated too much and not able to turn that off in RD settings either.

Tried several times on the Settings and now it is saving the setup (no autocomplete for ‘(‘ or ‘[‘ while I fixed up the issue in the screenshot above)

Regards,

Luke

From: Mathieu Guindon <notifications@github.com mailto:notifications@github.com > Sent: Thursday, 7 June 2018 7:06 AM To: rubberduck-vba/Rubberduck <Rubberduck@noreply.github.com mailto:Rubberduck@noreply.github.com > Cc: LukeHSC <luke@hsconsultants.net.au mailto:luke@hsconsultants.net.au >; Mention <mention@noreply.github.com mailto:mention@noreply.github.com > Subject: Re: [rubberduck-vba/Rubberduck] Bracket matcher/finder and auto-completion (#4033)

@LukeHSC https://github.com/LukeHSC I like the idea of a toggle on the toolbar (although, that toolbar is getting rather wide by now), however do note that backspacing/deleting is currently broken and only effectively works when the left-most character is removed - I'm giving up on trying to devise a fix using the current VBE messenging hook; I'll swap the hooking for an actual keyhook tonight, that way I can know what key was pressed, and reliably fire when a key is actually pressed, instead of filtering caret messages. Autocompletion will definitely work exactly as intended by v2.3 "green" release!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rubberduck-vba/Rubberduck/issues/4033#issuecomment-395213759 , or mute the thread https://github.com/notifications/unsubscribe-auth/AlvmwDqMay9s_boaoY8zKrMkhAFfSQvYks5t6EQ0gaJpZM4ULgJy . https://github.com/notifications/beacon/AlvmwPJ-aYYtc-ji3HE1Bu6BARZu4ak9ks5t6EQ0gaJpZM4ULgJy.gif