Paul King created GROOVY-12635:
----------------------------------
Summary: groovy-lsp: hover fallback uses the text before the caret
rather than the identifier under it
Key: GROOVY-12635
URL: https://issues.apache.org/jira/browse/GROOVY-12635
Project: Groovy
Issue Type: Bug
Reporter: Paul King
Note: I have written this as a separate ticket but it could be done as a
sub-part of GROOVY-12634.
When hover finds no AST node to describe, {{HoverService.identifierHover()}}
builds its fallback from {{CompletionService.prefixAt()}}. That helper returns
the identifier text *before* the caret, which is right for completion but wrong
for hover: hover's position is the character under the mouse pointer, which can
be anywhere in the word.
As a result:
* Hovering in the middle of a word shows a truncated word, and hovering on its
first character shows nothing.
* The type-index lookup ({{TypeIndex.uniqueBySimpleName}}) only matches when
the caret sits just after the last character of the word. Hovering over a type
name in a comment, or in a file that fails to compile, finds the type only from
that one position.
* A word that matches no type is echoed back as the hover content, e.g.
hovering over {{mysteryword}} in a comment shows a fragment of that word.
{{NavigationService.identifierAt()}} already handles this correctly: it uses
{{Identifiers.wordAround()}} and falls back to {{prefixAt()}} only when that
finds no word.
h3. Proposed behaviour
* Use the whole identifier under the caret ({{Identifiers.wordAround()}}) for
the fallback, as navigation does.
* Keep the type-index lookup, so a type name in a comment or uncompiled code
still gets a hover with its fully qualified name.
* Return no hover when the word matches no type, rather than echoing the word.
The last point changes tested behaviour:
{{NavigationExecutionTest.staticCallsPropertiesAndIdentifierHover}} and the
loose-document case in {{JdtInspiredTest}} expect the unknown word to be
returned. The existing loose-document test also places the caret at the end of
the word, the only position where the current code works, so it should gain a
mid-word case.
Note: there is an argument to keep the echo (last bullet) and "Return the whole
word" and no need for tests related to that. I am not familiar enough with
usage patterns we might see but best guess is above.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)