bscan / PerlNavigator

Perl Language Server that includes syntax checking, perl critic, and code navigation
MIT License
198 stars 39 forks source link

hover.ts: Change else ifs to switch (like completion.ts) #93

Closed IAKOBVS closed 11 months ago

bscan commented 11 months ago

Thanks, the newer changes look good for the switch statements. I see that you're also trying to tackle case insensitive autocompletion https://github.com/bscan/PerlNavigator/issues/26 as well

Solving that one would be great, but it's much trickier than it looks, and I gave up on it last year after trying for a while to get insensitive matches working.

The core challenge is that we currently match on a variety of constructs, and then put back the original. For example we may have Foo::Bar in our set of known elements. Foo->B needs to match Foo::Bar, but still autocomplete to Foo->Bar. Currently this works with the following key line of code:

let aligned = elemName.replace(new RegExp(`^${quotedSymbol}`, 'gi'), symbol);

Similarly, we sometimes know the object type, so for example:

use File::Temp;
my $file = File::Temp->new();
$file->fil

and $file->fil will autocomplete to $file->filename, but gets looked up in the set of elements by File::Temp::fil and then the prefix is restored. Lots of little details here, but it is all currently working well with case sensitive lookups.

Your proposed change currently breaks it however since it will only lookup lowercase (see image not matching uppercase -> uppercase), and more importantly, will restore invalid constructs instead of fixing them (Autocompletion below would fill in My_test1 if I pressed enter)

Important note for testing: the vscode autocompletion widget is case insensitive, which can make this feel like it's working sometimes, even when it's not. Completion results are requested once (case sensitive on the prefix), but then not recomputed as you type. You can press esc and then ctrl+space if you need to repull the matches.

Do you have the dev version of the Perl Navigator up locally for testing? Are you a vscode user? You can also feel free to find me on Reddit or Discord (I'm in the Perl server).

image

IAKOBVS commented 11 months ago

I actually use it with coc-nvim.

bscan commented 11 months ago

This looks great to me. Using Enum elements is certainly more readable, and formatting is always good too. Thanks for the contribution! I appreciate it and welcome changes.