1
1
import { NodeTypes } from '@shopify/liquid-html-parser' ;
2
2
import { LiquidHtmlNode } from '@shopify/theme-check-common' ;
3
- import { Hover , MarkupKind } from 'vscode-languageserver' ;
3
+ import { Hover , HoverParams , MarkupKind } from 'vscode-languageserver' ;
4
4
import { BaseHoverProvider } from '../BaseHoverProvider' ;
5
5
import { formatLiquidDocTagHandle , SUPPORTED_LIQUID_DOC_TAG_HANDLES } from '../../utils/liquidDoc' ;
6
+ import { DocumentManager } from '../../documents' ;
6
7
7
8
export class LiquidDocTagHoverProvider implements BaseHoverProvider {
8
- constructor ( ) { }
9
+ constructor ( private documentManager : DocumentManager ) { }
9
10
10
- async hover ( currentNode : LiquidHtmlNode , ancestors : LiquidHtmlNode [ ] ) : Promise < Hover | null > {
11
+ async hover (
12
+ currentNode : LiquidHtmlNode ,
13
+ ancestors : LiquidHtmlNode [ ] ,
14
+ params : HoverParams ,
15
+ ) : Promise < Hover | null > {
11
16
const parentNode = ancestors . at ( - 1 ) ;
12
17
13
- let docTagNode ;
14
-
15
- // We could be hovering on the liquidDoc tag itself
16
18
if (
17
- currentNode . type === NodeTypes . LiquidDocParamNode ||
18
- currentNode . type === NodeTypes . LiquidDocDescriptionNode ||
19
- currentNode . type = == NodeTypes . LiquidDocExampleNode
19
+ currentNode . type !== NodeTypes . LiquidDocParamNode &&
20
+ currentNode . type !== NodeTypes . LiquidDocDescriptionNode &&
21
+ currentNode . type ! == NodeTypes . LiquidDocExampleNode
20
22
) {
21
- docTagNode = currentNode ;
23
+ return null ;
22
24
}
23
25
24
- // or we could be hovering on the liquidDoc tag's text
26
+ const document = this . documentManager . get ( params . textDocument . uri ) ?. textDocument ;
27
+
28
+ // We only want to provide hover when we are on the exact tag name
29
+ // If the cursor is passed that but still within the tag node, we ignore it
30
+ //
31
+ // E.g.
32
+ // Provide hover: @para █m name - description
33
+ // Don't provide hover: @param █name - description
25
34
if (
26
- ( parentNode ?. type === NodeTypes . LiquidDocParamNode ||
27
- parentNode ?. type === NodeTypes . LiquidDocDescriptionNode ||
28
- parentNode ?. type === NodeTypes . LiquidDocExampleNode ) &&
29
- currentNode . type === NodeTypes . TextNode
35
+ document &&
36
+ document . offsetAt ( params . position ) > currentNode . position . start + currentNode . name . length
30
37
) {
31
- docTagNode = parentNode ;
32
- }
33
-
34
- if ( ! docTagNode ) {
35
38
return null ;
36
39
}
37
40
38
- const docTagData = SUPPORTED_LIQUID_DOC_TAG_HANDLES [ docTagNode . name ] ;
41
+ const docTagData = SUPPORTED_LIQUID_DOC_TAG_HANDLES [ currentNode . name ] ;
39
42
40
43
if ( ! docTagData ) {
41
44
return null ;
@@ -45,7 +48,7 @@ export class LiquidDocTagHoverProvider implements BaseHoverProvider {
45
48
contents : {
46
49
kind : MarkupKind . Markdown ,
47
50
value : formatLiquidDocTagHandle (
48
- docTagNode . name ,
51
+ currentNode . name ,
49
52
docTagData . description ,
50
53
docTagData . example ,
51
54
) ,
0 commit comments