nolanderc / glsl_analyzer

Language server for GLSL (autocomplete, goto-definition, formatter, and more)
GNU General Public License v3.0
188 stars 5 forks source link

Duplicate hover hints for re-declared functions #16

Closed automaticp closed 11 months ago

automaticp commented 12 months ago

Declaring the same function multiple times produces a hint for each declaration. Quite noticeable if you like to declare helper functions at the top and define them at the bottom.

#version 330 core

float foo(float, vec3);
float foo(float, vec3);

void main() {
    foo(1.0, vec3(1.0)); // <- triple hint
}

float foo(float, vec3) { return 1.0; }

image

nolanderc commented 12 months ago

Yes, this is an issue with the current name-resolution/type-checking. I have been meaning to rewrite it for a while... Currently it simply does an upwards tree traversal, looking for any definitions that match the current name. In order to support overloading, it currently returns all matches (instead of just the first) since it isn't clever enough to compare the types of the function parameters. However, this is quite a large change, so you'll have to live with this for a while :slightly_frowning_face:

automaticp commented 12 months ago

Of course, no pressure. This is totally a minor issue anyways.

nolanderc commented 11 months ago

I have an idea on how to fix this: essentially, we just pretty-print the types and compare the strings for equality. It's not totally fool-proof, but likely good enough as a MVP. But I've already done a lot tonight so might leave that for tomorrow.

automaticp commented 11 months ago

Yeah, just don't send out identical responses from the same hover request. Maybe even condense multiple overloads into a singe lsp response too. Might be slightly harder to test, but it's rare to see multiple hover pop-ups on a single request. I didn't even know you could have that.

nolanderc commented 11 months ago

it's rare to see multiple hover pop-ups on a single request

Yes, ideally we would know which overload is being used, but without types that is not possible. I believe vscode gives a more reasonable UI for signature help, which we should also implement.