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.91k stars 299 forks source link

Autocompletion in middle of string. #5557

Open bclothier opened 4 years ago

bclothier commented 4 years ago

Rubberduck version information Version 2.5.0.5524 OS: Microsoft Windows NT 10.0.14393.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.12527.20880 Host Executable: MSACCESS.EXE

Description Auto completion doesn't seem to work sanely when in a middle of string. This becomes quite annoying when constructing long strings that needs variable interpolated.

To Reproduce Given the code:

foo = "abc| def"

I want to modify this and insert a variable, so I type " & bar &, leaving me at this:

foo = "abc" & bar & | def"

I then type " and the autocomplete kicks in:

foo = "abc" & bar &"|" def"

This is now invalid line and I have to delete the ", add a space between the & and the remaining " to get me this valid line:

foo = "abc" & bar & "def"

Expected behavior I think the simplest fix is to prevent autocompletion when interpolating in middle of a string, especially if the line contains odd number of quoting characters.

retailcoder commented 4 years ago

Something is off with the condition / expected behavior - if the number of double quotes on either side of the caret isn't odd*, then the caret isn't in the middle of a string literal.

The first quote was inserted without AC intervention because the caret is in the middle of a string literal; seems what you really want/expect, is for AC to stop bailing out inside a string literal.

If AC doesn't bail out, then the first " keypress would have resulted with "|" and the manual concatenation would have been seamless. Right?

* yeah it's actually more complicated than that ;-)

bclothier commented 4 years ago

If you mean from this:

foo = "abc| def"

that might work.... provided that the VBIDE doesn't try to get cute and insert a ; or something silly.

MDoerner commented 4 years ago

I think what is requested here is that AC does not kick in if the line ends in a non-terminated string literal.

retailcoder commented 4 years ago

Linking #5340

retailcoder commented 4 years ago

Argh that's correct, VBE steps in unless we push the feature into mind-reading territory and complete with " & | & "... wait what if it actually did that, and did ""| when the Ctrl key is being held down?

Otherwise yeah, bailing out is the only possible solution.

retailcoder commented 4 years ago

The default should probably be no-op / bail out.

Perhaps configurable Ctrl/Shift + " combos can then be added to explicitly (as in "I asked for this to happen")...

Starting to think backspace handling should also be no-op /bail out (i.e. let the VBE handle it business as usual) by default, and optionally enabled with configurable control/shift/none keys as well.