1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
import { expect, test } from 'vitest'
import { withFixture } from '../common'
withFixture('basic', (c) => {
async function completion({
lang,
text,
position,
context = {
triggerKind: 1,
},
settings,
}) {
let textDocument = await c.openDocument({ text, lang, settings })
return c.sendRequest('textDocument/completion', {
textDocument,
position,
context,
})
}
async function expectCompletions({ lang, text, position, settings }) {
let result = await completion({ lang, text, position, settings })
let textEdit = expect.objectContaining({ range: { start: position, end: position } })
expect(result.items.length).toBe(11175)
expect(result.items.filter((item) => item.label.endsWith(':')).length).toBe(157)
expect(result).toEqual({
isIncomplete: false,
items: expect.arrayContaining([
expect.objectContaining({ label: 'hover:', textEdit }),
expect.objectContaining({ label: 'uppercase', textEdit }),
]),
})
}
test.concurrent('HTML', async () => {
await expectCompletions({ text: '<div class=""></div>', position: { line: 0, character: 12 } })
})
test.concurrent('JSX', async () => {
await expectCompletions({
lang: 'javascriptreact',
text: "<div className={''}></div>",
position: {
line: 0,
character: 17,
},
})
})
test.concurrent('JSX concatination', async () => {
await expectCompletions({
lang: 'javascriptreact',
text: "<div className={'' + ''}></div>",
position: {
line: 0,
character: 22,
},
})
})
test.concurrent('JSX outside strings', async () => {
let result = await completion({
lang: 'javascriptreact',
text: "<div className={'' + ''}></div>",
position: {
line: 0,
character: 18,
},
})
expect(result).toBe(null)
})
test.concurrent('classRegex simple', async () => {
await expectCompletions({
text: 'test ',
position: {
line: 0,
character: 5,
},
settings: { tailwindCSS: { experimental: { classRegex: ['test (\\S*)'] } } },
})
})
test.concurrent('classRegex nested', async () => {
await expectCompletions({
text: 'test ""',
position: {
line: 0,
character: 6,
},
settings: {
tailwindCSS: { experimental: { classRegex: [['test (\\S*)', '"([^"]*)"']] } },
},
})
})
test.concurrent('resolve', async () => {
let result = await completion({
text: '<div class="">',
position: {
line: 0,
character: 12,
},
})
let item = result.items.find((item) => item.label === 'uppercase')
let resolved = await c.sendRequest('completionItem/resolve', item)
expect(resolved).toEqual({
...item,
detail: 'text-transform: uppercase;',
documentation: {
kind: 'markdown',
value: '```css\n.uppercase {\n text-transform: uppercase;\n}\n```',
},
})
})
})
withFixture('overrides-variants', (c) => {
async function completion({
lang,
text,
position,
context = {
triggerKind: 1,
},
settings,
}) {
let textDocument = await c.openDocument({ text, lang, settings })
return c.sendRequest('textDocument/completion', {
textDocument,
position,
context,
})
}
test.concurrent(
'duplicate variant + value pairs do not produce multiple completions',
async () => {
let result = await completion({
text: '<div class="custom-hover"></div>',
position: { line: 0, character: 23 },
})
expect(result.items.filter((item) => item.label.endsWith('custom-hover:')).length).toBe(1)
}
)
})
|