@master/css-language-server 2.0.0-beta.62 → 2.0.0-beta.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/completionProvider.d.ts +11 -0
- package/dist/constant.d.ts +32 -0
- package/dist/documentColorProvider.d.ts +22 -0
- package/dist/hoverProvider.d.ts +19 -0
- package/dist/masterCss.d.ts +17 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.mjs +1 -0
- package/dist/utils/hex-to-rgb.d.ts +2 -0
- package/dist/utils/regex.d.ts +1 -0
- package/package.json +1 -1
- package/src/completionProvider.ts +0 -307
- package/src/constant.ts +0 -1170
- package/src/documentColorProvider.ts +0 -296
- package/src/hoverProvider.ts +0 -158
- package/src/masterCss.ts +0 -80
- package/src/server.ts +0 -264
- package/src/utils/hex-to-rgb.ts +0 -8
- package/src/utils/regex.ts +0 -1
- package/tsconfig.json +0 -14
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
masterCssKeyValues,
|
|
3
|
-
masterCssSelectors,
|
|
4
|
-
masterCssElements,
|
|
5
|
-
masterCssMedia,
|
|
6
|
-
masterCssOtherKeys,
|
|
7
|
-
masterCssType,
|
|
8
|
-
masterCssCommonValues
|
|
9
|
-
} from './constant'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
TextDocuments,
|
|
13
|
-
CompletionItem,
|
|
14
|
-
CompletionItemKind,
|
|
15
|
-
TextDocumentPositionParams
|
|
16
|
-
} from 'vscode-languageserver/node'
|
|
17
|
-
import { TextDocument } from 'vscode-languageserver-textdocument'
|
|
18
|
-
import MasterCSS from '@master/css'
|
|
19
|
-
import { pascalCase } from 'pascal-case'
|
|
20
|
-
|
|
21
|
-
let cssKeys: Array<string | CompletionItem> = []
|
|
22
|
-
cssKeys = cssKeys.concat(masterCssOtherKeys)
|
|
23
|
-
masterCssKeyValues.forEach(x => {
|
|
24
|
-
cssKeys = cssKeys.concat(x.key)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const masterCssKeys: Array<string | CompletionItem> = [...new Set(cssKeys)]
|
|
28
|
-
|
|
29
|
-
export function GetLastInstance(textDocumentPosition: TextDocumentPositionParams, documents: TextDocuments<TextDocument>) {
|
|
30
|
-
const documentUri = textDocumentPosition.textDocument.uri
|
|
31
|
-
const language = documentUri.substring(documentUri.lastIndexOf('.') + 1)
|
|
32
|
-
const position = textDocumentPosition.position
|
|
33
|
-
|
|
34
|
-
const classPattern = /(?:[^"{'\s])+(?=>\s|\b)/g
|
|
35
|
-
let classMatch: RegExpExecArray | null
|
|
36
|
-
let lastKey = ''
|
|
37
|
-
|
|
38
|
-
const document = documents.get(documentUri)
|
|
39
|
-
const line = document?.getText({
|
|
40
|
-
start: { line: position.line, character: 0 },
|
|
41
|
-
end: { line: position.line, character: position.character },
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
let lineText: string = line == null ? '' : line
|
|
45
|
-
lineText = lineText.trim()
|
|
46
|
-
|
|
47
|
-
const text = document?.getText({
|
|
48
|
-
start: { line: 0, character: 0 },
|
|
49
|
-
end: { line: position.line, character: position.character },
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (lineText.match(classPattern) === null) {
|
|
54
|
-
return { isInstance: false, lastKey: '', triggerKey: '', isStart: false, language: language }
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
while ((classMatch = classPattern.exec(lineText)) !== null) {
|
|
58
|
-
lastKey = classMatch[0]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let triggerKey = lineText.charAt(lineText.length - 1)
|
|
63
|
-
let isStart = position.character == 1 || lineText.charAt(lineText.length - 2) === ' ' || lineText.charAt(lineText.length - 2) === '' || lineText.charAt(lineText.length - 2) === '"' || lineText.charAt(lineText.length - 2) === '\'' || lineText.charAt(lineText.length - 2) === '{'
|
|
64
|
-
|
|
65
|
-
if (lineText.charAt(lineText.length - 2) === ':' && lineText.charAt(lineText.length - 1) === ':') {
|
|
66
|
-
triggerKey = '::'
|
|
67
|
-
isStart = false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return { isInstance: true, lastKey: lastKey, triggerKey: triggerKey, isStart: isStart, language: language }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function GetCompletionItem(instance: string, triggerKey: string, startWithSpace: boolean, language: string, masterCss: MasterCSS = new MasterCSS()) {
|
|
74
|
-
|
|
75
|
-
let masterStyleCompletionItem: CompletionItem[] = []
|
|
76
|
-
const haveValue = instance.split(':').length
|
|
77
|
-
let key = instance.split(':')[0]
|
|
78
|
-
key = key.trim()
|
|
79
|
-
const instanceLength = instance.split(':|@').length
|
|
80
|
-
const last = instance.split(':|@')[instanceLength - 1]
|
|
81
|
-
|
|
82
|
-
const mediaPattern = /[^\\s"]+@+([^\\s:"@]+)/g
|
|
83
|
-
const elementsPattern = /[^\\s"]+::+([^\\s:"@]+)/g
|
|
84
|
-
|
|
85
|
-
let isColorful = false
|
|
86
|
-
const isMedia = !(mediaPattern.exec(instance) === null && triggerKey !== '@')
|
|
87
|
-
const isElements = !(elementsPattern.exec(instance) === null && triggerKey !== '::')
|
|
88
|
-
|
|
89
|
-
let masterCssValues: Array<string | CompletionItem> = []
|
|
90
|
-
const masterCustomSelectors = Object.keys(masterCss.config.selectors ?? {})
|
|
91
|
-
.map(x => x.endsWith('(') ? `${x})` : x)
|
|
92
|
-
.filter(x => x.match(/:[^:]+/) && !masterCssSelectors.find(existedSelector => (typeof existedSelector === 'string' ? existedSelector : existedSelector.label) === `:${x}`))
|
|
93
|
-
.map(x => {
|
|
94
|
-
x = x.substring(1)
|
|
95
|
-
if (x.endsWith(')')) {
|
|
96
|
-
return { label: x, kind: CompletionItemKind.Function }
|
|
97
|
-
}
|
|
98
|
-
return x
|
|
99
|
-
})
|
|
100
|
-
console.log(masterCustomSelectors)
|
|
101
|
-
const masterCustomElements = Object.keys(masterCss.config.selectors ?? {})
|
|
102
|
-
.map(x => x.endsWith('(') ? `${x})` : x)
|
|
103
|
-
.filter(x => x.match(/::[^:]+/) && !masterCssElements.find(existedElement => (typeof existedElement === 'string' ? existedElement : existedElement.label) === `::${x}`))
|
|
104
|
-
.map(x => {
|
|
105
|
-
x = x.substring(2)
|
|
106
|
-
if (x.endsWith(')')) {
|
|
107
|
-
return { label: x, kind: CompletionItemKind.Function }
|
|
108
|
-
}
|
|
109
|
-
return x
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
masterCssKeyValues.forEach(x => {
|
|
113
|
-
if (x.key.includes(key)) {
|
|
114
|
-
masterCssValues = masterCssValues.concat(
|
|
115
|
-
x.values.filter(cssValue =>
|
|
116
|
-
!masterCssValues.find(existedValue => (typeof existedValue === 'string' ? existedValue : existedValue.label) === (typeof cssValue === 'string' ? cssValue : cssValue.label))
|
|
117
|
-
)
|
|
118
|
-
)
|
|
119
|
-
const pascalCaseFullKey = pascalCase(x.key[0])
|
|
120
|
-
if (masterCss.config.values?.[pascalCaseFullKey]) {
|
|
121
|
-
const masterCustomValues = Object.keys(masterCss.config.values[pascalCaseFullKey])
|
|
122
|
-
masterCssValues = masterCssValues.concat(
|
|
123
|
-
masterCustomValues
|
|
124
|
-
.filter(customValue =>
|
|
125
|
-
!masterCssValues.find(existedValue => (typeof existedValue === 'string' ? existedValue : existedValue.label) === customValue)
|
|
126
|
-
)
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (x.colorful) {
|
|
131
|
-
isColorful = true
|
|
132
|
-
const needPushList = masterCssType.find(y => y.type === 'color')?.values.filter(z => !masterCssValues.find(a => (typeof a === 'string' ? a : a.label) === (typeof z === 'string' ? z : z.label)))
|
|
133
|
-
if (needPushList) {
|
|
134
|
-
masterCssValues = masterCssValues.concat(needPushList)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
if (startWithSpace == true && triggerKey !== '@' && triggerKey !== ':') { //ex " background"
|
|
141
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssKeys, CompletionItemKind.Property, ':'))
|
|
142
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(Object.keys(masterCss.config.semantics ?? {}), CompletionItemKind.Property))
|
|
143
|
-
|
|
144
|
-
if (language == 'tsx' || language == 'vue' || language == 'jsx') {
|
|
145
|
-
return HaveDash(key, masterStyleCompletionItem)
|
|
146
|
-
}
|
|
147
|
-
return masterStyleCompletionItem
|
|
148
|
-
}
|
|
149
|
-
else if (startWithSpace == true) { //triggerKey==@|: //ex " :"
|
|
150
|
-
return []
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (!masterCssKeys.includes(key) && triggerKey !== ':') { //show key //ex "backgr"
|
|
154
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssKeys, CompletionItemKind.Property, ':'))
|
|
155
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(Object.keys(masterCss.config.semantics ?? {}), CompletionItemKind.Property))
|
|
156
|
-
if (language == 'tsx' || language == 'vue' || language == 'jsx') {
|
|
157
|
-
return HaveDash(key, masterStyleCompletionItem)
|
|
158
|
-
}
|
|
159
|
-
return masterStyleCompletionItem
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (masterCssKeys.includes(key) && key !== null && isElements === true) { //show elements
|
|
163
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssElements, CompletionItemKind.Property))
|
|
164
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomElements, CompletionItemKind.Property))
|
|
165
|
-
if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
|
|
166
|
-
return HaveDash(last, masterStyleCompletionItem)
|
|
167
|
-
}
|
|
168
|
-
return masterStyleCompletionItem
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (masterCssKeys.includes(key) && key !== null && isMedia === true) { //show media
|
|
172
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssMedia, CompletionItemKind.Property))
|
|
173
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(Object.keys(masterCss.config.breakpoints ?? {}), CompletionItemKind.Property))
|
|
174
|
-
if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
|
|
175
|
-
return HaveDash('@' + last, masterStyleCompletionItem)
|
|
176
|
-
}
|
|
177
|
-
return masterStyleCompletionItem
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (Object.keys(masterCss.config.semantics ?? {}).includes(key) && !masterCssKeyValues.find(x => x.key.includes(key))) {
|
|
181
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssSelectors, CompletionItemKind.Property))
|
|
182
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomSelectors, CompletionItemKind.Property))
|
|
183
|
-
if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
|
|
184
|
-
return HaveDash(last, masterStyleCompletionItem)
|
|
185
|
-
}
|
|
186
|
-
return masterStyleCompletionItem
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
else if (masterCssKeys.includes(key) && haveValue <= 2 && !(haveValue == 2 && triggerKey === ':')) { //show value
|
|
190
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssValues, CompletionItemKind.Enum))
|
|
191
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssCommonValues, CompletionItemKind.Enum).map(x => {x.sortText = 'z'+x; return x}))
|
|
192
|
-
|
|
193
|
-
if (isColorful) {
|
|
194
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getColorsItem(masterCss))
|
|
195
|
-
}
|
|
196
|
-
if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
|
|
197
|
-
return HaveDash(last, masterStyleCompletionItem)
|
|
198
|
-
}
|
|
199
|
-
return masterStyleCompletionItem
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (masterCssKeys.includes(key) && (haveValue == 2 && triggerKey === ':' || haveValue >= 3) || masterCssKeyValues.find(x => x.values.includes(key))) { //show select
|
|
203
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssSelectors, CompletionItemKind.Function))
|
|
204
|
-
masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomSelectors, CompletionItemKind.Property))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
|
|
208
|
-
return HaveDash(last, masterStyleCompletionItem)
|
|
209
|
-
}
|
|
210
|
-
return masterStyleCompletionItem
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
function getReturnItem(items: Array<string | CompletionItem>, kind: CompletionItemKind, insertText = ''): CompletionItem[] {
|
|
215
|
-
const masterStyleCompletionItem: CompletionItem[] = []
|
|
216
|
-
|
|
217
|
-
items.forEach(x => {
|
|
218
|
-
if (typeof x === 'string') {
|
|
219
|
-
masterStyleCompletionItem.push({
|
|
220
|
-
label: x + insertText,
|
|
221
|
-
kind: kind,
|
|
222
|
-
insertText: x + insertText,
|
|
223
|
-
insertTextMode: 2,
|
|
224
|
-
command: insertText === ':'
|
|
225
|
-
? {
|
|
226
|
-
title: 'triggerSuggest',
|
|
227
|
-
command: 'editor.action.triggerSuggest'
|
|
228
|
-
}
|
|
229
|
-
: undefined
|
|
230
|
-
})
|
|
231
|
-
} else {
|
|
232
|
-
masterStyleCompletionItem.push({
|
|
233
|
-
insertText: x.label + insertText,
|
|
234
|
-
insertTextMode: 2,
|
|
235
|
-
command: insertText === ':'
|
|
236
|
-
? {
|
|
237
|
-
title: 'triggerSuggest',
|
|
238
|
-
command: 'editor.action.triggerSuggest'
|
|
239
|
-
}
|
|
240
|
-
: undefined
|
|
241
|
-
,
|
|
242
|
-
...x
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
return masterStyleCompletionItem
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
function getColorsItem(masterCss: MasterCSS = new MasterCSS()): CompletionItem[] {
|
|
253
|
-
|
|
254
|
-
const masterStyleCompletionItem: CompletionItem[] = []
|
|
255
|
-
|
|
256
|
-
Object.keys(masterCss.colorsThemesMap)
|
|
257
|
-
.forEach((colorName: string) => {
|
|
258
|
-
const colors = masterCss.colorsThemesMap[colorName]
|
|
259
|
-
Object.keys(colors)
|
|
260
|
-
.forEach((level: string) => {
|
|
261
|
-
const colorValue: any = masterCss.colorsThemesMap[colorName][level]
|
|
262
|
-
try {
|
|
263
|
-
if (level === '') {
|
|
264
|
-
masterStyleCompletionItem.push({
|
|
265
|
-
label: colorName,
|
|
266
|
-
documentation: Object.values<string>(colorValue)[0],
|
|
267
|
-
kind: CompletionItemKind.Color,
|
|
268
|
-
sortText: `${colorName}`
|
|
269
|
-
})
|
|
270
|
-
} else if (!isNaN(+level)) {
|
|
271
|
-
masterStyleCompletionItem.push({
|
|
272
|
-
label: colorName + '-' + level,
|
|
273
|
-
documentation: Object.values<string>(colorValue)[0],
|
|
274
|
-
kind: CompletionItemKind.Color,
|
|
275
|
-
sortText: `${colorName}-${(level).toString().padStart(2, '0')}`
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
} catch (_) { /* empty */ }
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
return masterStyleCompletionItem
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function HaveDash(str: string, itemList: CompletionItem[]): CompletionItem[] {
|
|
286
|
-
const completionItem: CompletionItem[] = []
|
|
287
|
-
if (str.split('-').length - 1 <= 0) {
|
|
288
|
-
return itemList
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
const start = str.split('-')[0] + '-'
|
|
292
|
-
itemList.map(x => {
|
|
293
|
-
if (x.label.includes(start)) {
|
|
294
|
-
completionItem.push({
|
|
295
|
-
label: x.label,
|
|
296
|
-
kind: x.kind,
|
|
297
|
-
insertText: x.insertText?.substring(start.length),
|
|
298
|
-
insertTextMode: x.insertTextMode,
|
|
299
|
-
command: x.command
|
|
300
|
-
}
|
|
301
|
-
)
|
|
302
|
-
}
|
|
303
|
-
})
|
|
304
|
-
return completionItem
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|