@@ -4,29 +4,83 @@ import {
4
4
getClassNameAtPosition ,
5
5
getClassNameParts ,
6
6
} from '../util/getClassNameAtPosition'
7
- import { stringifyCss } from '../util/stringify'
7
+ import { stringifyCss , stringifyConfigValue } from '../util/stringify'
8
8
const dlv = require ( 'dlv' )
9
9
import escapeClassName from 'css.escape'
10
10
import { isHtmlContext } from '../util/html'
11
+ import { isCssContext } from '../util/css'
11
12
12
13
export function provideHover (
13
14
state : State ,
14
15
params : TextDocumentPositionParams
15
16
) : Hover {
16
- let doc = state . editor . documents . get ( params . textDocument . uri )
17
+ return (
18
+ provideClassNameHover ( state , params ) || provideCssHelperHover ( state , params )
19
+ )
20
+ }
21
+
22
+ function provideCssHelperHover (
23
+ state : State ,
24
+ { textDocument, position } : TextDocumentPositionParams
25
+ ) : Hover {
26
+ let doc = state . editor . documents . get ( textDocument . uri )
27
+
28
+ if ( ! isCssContext ( doc , position ) ) return null
29
+
30
+ const line = doc . getText ( {
31
+ start : { line : position . line , character : 0 } ,
32
+ end : { line : position . line + 1 , character : 0 } ,
33
+ } )
34
+
35
+ const match = line . match (
36
+ / (?< helper > t h e m e | c o n f i g ) \( (?< quote > [ ' " ] ) (?< key > [ ^ ) ] + ) \k<quote > \) /
37
+ )
38
+
39
+ if ( match === null ) return null
40
+
41
+ const startChar = match . index + 7
42
+ const endChar = startChar + match . groups . key . length
17
43
18
- if ( isHtmlContext ( doc , params . position ) ) {
19
- return provideClassNameHover ( state , params )
44
+ if ( position . character < startChar || position . character >= endChar ) {
45
+ return null
20
46
}
21
47
22
- return null
48
+ let key = match . groups . key
49
+ . split ( / ( \[ [ ^ \] ] + \] | \. ) / )
50
+ . filter ( Boolean )
51
+ . filter ( ( x ) => x !== '.' )
52
+ . map ( ( x ) => x . replace ( / ^ \[ ( [ ^ \] ] + ) \] $ / , '$1' ) )
53
+
54
+ if ( key . length === 0 ) return null
55
+
56
+ if ( match . groups . helper === 'theme' ) {
57
+ key = [ 'theme' , ...key ]
58
+ }
59
+
60
+ const value = stringifyConfigValue ( dlv ( state . config , key ) )
61
+
62
+ if ( value === null ) return null
63
+
64
+ return {
65
+ contents : { kind : 'plaintext' , value } ,
66
+ range : {
67
+ start : { line : position . line , character : startChar } ,
68
+ end : {
69
+ line : position . line ,
70
+ character : endChar ,
71
+ } ,
72
+ } ,
73
+ }
23
74
}
24
75
25
76
function provideClassNameHover (
26
77
state : State ,
27
78
{ textDocument, position } : TextDocumentPositionParams
28
79
) : Hover {
29
80
let doc = state . editor . documents . get ( textDocument . uri )
81
+
82
+ if ( ! isHtmlContext ( doc , position ) ) return null
83
+
30
84
let hovered = getClassNameAtPosition ( doc , position )
31
85
if ( ! hovered ) return null
32
86
0 commit comments