vscode-css-languageservice 6.3.10 → 7.0.0-next.1

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/esm/beautify/beautify-css.js +1437 -1606
  3. package/lib/esm/cssLanguageService.d.ts +2 -2
  4. package/lib/esm/cssLanguageService.js +18 -18
  5. package/lib/esm/languageFacts/colors.js +1 -1
  6. package/lib/esm/languageFacts/dataManager.js +3 -3
  7. package/lib/esm/languageFacts/entry.js +1 -1
  8. package/lib/esm/languageFacts/facts.js +3 -3
  9. package/lib/esm/parser/cssNodes.js +1 -1
  10. package/lib/esm/parser/cssParser.js +5 -5
  11. package/lib/esm/parser/cssSymbolScope.js +2 -2
  12. package/lib/esm/parser/lessParser.js +5 -5
  13. package/lib/esm/parser/lessScanner.js +1 -1
  14. package/lib/esm/parser/scssParser.js +6 -6
  15. package/lib/esm/parser/scssScanner.js +1 -1
  16. package/lib/esm/services/cssCodeActions.js +4 -4
  17. package/lib/esm/services/cssCompletion.js +7 -7
  18. package/lib/esm/services/cssFolding.js +3 -3
  19. package/lib/esm/services/cssFormatter.js +3 -3
  20. package/lib/esm/services/cssHover.js +6 -6
  21. package/lib/esm/services/cssNavigation.js +6 -6
  22. package/lib/esm/services/cssSelectionRange.js +2 -2
  23. package/lib/esm/services/cssValidation.js +4 -4
  24. package/lib/esm/services/lessCompletion.js +2 -2
  25. package/lib/esm/services/lint.js +5 -5
  26. package/lib/esm/services/lintRules.js +1 -1
  27. package/lib/esm/services/lintUtil.js +1 -1
  28. package/lib/esm/services/pathCompletion.js +3 -3
  29. package/lib/esm/services/scssCompletion.js +3 -3
  30. package/lib/esm/services/scssNavigation.js +4 -4
  31. package/lib/esm/services/selectorPrinting.js +3 -3
  32. package/package.json +15 -15
  33. package/lib/umd/beautify/beautify-css.js +0 -1695
  34. package/lib/umd/cssLanguageService.d.ts +0 -39
  35. package/lib/umd/cssLanguageService.js +0 -105
  36. package/lib/umd/cssLanguageTypes.d.ts +0 -267
  37. package/lib/umd/cssLanguageTypes.js +0 -89
  38. package/lib/umd/data/webCustomData.js +0 -44613
  39. package/lib/umd/languageFacts/builtinData.js +0 -155
  40. package/lib/umd/languageFacts/colors.js +0 -949
  41. package/lib/umd/languageFacts/dataManager.js +0 -101
  42. package/lib/umd/languageFacts/dataProvider.js +0 -86
  43. package/lib/umd/languageFacts/entry.js +0 -217
  44. package/lib/umd/languageFacts/facts.js +0 -33
  45. package/lib/umd/parser/cssErrors.js +0 -61
  46. package/lib/umd/parser/cssNodes.js +0 -1676
  47. package/lib/umd/parser/cssParser.js +0 -2035
  48. package/lib/umd/parser/cssScanner.js +0 -619
  49. package/lib/umd/parser/cssSymbolScope.js +0 -328
  50. package/lib/umd/parser/lessParser.js +0 -732
  51. package/lib/umd/parser/lessScanner.js +0 -70
  52. package/lib/umd/parser/scssErrors.js +0 -30
  53. package/lib/umd/parser/scssParser.js +0 -874
  54. package/lib/umd/parser/scssScanner.js +0 -108
  55. package/lib/umd/services/cssCodeActions.js +0 -89
  56. package/lib/umd/services/cssCompletion.js +0 -1109
  57. package/lib/umd/services/cssFolding.js +0 -202
  58. package/lib/umd/services/cssFormatter.js +0 -149
  59. package/lib/umd/services/cssHover.js +0 -174
  60. package/lib/umd/services/cssNavigation.js +0 -539
  61. package/lib/umd/services/cssSelectionRange.js +0 -59
  62. package/lib/umd/services/cssValidation.js +0 -54
  63. package/lib/umd/services/lessCompletion.js +0 -390
  64. package/lib/umd/services/lint.js +0 -577
  65. package/lib/umd/services/lintRules.js +0 -90
  66. package/lib/umd/services/lintUtil.js +0 -210
  67. package/lib/umd/services/pathCompletion.js +0 -171
  68. package/lib/umd/services/scssCompletion.js +0 -367
  69. package/lib/umd/services/scssNavigation.js +0 -169
  70. package/lib/umd/services/selectorPrinting.js +0 -575
  71. package/lib/umd/utils/arrays.js +0 -54
  72. package/lib/umd/utils/objects.js +0 -24
  73. package/lib/umd/utils/resources.js +0 -25
  74. package/lib/umd/utils/strings.js +0 -123
@@ -1,1109 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../parser/cssNodes", "../parser/cssSymbolScope", "../languageFacts/facts", "../utils/strings", "../cssLanguageTypes", "@vscode/l10n", "../utils/objects", "./pathCompletion"], factory);
8
- }
9
- })(function (require, exports) {
10
- /*---------------------------------------------------------------------------------------------
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License. See License.txt in the project root for license information.
13
- *--------------------------------------------------------------------------------------------*/
14
- 'use strict';
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.CSSCompletion = void 0;
17
- const nodes = require("../parser/cssNodes");
18
- const cssSymbolScope_1 = require("../parser/cssSymbolScope");
19
- const languageFacts = require("../languageFacts/facts");
20
- const strings = require("../utils/strings");
21
- const cssLanguageTypes_1 = require("../cssLanguageTypes");
22
- const l10n = require("@vscode/l10n");
23
- const objects_1 = require("../utils/objects");
24
- const pathCompletion_1 = require("./pathCompletion");
25
- const SnippetFormat = cssLanguageTypes_1.InsertTextFormat.Snippet;
26
- const retriggerCommand = {
27
- title: 'Suggest',
28
- command: 'editor.action.triggerSuggest'
29
- };
30
- var SortTexts;
31
- (function (SortTexts) {
32
- // char code 32, comes before everything
33
- SortTexts["Enums"] = " ";
34
- SortTexts["Normal"] = "d";
35
- SortTexts["VendorPrefixed"] = "x";
36
- SortTexts["Term"] = "y";
37
- SortTexts["Variable"] = "z";
38
- })(SortTexts || (SortTexts = {}));
39
- class CSSCompletion {
40
- constructor(variablePrefix = null, lsOptions, cssDataManager) {
41
- this.variablePrefix = variablePrefix;
42
- this.lsOptions = lsOptions;
43
- this.cssDataManager = cssDataManager;
44
- this.completionParticipants = [];
45
- }
46
- configure(settings) {
47
- this.defaultSettings = settings;
48
- }
49
- getSymbolContext() {
50
- if (!this.symbolContext) {
51
- this.symbolContext = new cssSymbolScope_1.Symbols(this.styleSheet);
52
- }
53
- return this.symbolContext;
54
- }
55
- setCompletionParticipants(registeredCompletionParticipants) {
56
- this.completionParticipants = registeredCompletionParticipants || [];
57
- }
58
- async doComplete2(document, position, styleSheet, documentContext, completionSettings = this.defaultSettings) {
59
- if (!this.lsOptions.fileSystemProvider || !this.lsOptions.fileSystemProvider.readDirectory) {
60
- return this.doComplete(document, position, styleSheet, completionSettings);
61
- }
62
- const participant = new pathCompletion_1.PathCompletionParticipant(this.lsOptions.fileSystemProvider.readDirectory);
63
- const contributedParticipants = this.completionParticipants;
64
- this.completionParticipants = [participant].concat(contributedParticipants);
65
- const result = this.doComplete(document, position, styleSheet, completionSettings);
66
- try {
67
- const pathCompletionResult = await participant.computeCompletions(document, documentContext);
68
- return {
69
- isIncomplete: result.isIncomplete || pathCompletionResult.isIncomplete,
70
- itemDefaults: result.itemDefaults,
71
- items: pathCompletionResult.items.concat(result.items)
72
- };
73
- }
74
- finally {
75
- this.completionParticipants = contributedParticipants;
76
- }
77
- }
78
- doComplete(document, position, styleSheet, documentSettings) {
79
- this.offset = document.offsetAt(position);
80
- this.position = position;
81
- this.currentWord = getCurrentWord(document, this.offset);
82
- this.defaultReplaceRange = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(this.position.line, this.position.character - this.currentWord.length), this.position);
83
- this.textDocument = document;
84
- this.styleSheet = styleSheet;
85
- this.documentSettings = documentSettings;
86
- try {
87
- const result = {
88
- isIncomplete: false,
89
- itemDefaults: {
90
- editRange: {
91
- start: { line: position.line, character: position.character - this.currentWord.length },
92
- end: position
93
- }
94
- },
95
- items: []
96
- };
97
- this.nodePath = nodes.getNodePath(this.styleSheet, this.offset);
98
- for (let i = this.nodePath.length - 1; i >= 0; i--) {
99
- const node = this.nodePath[i];
100
- if (node instanceof nodes.Property) {
101
- this.getCompletionsForDeclarationProperty(node.getParent(), result);
102
- }
103
- else if (node instanceof nodes.Expression) {
104
- if (node.parent instanceof nodes.Interpolation) {
105
- this.getVariableProposals(null, result);
106
- }
107
- else {
108
- this.getCompletionsForExpression(node, result);
109
- }
110
- }
111
- else if (node instanceof nodes.SimpleSelector) {
112
- const parentRef = node.findAParent(nodes.NodeType.ExtendsReference, nodes.NodeType.Ruleset);
113
- if (parentRef) {
114
- if (parentRef.type === nodes.NodeType.ExtendsReference) {
115
- this.getCompletionsForExtendsReference(parentRef, node, result);
116
- }
117
- else {
118
- const parentRuleSet = parentRef;
119
- this.getCompletionsForSelector(parentRuleSet, parentRuleSet && parentRuleSet.isNested(), result);
120
- }
121
- }
122
- }
123
- else if (node instanceof nodes.FunctionArgument) {
124
- this.getCompletionsForFunctionArgument(node, node.getParent(), result);
125
- }
126
- else if (node instanceof nodes.Declarations) {
127
- this.getCompletionsForDeclarations(node, result);
128
- }
129
- else if (node instanceof nodes.VariableDeclaration) {
130
- this.getCompletionsForVariableDeclaration(node, result);
131
- }
132
- else if (node instanceof nodes.RuleSet) {
133
- this.getCompletionsForRuleSet(node, result);
134
- }
135
- else if (node instanceof nodes.Interpolation) {
136
- this.getCompletionsForInterpolation(node, result);
137
- }
138
- else if (node instanceof nodes.FunctionDeclaration) {
139
- this.getCompletionsForFunctionDeclaration(node, result);
140
- }
141
- else if (node instanceof nodes.MixinReference) {
142
- this.getCompletionsForMixinReference(node, result);
143
- }
144
- else if (node instanceof nodes.Function) {
145
- this.getCompletionsForFunctionArgument(null, node, result);
146
- }
147
- else if (node instanceof nodes.Supports) {
148
- this.getCompletionsForSupports(node, result);
149
- }
150
- else if (node instanceof nodes.SupportsCondition) {
151
- this.getCompletionsForSupportsCondition(node, result);
152
- }
153
- else if (node instanceof nodes.MediaCondition) {
154
- this.getCompletionsForMediaCondition(node, result);
155
- }
156
- else if (node instanceof nodes.ExtendsReference) {
157
- this.getCompletionsForExtendsReference(node, null, result);
158
- }
159
- else if (node.type === nodes.NodeType.URILiteral) {
160
- this.getCompletionForUriLiteralValue(node, result);
161
- }
162
- else if (node.parent === null) {
163
- this.getCompletionForTopLevel(result);
164
- }
165
- else if (node.type === nodes.NodeType.StringLiteral && this.isImportPathParent(node.parent.type)) {
166
- this.getCompletionForImportPath(node, result);
167
- // } else if (node instanceof nodes.Variable) {
168
- // this.getCompletionsForVariableDeclaration()
169
- }
170
- else {
171
- continue;
172
- }
173
- if (result.items.length > 0 || this.offset > node.offset) {
174
- return this.finalize(result);
175
- }
176
- }
177
- this.getCompletionsForStylesheet(result);
178
- if (result.items.length === 0) {
179
- if (this.variablePrefix && this.currentWord.indexOf(this.variablePrefix) === 0) {
180
- this.getVariableProposals(null, result);
181
- }
182
- }
183
- return this.finalize(result);
184
- }
185
- finally {
186
- // don't hold on any state, clear symbolContext
187
- this.position = null;
188
- this.currentWord = null;
189
- this.textDocument = null;
190
- this.styleSheet = null;
191
- this.symbolContext = null;
192
- this.defaultReplaceRange = null;
193
- this.nodePath = null;
194
- }
195
- }
196
- isImportPathParent(type) {
197
- return type === nodes.NodeType.Import;
198
- }
199
- finalize(result) {
200
- return result;
201
- }
202
- findInNodePath(...types) {
203
- for (let i = this.nodePath.length - 1; i >= 0; i--) {
204
- const node = this.nodePath[i];
205
- if (types.indexOf(node.type) !== -1) {
206
- return node;
207
- }
208
- }
209
- return null;
210
- }
211
- getCompletionsForDeclarationProperty(declaration, result) {
212
- return this.getPropertyProposals(declaration, result);
213
- }
214
- getPropertyProposals(declaration, result) {
215
- const triggerPropertyValueCompletion = this.isTriggerPropertyValueCompletionEnabled;
216
- const completePropertyWithSemicolon = this.isCompletePropertyWithSemicolonEnabled;
217
- const properties = this.cssDataManager.getProperties();
218
- properties.forEach(entry => {
219
- let range;
220
- let insertText;
221
- let retrigger = false;
222
- if (declaration) {
223
- range = this.getCompletionRange(declaration.getProperty());
224
- insertText = entry.name;
225
- if (!(0, objects_1.isDefined)(declaration.colonPosition)) {
226
- insertText += ': ';
227
- retrigger = true;
228
- }
229
- }
230
- else {
231
- range = this.getCompletionRange(null);
232
- insertText = entry.name + ': ';
233
- retrigger = true;
234
- }
235
- // Empty .selector { | } case
236
- if (!declaration && completePropertyWithSemicolon) {
237
- insertText += '$0;';
238
- }
239
- // Cases such as .selector { p; } or .selector { p:; }
240
- if (declaration && !declaration.semicolonPosition) {
241
- if (completePropertyWithSemicolon && this.offset >= this.textDocument.offsetAt(range.end)) {
242
- insertText += '$0;';
243
- }
244
- }
245
- const item = {
246
- label: entry.name,
247
- documentation: languageFacts.getEntryDescription(entry, this.doesSupportMarkdown()),
248
- tags: isDeprecated(entry) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
249
- textEdit: cssLanguageTypes_1.TextEdit.replace(range, insertText),
250
- insertTextFormat: cssLanguageTypes_1.InsertTextFormat.Snippet,
251
- kind: cssLanguageTypes_1.CompletionItemKind.Property
252
- };
253
- if (triggerPropertyValueCompletion && retrigger) {
254
- item.command = retriggerCommand;
255
- }
256
- const relevance = typeof entry.relevance === 'number' ? Math.min(Math.max(entry.relevance, 0), 99) : 50;
257
- const sortTextSuffix = (255 - relevance).toString(16);
258
- const sortTextPrefix = strings.startsWith(entry.name, '-') ? SortTexts.VendorPrefixed : SortTexts.Normal;
259
- item.sortText = sortTextPrefix + '_' + sortTextSuffix;
260
- result.items.push(item);
261
- });
262
- this.completionParticipants.forEach(participant => {
263
- if (participant.onCssProperty) {
264
- participant.onCssProperty({
265
- propertyName: this.currentWord,
266
- range: this.defaultReplaceRange
267
- });
268
- }
269
- });
270
- return result;
271
- }
272
- get isTriggerPropertyValueCompletionEnabled() {
273
- return this.documentSettings?.triggerPropertyValueCompletion ?? true;
274
- }
275
- get isCompletePropertyWithSemicolonEnabled() {
276
- return this.documentSettings?.completePropertyWithSemicolon ?? true;
277
- }
278
- getCompletionsForDeclarationValue(node, result) {
279
- const propertyName = node.getFullPropertyName();
280
- const entry = this.cssDataManager.getProperty(propertyName);
281
- let existingNode = node.getValue() || null;
282
- while (existingNode && existingNode.hasChildren()) {
283
- existingNode = existingNode.findChildAtOffset(this.offset, false);
284
- }
285
- this.completionParticipants.forEach(participant => {
286
- if (participant.onCssPropertyValue) {
287
- participant.onCssPropertyValue({
288
- propertyName,
289
- propertyValue: this.currentWord,
290
- range: this.getCompletionRange(existingNode)
291
- });
292
- }
293
- });
294
- if (entry) {
295
- if (entry.restrictions) {
296
- for (const restriction of entry.restrictions) {
297
- switch (restriction) {
298
- case 'color':
299
- this.getColorProposals(entry, existingNode, result);
300
- break;
301
- case 'position':
302
- this.getPositionProposals(entry, existingNode, result);
303
- break;
304
- case 'repeat':
305
- this.getRepeatStyleProposals(entry, existingNode, result);
306
- break;
307
- case 'line-style':
308
- this.getLineStyleProposals(entry, existingNode, result);
309
- break;
310
- case 'line-width':
311
- this.getLineWidthProposals(entry, existingNode, result);
312
- break;
313
- case 'geometry-box':
314
- this.getGeometryBoxProposals(entry, existingNode, result);
315
- break;
316
- case 'box':
317
- this.getBoxProposals(entry, existingNode, result);
318
- break;
319
- case 'image':
320
- this.getImageProposals(entry, existingNode, result);
321
- break;
322
- case 'timing-function':
323
- this.getTimingFunctionProposals(entry, existingNode, result);
324
- break;
325
- case 'shape':
326
- this.getBasicShapeProposals(entry, existingNode, result);
327
- break;
328
- }
329
- }
330
- }
331
- this.getValueEnumProposals(entry, existingNode, result);
332
- this.getCSSWideKeywordProposals(entry, existingNode, result);
333
- this.getUnitProposals(entry, existingNode, result);
334
- }
335
- else {
336
- const existingValues = collectValues(this.styleSheet, node);
337
- for (const existingValue of existingValues.getEntries()) {
338
- result.items.push({
339
- label: existingValue,
340
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), existingValue),
341
- kind: cssLanguageTypes_1.CompletionItemKind.Value
342
- });
343
- }
344
- }
345
- this.getVariableProposals(existingNode, result);
346
- this.getTermProposals(entry, existingNode, result);
347
- return result;
348
- }
349
- getValueEnumProposals(entry, existingNode, result) {
350
- if (entry.values) {
351
- for (const value of entry.values) {
352
- let insertString = value.name;
353
- let insertTextFormat;
354
- if (strings.endsWith(insertString, ')')) {
355
- const from = insertString.lastIndexOf('(');
356
- if (from !== -1) {
357
- insertString = insertString.substring(0, from + 1) + '$1' + insertString.substring(from + 1);
358
- insertTextFormat = SnippetFormat;
359
- }
360
- }
361
- let sortText = SortTexts.Enums;
362
- if (strings.startsWith(value.name, '-')) {
363
- sortText += SortTexts.VendorPrefixed;
364
- }
365
- const item = {
366
- label: value.name,
367
- documentation: languageFacts.getEntryDescription(value, this.doesSupportMarkdown()),
368
- tags: isDeprecated(entry) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
369
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertString),
370
- sortText,
371
- kind: cssLanguageTypes_1.CompletionItemKind.Value,
372
- insertTextFormat
373
- };
374
- result.items.push(item);
375
- }
376
- }
377
- return result;
378
- }
379
- getCSSWideKeywordProposals(entry, existingNode, result) {
380
- for (const keywords in languageFacts.cssWideKeywords) {
381
- result.items.push({
382
- label: keywords,
383
- documentation: languageFacts.cssWideKeywords[keywords],
384
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), keywords),
385
- kind: cssLanguageTypes_1.CompletionItemKind.Value
386
- });
387
- }
388
- for (const func in languageFacts.cssWideFunctions) {
389
- const insertText = moveCursorInsideParenthesis(func);
390
- result.items.push({
391
- label: func,
392
- documentation: languageFacts.cssWideFunctions[func],
393
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
394
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
395
- insertTextFormat: SnippetFormat,
396
- command: strings.startsWith(func, 'var') ? retriggerCommand : undefined
397
- });
398
- }
399
- return result;
400
- }
401
- getCompletionsForInterpolation(node, result) {
402
- if (this.offset >= node.offset + 2) {
403
- this.getVariableProposals(null, result);
404
- }
405
- return result;
406
- }
407
- getVariableProposals(existingNode, result) {
408
- const symbols = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Variable);
409
- for (const symbol of symbols) {
410
- const insertText = strings.startsWith(symbol.name, '--') ? `var(${symbol.name})` : symbol.name;
411
- const completionItem = {
412
- label: symbol.name,
413
- documentation: symbol.value ? strings.getLimitedString(symbol.value) : symbol.value,
414
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
415
- kind: cssLanguageTypes_1.CompletionItemKind.Variable,
416
- sortText: SortTexts.Variable
417
- };
418
- if (typeof completionItem.documentation === 'string' && languageFacts.isColorString(completionItem.documentation)) {
419
- completionItem.kind = cssLanguageTypes_1.CompletionItemKind.Color;
420
- }
421
- if (symbol.node.type === nodes.NodeType.FunctionParameter) {
422
- const mixinNode = (symbol.node.getParent());
423
- if (mixinNode.type === nodes.NodeType.MixinDeclaration) {
424
- completionItem.detail = l10n.t('argument from \'{0}\'', mixinNode.getName());
425
- }
426
- }
427
- result.items.push(completionItem);
428
- }
429
- return result;
430
- }
431
- getVariableProposalsForCSSVarFunction(result) {
432
- const allReferencedVariables = new Set();
433
- this.styleSheet.acceptVisitor(new VariableCollector(allReferencedVariables, this.offset));
434
- let symbols = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Variable);
435
- for (const symbol of symbols) {
436
- if (strings.startsWith(symbol.name, '--')) {
437
- const completionItem = {
438
- label: symbol.name,
439
- documentation: symbol.value ? strings.getLimitedString(symbol.value) : symbol.value,
440
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(null), symbol.name),
441
- kind: cssLanguageTypes_1.CompletionItemKind.Variable
442
- };
443
- if (typeof completionItem.documentation === 'string' && languageFacts.isColorString(completionItem.documentation)) {
444
- completionItem.kind = cssLanguageTypes_1.CompletionItemKind.Color;
445
- }
446
- result.items.push(completionItem);
447
- }
448
- allReferencedVariables.remove(symbol.name);
449
- }
450
- for (const name of allReferencedVariables.getEntries()) {
451
- if (strings.startsWith(name, '--')) {
452
- const completionItem = {
453
- label: name,
454
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(null), name),
455
- kind: cssLanguageTypes_1.CompletionItemKind.Variable
456
- };
457
- result.items.push(completionItem);
458
- }
459
- }
460
- return result;
461
- }
462
- getUnitProposals(entry, existingNode, result) {
463
- let currentWord = '0';
464
- if (this.currentWord.length > 0) {
465
- const numMatch = this.currentWord.match(/^-?\d[\.\d+]*/);
466
- if (numMatch) {
467
- currentWord = numMatch[0];
468
- result.isIncomplete = currentWord.length === this.currentWord.length;
469
- }
470
- }
471
- else if (this.currentWord.length === 0) {
472
- result.isIncomplete = true;
473
- }
474
- if (existingNode && existingNode.parent && existingNode.parent.type === nodes.NodeType.Term) {
475
- existingNode = existingNode.getParent(); // include the unary operator
476
- }
477
- if (entry.restrictions) {
478
- for (const restriction of entry.restrictions) {
479
- const units = languageFacts.units[restriction];
480
- if (units) {
481
- for (const unit of units) {
482
- const insertText = currentWord + unit;
483
- result.items.push({
484
- label: insertText,
485
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
486
- kind: cssLanguageTypes_1.CompletionItemKind.Unit
487
- });
488
- }
489
- }
490
- }
491
- }
492
- return result;
493
- }
494
- getCompletionRange(existingNode) {
495
- if (existingNode && existingNode.offset <= this.offset && this.offset <= existingNode.end) {
496
- const end = existingNode.end !== -1 ? this.textDocument.positionAt(existingNode.end) : this.position;
497
- const start = this.textDocument.positionAt(existingNode.offset);
498
- if (start.line === end.line) {
499
- return cssLanguageTypes_1.Range.create(start, end); // multi line edits are not allowed
500
- }
501
- }
502
- return this.defaultReplaceRange;
503
- }
504
- getColorProposals(entry, existingNode, result) {
505
- for (const color in languageFacts.colors) {
506
- result.items.push({
507
- label: color,
508
- documentation: languageFacts.colors[color],
509
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), color),
510
- kind: cssLanguageTypes_1.CompletionItemKind.Color
511
- });
512
- }
513
- for (const color in languageFacts.colorKeywords) {
514
- result.items.push({
515
- label: color,
516
- documentation: languageFacts.colorKeywords[color],
517
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), color),
518
- kind: cssLanguageTypes_1.CompletionItemKind.Value
519
- });
520
- }
521
- const colorValues = new Set();
522
- this.styleSheet.acceptVisitor(new ColorValueCollector(colorValues, this.offset));
523
- for (const color of colorValues.getEntries()) {
524
- result.items.push({
525
- label: color,
526
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), color),
527
- kind: cssLanguageTypes_1.CompletionItemKind.Color
528
- });
529
- }
530
- for (const p of languageFacts.colorFunctions) {
531
- result.items.push({
532
- label: p.label,
533
- detail: p.func,
534
- documentation: p.desc,
535
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), p.insertText),
536
- insertTextFormat: SnippetFormat,
537
- kind: cssLanguageTypes_1.CompletionItemKind.Function
538
- });
539
- }
540
- return result;
541
- }
542
- getPositionProposals(entry, existingNode, result) {
543
- for (const position in languageFacts.positionKeywords) {
544
- result.items.push({
545
- label: position,
546
- documentation: languageFacts.positionKeywords[position],
547
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), position),
548
- kind: cssLanguageTypes_1.CompletionItemKind.Value
549
- });
550
- }
551
- return result;
552
- }
553
- getRepeatStyleProposals(entry, existingNode, result) {
554
- for (const repeat in languageFacts.repeatStyleKeywords) {
555
- result.items.push({
556
- label: repeat,
557
- documentation: languageFacts.repeatStyleKeywords[repeat],
558
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), repeat),
559
- kind: cssLanguageTypes_1.CompletionItemKind.Value
560
- });
561
- }
562
- return result;
563
- }
564
- getLineStyleProposals(entry, existingNode, result) {
565
- for (const lineStyle in languageFacts.lineStyleKeywords) {
566
- result.items.push({
567
- label: lineStyle,
568
- documentation: languageFacts.lineStyleKeywords[lineStyle],
569
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), lineStyle),
570
- kind: cssLanguageTypes_1.CompletionItemKind.Value
571
- });
572
- }
573
- return result;
574
- }
575
- getLineWidthProposals(entry, existingNode, result) {
576
- for (const lineWidth of languageFacts.lineWidthKeywords) {
577
- result.items.push({
578
- label: lineWidth,
579
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), lineWidth),
580
- kind: cssLanguageTypes_1.CompletionItemKind.Value
581
- });
582
- }
583
- return result;
584
- }
585
- getGeometryBoxProposals(entry, existingNode, result) {
586
- for (const box in languageFacts.geometryBoxKeywords) {
587
- result.items.push({
588
- label: box,
589
- documentation: languageFacts.geometryBoxKeywords[box],
590
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), box),
591
- kind: cssLanguageTypes_1.CompletionItemKind.Value
592
- });
593
- }
594
- return result;
595
- }
596
- getBoxProposals(entry, existingNode, result) {
597
- for (const box in languageFacts.boxKeywords) {
598
- result.items.push({
599
- label: box,
600
- documentation: languageFacts.boxKeywords[box],
601
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), box),
602
- kind: cssLanguageTypes_1.CompletionItemKind.Value
603
- });
604
- }
605
- return result;
606
- }
607
- getImageProposals(entry, existingNode, result) {
608
- for (const image in languageFacts.imageFunctions) {
609
- const insertText = moveCursorInsideParenthesis(image);
610
- result.items.push({
611
- label: image,
612
- documentation: languageFacts.imageFunctions[image],
613
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
614
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
615
- insertTextFormat: image !== insertText ? SnippetFormat : void 0
616
- });
617
- }
618
- return result;
619
- }
620
- getTimingFunctionProposals(entry, existingNode, result) {
621
- for (const timing in languageFacts.transitionTimingFunctions) {
622
- const insertText = moveCursorInsideParenthesis(timing);
623
- result.items.push({
624
- label: timing,
625
- documentation: languageFacts.transitionTimingFunctions[timing],
626
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
627
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
628
- insertTextFormat: timing !== insertText ? SnippetFormat : void 0
629
- });
630
- }
631
- return result;
632
- }
633
- getBasicShapeProposals(entry, existingNode, result) {
634
- for (const shape in languageFacts.basicShapeFunctions) {
635
- const insertText = moveCursorInsideParenthesis(shape);
636
- result.items.push({
637
- label: shape,
638
- documentation: languageFacts.basicShapeFunctions[shape],
639
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
640
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
641
- insertTextFormat: shape !== insertText ? SnippetFormat : void 0
642
- });
643
- }
644
- return result;
645
- }
646
- getCompletionsForStylesheet(result) {
647
- const node = this.styleSheet.findFirstChildBeforeOffset(this.offset);
648
- if (!node) {
649
- return this.getCompletionForTopLevel(result);
650
- }
651
- if (node instanceof nodes.RuleSet) {
652
- return this.getCompletionsForRuleSet(node, result);
653
- }
654
- if (node instanceof nodes.Supports) {
655
- return this.getCompletionsForSupports(node, result);
656
- }
657
- return result;
658
- }
659
- getCompletionForTopLevel(result) {
660
- this.cssDataManager.getAtDirectives().forEach(entry => {
661
- result.items.push({
662
- label: entry.name,
663
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(null), entry.name),
664
- documentation: languageFacts.getEntryDescription(entry, this.doesSupportMarkdown()),
665
- tags: isDeprecated(entry) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
666
- kind: cssLanguageTypes_1.CompletionItemKind.Keyword
667
- });
668
- });
669
- this.getCompletionsForSelector(null, false, result);
670
- return result;
671
- }
672
- getCompletionsForRuleSet(ruleSet, result) {
673
- const declarations = ruleSet.getDeclarations();
674
- const isAfter = declarations && declarations.endsWith('}') && this.offset >= declarations.end;
675
- if (isAfter) {
676
- return this.getCompletionForTopLevel(result);
677
- }
678
- const isInSelectors = !declarations || this.offset <= declarations.offset;
679
- if (isInSelectors) {
680
- return this.getCompletionsForSelector(ruleSet, ruleSet.isNested(), result);
681
- }
682
- return this.getCompletionsForDeclarations(ruleSet.getDeclarations(), result);
683
- }
684
- getCompletionsForSelector(ruleSet, isNested, result) {
685
- const existingNode = this.findInNodePath(nodes.NodeType.PseudoSelector, nodes.NodeType.IdentifierSelector, nodes.NodeType.ClassSelector, nodes.NodeType.ElementNameSelector);
686
- if (!existingNode && this.hasCharacterAtPosition(this.offset - this.currentWord.length - 1, ':')) {
687
- // after the ':' of a pseudo selector, no node generated for just ':'
688
- this.currentWord = ':' + this.currentWord;
689
- if (this.hasCharacterAtPosition(this.offset - this.currentWord.length - 1, ':')) {
690
- this.currentWord = ':' + this.currentWord; // for '::'
691
- }
692
- this.defaultReplaceRange = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(this.position.line, this.position.character - this.currentWord.length), this.position);
693
- }
694
- const pseudoClasses = this.cssDataManager.getPseudoClasses();
695
- pseudoClasses.forEach(entry => {
696
- const insertText = moveCursorInsideParenthesis(entry.name);
697
- const item = {
698
- label: entry.name,
699
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
700
- documentation: languageFacts.getEntryDescription(entry, this.doesSupportMarkdown()),
701
- tags: isDeprecated(entry) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
702
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
703
- insertTextFormat: entry.name !== insertText ? SnippetFormat : void 0
704
- };
705
- if (strings.startsWith(entry.name, ':-')) {
706
- item.sortText = SortTexts.VendorPrefixed;
707
- }
708
- result.items.push(item);
709
- });
710
- const pseudoElements = this.cssDataManager.getPseudoElements();
711
- pseudoElements.forEach(entry => {
712
- const insertText = moveCursorInsideParenthesis(entry.name);
713
- const item = {
714
- label: entry.name,
715
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
716
- documentation: languageFacts.getEntryDescription(entry, this.doesSupportMarkdown()),
717
- tags: isDeprecated(entry) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
718
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
719
- insertTextFormat: entry.name !== insertText ? SnippetFormat : void 0
720
- };
721
- if (strings.startsWith(entry.name, '::-')) {
722
- item.sortText = SortTexts.VendorPrefixed;
723
- }
724
- result.items.push(item);
725
- });
726
- if (!isNested) { // show html tags only for top level
727
- for (const entry of languageFacts.html5Tags) {
728
- result.items.push({
729
- label: entry,
730
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), entry),
731
- kind: cssLanguageTypes_1.CompletionItemKind.Keyword
732
- });
733
- }
734
- for (const entry of languageFacts.svgElements) {
735
- result.items.push({
736
- label: entry,
737
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), entry),
738
- kind: cssLanguageTypes_1.CompletionItemKind.Keyword
739
- });
740
- }
741
- }
742
- const visited = {};
743
- visited[this.currentWord] = true;
744
- const docText = this.textDocument.getText();
745
- this.styleSheet.accept(n => {
746
- if (n.type === nodes.NodeType.SimpleSelector && n.length > 0) {
747
- const selector = docText.substr(n.offset, n.length);
748
- if (selector.charAt(0) === '.' && !visited[selector]) {
749
- visited[selector] = true;
750
- result.items.push({
751
- label: selector,
752
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), selector),
753
- kind: cssLanguageTypes_1.CompletionItemKind.Keyword
754
- });
755
- }
756
- return false;
757
- }
758
- return true;
759
- });
760
- if (ruleSet && ruleSet.isNested()) {
761
- const selector = ruleSet.getSelectors().findFirstChildBeforeOffset(this.offset);
762
- if (selector && ruleSet.getSelectors().getChildren().indexOf(selector) === 0) {
763
- this.getPropertyProposals(null, result);
764
- }
765
- }
766
- return result;
767
- }
768
- getCompletionsForDeclarations(declarations, result) {
769
- if (!declarations || this.offset === declarations.offset) { // incomplete nodes
770
- return result;
771
- }
772
- const node = declarations.findFirstChildBeforeOffset(this.offset);
773
- if (!node) {
774
- return this.getCompletionsForDeclarationProperty(null, result);
775
- }
776
- if (node instanceof nodes.AbstractDeclaration) {
777
- const declaration = node;
778
- if (!(0, objects_1.isDefined)(declaration.colonPosition) || this.offset <= declaration.colonPosition) {
779
- // complete property
780
- return this.getCompletionsForDeclarationProperty(declaration, result);
781
- }
782
- else if (((0, objects_1.isDefined)(declaration.semicolonPosition) && declaration.semicolonPosition < this.offset)) {
783
- if (this.offset === declaration.semicolonPosition + 1) {
784
- return result; // don't show new properties right after semicolon (see Bug 15421:[intellisense] [css] Be less aggressive when manually typing CSS)
785
- }
786
- // complete next property
787
- return this.getCompletionsForDeclarationProperty(null, result);
788
- }
789
- if (declaration instanceof nodes.Declaration) {
790
- // complete value
791
- return this.getCompletionsForDeclarationValue(declaration, result);
792
- }
793
- }
794
- else if (node instanceof nodes.ExtendsReference) {
795
- this.getCompletionsForExtendsReference(node, null, result);
796
- }
797
- else if (this.currentWord && this.currentWord[0] === '@') {
798
- this.getCompletionsForDeclarationProperty(null, result);
799
- }
800
- else if (node instanceof nodes.RuleSet) {
801
- this.getCompletionsForDeclarationProperty(null, result);
802
- }
803
- return result;
804
- }
805
- getCompletionsForVariableDeclaration(declaration, result) {
806
- if (this.offset && (0, objects_1.isDefined)(declaration.colonPosition) && this.offset > declaration.colonPosition) {
807
- this.getVariableProposals(declaration.getValue() || null, result);
808
- }
809
- return result;
810
- }
811
- getCompletionsForExpression(expression, result) {
812
- const parent = expression.getParent();
813
- if (parent instanceof nodes.FunctionArgument) {
814
- this.getCompletionsForFunctionArgument(parent, parent.getParent(), result);
815
- return result;
816
- }
817
- const declaration = expression.findParent(nodes.NodeType.Declaration);
818
- if (!declaration) {
819
- this.getTermProposals(undefined, null, result);
820
- return result;
821
- }
822
- const node = expression.findChildAtOffset(this.offset, true);
823
- if (!node) {
824
- return this.getCompletionsForDeclarationValue(declaration, result);
825
- }
826
- if (node instanceof nodes.NumericValue || node instanceof nodes.Identifier) {
827
- return this.getCompletionsForDeclarationValue(declaration, result);
828
- }
829
- return result;
830
- }
831
- getCompletionsForFunctionArgument(arg, func, result) {
832
- const identifier = func.getIdentifier();
833
- if (identifier && identifier.matches('var')) {
834
- if (!func.getArguments().hasChildren() || func.getArguments().getChild(0) === arg) {
835
- this.getVariableProposalsForCSSVarFunction(result);
836
- }
837
- }
838
- return result;
839
- }
840
- getCompletionsForFunctionDeclaration(decl, result) {
841
- const declarations = decl.getDeclarations();
842
- if (declarations && this.offset > declarations.offset && this.offset < declarations.end) {
843
- this.getTermProposals(undefined, null, result);
844
- }
845
- return result;
846
- }
847
- getCompletionsForMixinReference(ref, result) {
848
- const allMixins = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Mixin);
849
- for (const mixinSymbol of allMixins) {
850
- if (mixinSymbol.node instanceof nodes.MixinDeclaration) {
851
- result.items.push(this.makeTermProposal(mixinSymbol, mixinSymbol.node.getParameters(), null));
852
- }
853
- }
854
- const identifierNode = ref.getIdentifier() || null;
855
- this.completionParticipants.forEach(participant => {
856
- if (participant.onCssMixinReference) {
857
- participant.onCssMixinReference({
858
- mixinName: this.currentWord,
859
- range: this.getCompletionRange(identifierNode)
860
- });
861
- }
862
- });
863
- return result;
864
- }
865
- getTermProposals(entry, existingNode, result) {
866
- const allFunctions = this.getSymbolContext().findSymbolsAtOffset(this.offset, nodes.ReferenceType.Function);
867
- for (const functionSymbol of allFunctions) {
868
- if (functionSymbol.node instanceof nodes.FunctionDeclaration) {
869
- result.items.push(this.makeTermProposal(functionSymbol, functionSymbol.node.getParameters(), existingNode));
870
- }
871
- }
872
- return result;
873
- }
874
- makeTermProposal(symbol, parameters, existingNode) {
875
- const decl = symbol.node;
876
- const params = parameters.getChildren().map((c) => {
877
- return (c instanceof nodes.FunctionParameter) ? c.getName() : c.getText();
878
- });
879
- const insertText = symbol.name + '(' + params.map((p, index) => '${' + (index + 1) + ':' + p + '}').join(', ') + ')';
880
- return {
881
- label: symbol.name,
882
- detail: symbol.name + '(' + params.join(', ') + ')',
883
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(existingNode), insertText),
884
- insertTextFormat: SnippetFormat,
885
- kind: cssLanguageTypes_1.CompletionItemKind.Function,
886
- sortText: SortTexts.Term
887
- };
888
- }
889
- getCompletionsForSupportsCondition(supportsCondition, result) {
890
- const child = supportsCondition.findFirstChildBeforeOffset(this.offset);
891
- if (child) {
892
- if (child instanceof nodes.Declaration) {
893
- if (!(0, objects_1.isDefined)(child.colonPosition) || this.offset <= child.colonPosition) {
894
- return this.getCompletionsForDeclarationProperty(child, result);
895
- }
896
- else {
897
- return this.getCompletionsForDeclarationValue(child, result);
898
- }
899
- }
900
- else if (child instanceof nodes.SupportsCondition) {
901
- return this.getCompletionsForSupportsCondition(child, result);
902
- }
903
- }
904
- if ((0, objects_1.isDefined)(supportsCondition.lParent) && this.offset > supportsCondition.lParent && (!(0, objects_1.isDefined)(supportsCondition.rParent) || this.offset <= supportsCondition.rParent)) {
905
- return this.getCompletionsForDeclarationProperty(null, result);
906
- }
907
- return result;
908
- }
909
- getCompletionsForSupports(supports, result) {
910
- const declarations = supports.getDeclarations();
911
- const inInCondition = !declarations || this.offset <= declarations.offset;
912
- if (inInCondition) {
913
- const child = supports.findFirstChildBeforeOffset(this.offset);
914
- if (child instanceof nodes.SupportsCondition) {
915
- return this.getCompletionsForSupportsCondition(child, result);
916
- }
917
- return result;
918
- }
919
- return this.getCompletionForTopLevel(result);
920
- }
921
- getCompletionsForMediaCondition(mediaCondition, result) {
922
- const child = mediaCondition.findFirstChildBeforeOffset(this.offset);
923
- if (child) {
924
- if (child instanceof nodes.MediaFeature) {
925
- const featureName = child.getChild(0);
926
- if (featureName && this.offset > featureName.end) {
927
- const name = featureName.getText();
928
- const media = this.cssDataManager.getAtDirective('@media')?.descriptors?.find((descriptor) => descriptor.name === name);
929
- if (media) {
930
- return this.getValueEnumProposals(media, null, result);
931
- }
932
- }
933
- }
934
- else if (child instanceof nodes.MediaCondition) {
935
- return this.getCompletionsForMediaCondition(child, result);
936
- }
937
- }
938
- // Return all media descriptors
939
- const media = this.cssDataManager.getAtDirective('@media');
940
- for (const descriptor of media?.descriptors || []) {
941
- let command = undefined;
942
- let text = descriptor.name;
943
- if (descriptor.type === 'discrete') {
944
- // Change this check when we support auto completes for other types
945
- if (descriptor.values) {
946
- command = retriggerCommand;
947
- }
948
- text = `${descriptor.name}: `;
949
- }
950
- result.items.push({
951
- label: descriptor.name,
952
- textEdit: cssLanguageTypes_1.TextEdit.replace(this.getCompletionRange(null), text),
953
- documentation: languageFacts.getEntryDescription(descriptor, this.doesSupportMarkdown()),
954
- tags: isDeprecated(descriptor) ? [cssLanguageTypes_1.CompletionItemTag.Deprecated] : [],
955
- kind: cssLanguageTypes_1.CompletionItemKind.Keyword,
956
- command,
957
- });
958
- }
959
- return result;
960
- }
961
- getCompletionsForExtendsReference(extendsRef, existingNode, result) {
962
- return result;
963
- }
964
- getCompletionForUriLiteralValue(uriLiteralNode, result) {
965
- let uriValue;
966
- let position;
967
- let range;
968
- // No children, empty value
969
- if (!uriLiteralNode.hasChildren()) {
970
- uriValue = '';
971
- position = this.position;
972
- const emptyURIValuePosition = this.textDocument.positionAt(uriLiteralNode.offset + 'url('.length);
973
- range = cssLanguageTypes_1.Range.create(emptyURIValuePosition, emptyURIValuePosition);
974
- }
975
- else {
976
- const uriValueNode = uriLiteralNode.getChild(0);
977
- uriValue = uriValueNode.getText();
978
- position = this.position;
979
- range = this.getCompletionRange(uriValueNode);
980
- }
981
- this.completionParticipants.forEach(participant => {
982
- if (participant.onCssURILiteralValue) {
983
- participant.onCssURILiteralValue({
984
- uriValue,
985
- position,
986
- range
987
- });
988
- }
989
- });
990
- return result;
991
- }
992
- getCompletionForImportPath(importPathNode, result) {
993
- this.completionParticipants.forEach(participant => {
994
- if (participant.onCssImportPath) {
995
- participant.onCssImportPath({
996
- pathValue: importPathNode.getText(),
997
- position: this.position,
998
- range: this.getCompletionRange(importPathNode)
999
- });
1000
- }
1001
- });
1002
- return result;
1003
- }
1004
- hasCharacterAtPosition(offset, char) {
1005
- const text = this.textDocument.getText();
1006
- return (offset >= 0 && offset < text.length) && text.charAt(offset) === char;
1007
- }
1008
- doesSupportMarkdown() {
1009
- if (!(0, objects_1.isDefined)(this.supportsMarkdown)) {
1010
- if (!(0, objects_1.isDefined)(this.lsOptions.clientCapabilities)) {
1011
- this.supportsMarkdown = true;
1012
- return this.supportsMarkdown;
1013
- }
1014
- const documentationFormat = this.lsOptions.clientCapabilities.textDocument?.completion?.completionItem?.documentationFormat;
1015
- this.supportsMarkdown = Array.isArray(documentationFormat) && documentationFormat.indexOf(cssLanguageTypes_1.MarkupKind.Markdown) !== -1;
1016
- }
1017
- return this.supportsMarkdown;
1018
- }
1019
- }
1020
- exports.CSSCompletion = CSSCompletion;
1021
- function isDeprecated(entry) {
1022
- if (entry.status && (entry.status === 'nonstandard' || entry.status === 'obsolete')) {
1023
- return true;
1024
- }
1025
- return false;
1026
- }
1027
- class Set {
1028
- constructor() {
1029
- this.entries = {};
1030
- }
1031
- add(entry) {
1032
- this.entries[entry] = true;
1033
- }
1034
- remove(entry) {
1035
- delete this.entries[entry];
1036
- }
1037
- getEntries() {
1038
- return Object.keys(this.entries);
1039
- }
1040
- }
1041
- function moveCursorInsideParenthesis(text) {
1042
- return text.replace(/\(\)$/, "($1)");
1043
- }
1044
- function collectValues(styleSheet, declaration) {
1045
- const fullPropertyName = declaration.getFullPropertyName();
1046
- const entries = new Set();
1047
- function visitValue(node) {
1048
- if (node instanceof nodes.Identifier || node instanceof nodes.NumericValue || node instanceof nodes.HexColorValue) {
1049
- entries.add(node.getText());
1050
- }
1051
- return true;
1052
- }
1053
- function matchesProperty(decl) {
1054
- const propertyName = decl.getFullPropertyName();
1055
- return fullPropertyName === propertyName;
1056
- }
1057
- function vistNode(node) {
1058
- if (node instanceof nodes.Declaration && node !== declaration) {
1059
- if (matchesProperty(node)) {
1060
- const value = node.getValue();
1061
- if (value) {
1062
- value.accept(visitValue);
1063
- }
1064
- }
1065
- }
1066
- return true;
1067
- }
1068
- styleSheet.accept(vistNode);
1069
- return entries;
1070
- }
1071
- class ColorValueCollector {
1072
- constructor(entries, currentOffset) {
1073
- this.entries = entries;
1074
- this.currentOffset = currentOffset;
1075
- // nothing to do
1076
- }
1077
- visitNode(node) {
1078
- if (node instanceof nodes.HexColorValue || (node instanceof nodes.Function && languageFacts.isColorConstructor(node))) {
1079
- if (this.currentOffset < node.offset || node.end < this.currentOffset) {
1080
- this.entries.add(node.getText());
1081
- }
1082
- }
1083
- return true;
1084
- }
1085
- }
1086
- class VariableCollector {
1087
- constructor(entries, currentOffset) {
1088
- this.entries = entries;
1089
- this.currentOffset = currentOffset;
1090
- // nothing to do
1091
- }
1092
- visitNode(node) {
1093
- if (node instanceof nodes.Identifier && node.isCustomProperty) {
1094
- if (this.currentOffset < node.offset || node.end < this.currentOffset) {
1095
- this.entries.add(node.getText());
1096
- }
1097
- }
1098
- return true;
1099
- }
1100
- }
1101
- function getCurrentWord(document, offset) {
1102
- let i = offset - 1;
1103
- const text = document.getText();
1104
- while (i >= 0 && ' \t\n\r":{[()]},*>+'.indexOf(text.charAt(i)) === -1) {
1105
- i--;
1106
- }
1107
- return text.substring(i + 1, offset);
1108
- }
1109
- });