@@ -3,60 +3,36 @@ import type { Hover, MarkupContent, Position, Range } from 'vscode-languageserve
3
3
import { stringifyCss , stringifyConfigValue } from './util/stringify'
4
4
import dlv from 'dlv'
5
5
import { isCssContext } from './util/css'
6
- import {
7
- findAll ,
8
- findClassNameAtPosition ,
9
- findHelperFunctionsInRange ,
10
- indexToPosition ,
11
- } from './util/find'
6
+ import { findAll , indexToPosition } from './util/find'
12
7
import { validateApply } from './util/validateApply'
13
8
import { getClassNameParts } from './util/getClassNameAtPosition'
14
9
import * as jit from './util/jit'
15
10
import { validateConfigPath } from './diagnostics/getInvalidConfigPathDiagnostics'
16
11
import { isWithinRange } from './util/isWithinRange'
17
- import type { TextDocument } from 'vscode-languageserver-textdocument'
18
12
import { addPixelEquivalentsToValue } from './util/pixelEquivalents'
19
13
import { getTextWithoutComments } from './util/doc'
20
14
import braces from 'braces'
21
15
import { absoluteRange } from './util/absoluteRange'
22
16
import { segment } from './util/segment'
17
+ import type { Document } from './documents/document'
23
18
24
- export async function doHover (
25
- state : State ,
26
- document : TextDocument ,
27
- position : Position ,
28
- ) : Promise < Hover > {
19
+ export async function doHover ( doc : Document , position : Position ) : Promise < Hover > {
29
20
return (
30
- ( await provideClassNameHover ( state , document , position ) ) ||
31
- ( await provideThemeDirectiveHover ( state , document , position ) ) ||
32
- ( await provideCssHelperHover ( state , document , position ) ) ||
33
- ( await provideSourceGlobHover ( state , document , position ) )
21
+ ( await provideClassNameHover ( doc , position ) ) ||
22
+ ( await provideThemeDirectiveHover ( doc , position ) ) ||
23
+ ( await provideCssHelperHover ( doc , position ) ) ||
24
+ ( await provideSourceGlobHover ( doc , position ) )
34
25
)
35
26
}
36
27
37
- async function provideCssHelperHover (
38
- state : State ,
39
- document : TextDocument ,
40
- position : Position ,
41
- ) : Promise < Hover > {
42
- if ( ! isCssContext ( state , document , position ) ) {
43
- return null
44
- }
45
-
46
- const settings = await state . editor . getConfiguration ( document . uri )
47
-
48
- let helperFns = findHelperFunctionsInRange ( document , {
49
- start : { line : position . line , character : 0 } ,
50
- end : { line : position . line + 1 , character : 0 } ,
51
- } )
52
-
53
- for ( let helperFn of helperFns ) {
28
+ async function provideCssHelperHover ( doc : Document , position : Position ) : Promise < Hover > {
29
+ for ( let helperFn of doc . helperFnsAt ( position ) ) {
54
30
if ( ! isWithinRange ( position , helperFn . ranges . path ) ) continue
55
31
56
- if ( helperFn . helper === 'var' && ! state . v4 ) continue
32
+ if ( helperFn . helper === 'var' && ! doc . state . v4 ) continue
57
33
58
34
let validated = validateConfigPath (
59
- state ,
35
+ doc . state ,
60
36
helperFn . path ,
61
37
helperFn . helper === 'theme' ? [ 'theme' ] : [ ] ,
62
38
)
@@ -65,13 +41,13 @@ async function provideCssHelperHover(
65
41
let value = validated . isValid ? stringifyConfigValue ( validated . value ) : null
66
42
if ( value === null ) return null
67
43
68
- if ( settings . tailwindCSS . showPixelEquivalents ) {
69
- value = addPixelEquivalentsToValue ( value , settings . tailwindCSS . rootFontSize )
44
+ if ( doc . settings . tailwindCSS . showPixelEquivalents ) {
45
+ value = addPixelEquivalentsToValue ( value , doc . settings . tailwindCSS . rootFontSize )
70
46
}
71
47
72
48
let lines = [ '```plaintext' , value , '```' ]
73
49
74
- if ( state . v4 && helperFn . path . startsWith ( '--' ) ) {
50
+ if ( doc . state . v4 && helperFn . path . startsWith ( '--' ) ) {
75
51
lines = [
76
52
//
77
53
'```css' ,
@@ -91,14 +67,11 @@ async function provideCssHelperHover(
91
67
return null
92
68
}
93
69
94
- async function provideClassNameHover (
95
- state : State ,
96
- document : TextDocument ,
97
- position : Position ,
98
- ) : Promise < Hover > {
99
- let className = await findClassNameAtPosition ( state , document , position )
100
- if ( className === null ) return null
70
+ async function provideClassNameHover ( doc : Document , position : Position ) : Promise < Hover > {
71
+ let className = Array . from ( doc . classNamesAt ( position ) ) [ 0 ]
72
+ if ( ! className ) return null
101
73
74
+ let state = doc . state
102
75
if ( state . v4 ) {
103
76
let root = state . designSystem . compile ( [ className . className ] ) [ 0 ]
104
77
@@ -109,7 +82,7 @@ async function provideClassNameHover(
109
82
return {
110
83
contents : {
111
84
language : 'css' ,
112
- value : await jit . stringifyRoot ( state , root , document . uri ) ,
85
+ value : await jit . stringifyRoot ( state , root , doc . uri ) ,
113
86
} ,
114
87
range : className . range ,
115
88
}
@@ -125,7 +98,7 @@ async function provideClassNameHover(
125
98
return {
126
99
contents : {
127
100
language : 'css' ,
128
- value : await jit . stringifyRoot ( state , root , document . uri ) ,
101
+ value : await jit . stringifyRoot ( state , root , doc . uri ) ,
129
102
} ,
130
103
range : className . range ,
131
104
}
@@ -134,14 +107,14 @@ async function provideClassNameHover(
134
107
const parts = getClassNameParts ( state , className . className )
135
108
if ( ! parts ) return null
136
109
137
- if ( isCssContext ( state , document , position ) ) {
110
+ if ( isCssContext ( state , doc . storage , position ) ) {
138
111
let validated = validateApply ( state , parts )
139
112
if ( validated === null || validated . isApplyable === false ) {
140
113
return null
141
114
}
142
115
}
143
116
144
- const settings = await state . editor . getConfiguration ( document . uri )
117
+ const settings = await state . editor . getConfiguration ( doc . uri )
145
118
146
119
const css = stringifyCss (
147
120
className . className ,
@@ -167,11 +140,10 @@ function markdown(lines: string[]): MarkupContent {
167
140
}
168
141
}
169
142
170
- async function provideSourceGlobHover (
171
- state : State ,
172
- document : TextDocument ,
173
- position : Position ,
174
- ) : Promise < Hover > {
143
+ async function provideSourceGlobHover ( doc : Document , position : Position ) : Promise < Hover > {
144
+ let state = doc . state
145
+ let document = doc . storage
146
+
175
147
if ( ! isCssContext ( state , document , position ) ) {
176
148
return null
177
149
}
@@ -230,11 +202,10 @@ async function provideSourceGlobHover(
230
202
const PATTERN_AT_THEME = / @ (?< directive > t h e m e ) \s + (?< parts > [ ^ { ] + ) \s * \{ / dg
231
203
const PATTERN_IMPORT_THEME = / @ (?< directive > i m p o r t ) \s * [ ^ ; ] + ?t h e m e \( (?< parts > [ ^ ) ] + ) \) / dg
232
204
233
- async function provideThemeDirectiveHover (
234
- state : State ,
235
- document : TextDocument ,
236
- position : Position ,
237
- ) : Promise < Hover > {
205
+ async function provideThemeDirectiveHover ( doc : Document , position : Position ) : Promise < Hover > {
206
+ let state = doc . state
207
+ let document = doc . storage
208
+
238
209
if ( ! state . v4 ) return null
239
210
240
211
let range = {
0 commit comments