4
4
5
5
use Amp \Promise ;
6
6
use Phpactor \Extension \LanguageServerBridge \Converter \PositionConverter ;
7
+ use Phpactor \LanguageServerProtocol \ClientCapabilities ;
7
8
use Phpactor \LanguageServerProtocol \Hover ;
8
9
use Phpactor \LanguageServerProtocol \MarkupContent ;
9
10
use Phpactor \LanguageServerProtocol \Position ;
@@ -43,11 +44,21 @@ class HoverHandler implements Handler, CanRegisterCapabilities
43
44
*/
44
45
private $ workspace ;
45
46
46
- public function __construct (Workspace $ workspace , Reflector $ reflector , ObjectRenderer $ renderer )
47
- {
47
+ /**
48
+ * @var ClientCapabilities
49
+ */
50
+ private ClientCapabilities $ clientCapabilities ;
51
+
52
+ public function __construct (
53
+ Workspace $ workspace ,
54
+ Reflector $ reflector ,
55
+ ObjectRenderer $ renderer ,
56
+ ClientCapabilities $ clientCapabilities
57
+ ) {
48
58
$ this ->reflector = $ reflector ;
49
59
$ this ->renderer = $ renderer ;
50
60
$ this ->workspace = $ workspace ;
61
+ $ this ->clientCapabilities = $ clientCapabilities ;
51
62
}
52
63
53
64
public function methods (): array
@@ -73,7 +84,7 @@ public function hover(
73
84
$ symbolContext = $ offsetReflection ->symbolContext ();
74
85
$ info = $ this ->infoFromReflecionOffset ($ offsetReflection );
75
86
$ string = new MarkupContent ('markdown ' , $ info );
76
-
87
+
77
88
return new Hover ($ string , new Range (
78
89
PositionConverter::byteOffsetToPosition (
79
90
ByteOffset::fromInt ($ symbolContext ->symbol ()->position ()->start ()),
@@ -89,7 +100,7 @@ public function hover(
89
100
90
101
public function registerCapabiltiies (ServerCapabilities $ capabilities ): void
91
102
{
92
- $ capabilities ->hoverProvider = true ;
103
+ $ capabilities ->hoverProvider = null !== $ this -> clientCapabilities -> textDocument -> hover ;
93
104
}
94
105
95
106
private function infoFromReflecionOffset (ReflectionOffset $ offset ): string
0 commit comments