Paul King created GROOVY-12634:
----------------------------------

             Summary: groovy-lsp: hover on a constructor call shows a fragment 
of the type name instead of the constructor
                 Key: GROOVY-12634
                 URL: https://issues.apache.org/jira/browse/GROOVY-12634
             Project: Groovy
          Issue Type: Bug
            Reporter: Paul King


Hovering over a constructor call does not describe the constructor or the type 
being instantiated. The hover instead shows the part of the word that lies 
before the hovered character.

For the script:
{code:groovy}
println new Date()
{code}

hovering at these 0-based UTF-16 columns gives:
||Column||Character||Hover content||
|9|{{e}} in {{new}}|{{n}}|
|12|{{D}}|(no hover)|
|13|{{a}}|{{D}}|
|14|{{t}}|{{Da}}|
|15|{{e}}|{{Dat}}|

Hover on {{println}} works as expected ({{void Script.println(Object arg0)}}). 
The script compiles without diagnostics.

h3. Cause
* {{HoverService.resolveForHover()}} only resolves a {{MethodCallExpression}}. 
A {{ConstructorCallExpression}} is passed through unchanged.
* {{HoverService.render()}} has no case for {{ConstructorCallExpression}}, so 
it returns {{null}}.
* A {{null}} result falls through to {{identifierHover()}}, which uses 
{{CompletionService.prefixAt()}}. That returns the identifier text before the 
caret, which gives the fragments above (see the separate issue on the fallback).

The other features already handle constructor calls: signature help 
({{SignatureHelpService}}), navigation ({{NavigationService}}) and the type 
hierarchy ({{HierarchyService}}). {{MethodBinding.resolveConstructor()}} 
already picks a unique constructor by argument count.

h3. Expected
* When a unique constructor matches the call, hover shows its signature and 
Groovydoc, for example {{new Date()}}.
* When no single constructor matches (overloads with the same argument count, 
or an anonymous inner class), hover falls back to the instantiated type, for 
example {{class java.util.Date}}.

h3. Notes
{{ConstructorNode}} extends {{MethodNode}}. If it is passed to the existing 
method rendering, the hover would read {{void Date.<init>()}}, so constructors 
need their own rendering placed before the {{MethodNode}} case.

Tests should cover hovering on the first, a middle and the last character of 
the type name, the {{new}} keyword, and a type whose constructors share an 
argument count.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to