@@ -11,6 +11,7 @@ import (
11
11
"github.com/microsoft/typescript-go/internal/checker"
12
12
"github.com/microsoft/typescript-go/internal/core"
13
13
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
14
+ "github.com/microsoft/typescript-go/internal/scanner"
14
15
)
15
16
16
17
const (
@@ -27,14 +28,20 @@ func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.
27
28
}
28
29
c , done := program .GetTypeCheckerForFile (ctx , file )
29
30
defer done ()
30
- quickInfo , documentation := getQuickInfoAndDocumentation (c , node )
31
+
32
+ // Calculate the applicable range for the hover
33
+ rangeNode := getNodeForQuickInfo (node )
34
+ quickInfo , documentation := getQuickInfoAndDocumentationWithNode (c , node , rangeNode )
31
35
if quickInfo == "" {
32
36
return lsproto.HoverOrNull {}, nil
33
37
}
34
-
35
- // Calculate the applicable range for the hover
36
- rangeNode := getNodeForQuickInfo (node )
37
- textRange := core .NewTextRange (rangeNode .Pos (), rangeNode .End ())
38
+
39
+ // Calculate range without leading trivia to avoid including whitespace
40
+ sourceFile := ast .GetSourceFileOfNode (rangeNode )
41
+ sourceText := sourceFile .Text ()
42
+ start := scanner .SkipTrivia (sourceText , rangeNode .Pos ())
43
+ end := rangeNode .End ()
44
+ textRange := core .NewTextRange (start , end )
38
45
hoverRange := l .converters .ToLSPRange (file , textRange )
39
46
40
47
return lsproto.HoverOrNull {
@@ -51,7 +58,11 @@ func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.
51
58
}
52
59
53
60
func getQuickInfoAndDocumentation (c * checker.Checker , node * ast.Node ) (string , string ) {
54
- return getQuickInfoAndDocumentationForSymbol (c , c .GetSymbolAtLocation (node ), getNodeForQuickInfo (node ))
61
+ return getQuickInfoAndDocumentationWithNode (c , node , getNodeForQuickInfo (node ))
62
+ }
63
+
64
+ func getQuickInfoAndDocumentationWithNode (c * checker.Checker , node * ast.Node , rangeNode * ast.Node ) (string , string ) {
65
+ return getQuickInfoAndDocumentationForSymbol (c , c .GetSymbolAtLocation (node ), rangeNode )
55
66
}
56
67
57
68
func getQuickInfoAndDocumentationForSymbol (c * checker.Checker , symbol * ast.Symbol , node * ast.Node ) (string , string ) {
0 commit comments