vscode-css-languageservice 5.4.1 → 6.0.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 (87) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +1 -0
  3. package/lib/esm/beautify/beautify-css.js +50 -8
  4. package/lib/esm/cssLanguageService.d.ts +37 -37
  5. package/lib/esm/cssLanguageService.js +72 -75
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +21959 -21965
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -472
  11. package/lib/esm/languageFacts/dataManager.js +88 -92
  12. package/lib/esm/languageFacts/dataProvider.js +73 -79
  13. package/lib/esm/languageFacts/entry.js +137 -138
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -50
  16. package/lib/esm/parser/cssNodes.js +1502 -2019
  17. package/lib/esm/parser/cssParser.js +1534 -1566
  18. package/lib/esm/parser/cssScanner.js +592 -599
  19. package/lib/esm/parser/cssSymbolScope.js +311 -341
  20. package/lib/esm/parser/lessParser.js +714 -740
  21. package/lib/esm/parser/lessScanner.js +57 -78
  22. package/lib/esm/parser/scssErrors.js +18 -20
  23. package/lib/esm/parser/scssParser.js +796 -818
  24. package/lib/esm/parser/scssScanner.js +95 -116
  25. package/lib/esm/services/cssCodeActions.js +77 -81
  26. package/lib/esm/services/cssCompletion.js +1054 -1149
  27. package/lib/esm/services/cssFolding.js +190 -193
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -151
  30. package/lib/esm/services/cssNavigation.js +378 -470
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -44
  33. package/lib/esm/services/lessCompletion.js +378 -397
  34. package/lib/esm/services/lint.js +518 -532
  35. package/lib/esm/services/lintRules.js +76 -83
  36. package/lib/esm/services/lintUtil.js +196 -205
  37. package/lib/esm/services/pathCompletion.js +157 -231
  38. package/lib/esm/services/scssCompletion.js +354 -378
  39. package/lib/esm/services/scssNavigation.js +82 -154
  40. package/lib/esm/services/selectorPrinting.js +492 -536
  41. package/lib/esm/utils/arrays.js +40 -46
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -24
  44. package/lib/esm/utils/strings.js +102 -104
  45. package/lib/umd/beautify/beautify-css.js +50 -8
  46. package/lib/umd/cssLanguageService.d.ts +37 -37
  47. package/lib/umd/cssLanguageService.js +99 -102
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -88
  50. package/lib/umd/data/webCustomData.js +21972 -21978
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -495
  53. package/lib/umd/languageFacts/dataManager.js +101 -104
  54. package/lib/umd/languageFacts/dataProvider.js +86 -91
  55. package/lib/umd/languageFacts/entry.js +152 -153
  56. package/lib/umd/languageFacts/facts.js +29 -29
  57. package/lib/umd/parser/cssErrors.js +61 -62
  58. package/lib/umd/parser/cssNodes.js +1587 -2034
  59. package/lib/umd/parser/cssParser.js +1547 -1578
  60. package/lib/umd/parser/cssScanner.js +606 -611
  61. package/lib/umd/parser/cssSymbolScope.js +328 -353
  62. package/lib/umd/parser/lessParser.js +727 -752
  63. package/lib/umd/parser/lessScanner.js +70 -90
  64. package/lib/umd/parser/scssErrors.js +31 -32
  65. package/lib/umd/parser/scssParser.js +809 -830
  66. package/lib/umd/parser/scssScanner.js +108 -128
  67. package/lib/umd/services/cssCodeActions.js +90 -93
  68. package/lib/umd/services/cssCompletion.js +1067 -1161
  69. package/lib/umd/services/cssFolding.js +203 -206
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -163
  72. package/lib/umd/services/cssNavigation.js +391 -482
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -56
  75. package/lib/umd/services/lessCompletion.js +391 -409
  76. package/lib/umd/services/lint.js +531 -544
  77. package/lib/umd/services/lintRules.js +91 -95
  78. package/lib/umd/services/lintUtil.js +210 -218
  79. package/lib/umd/services/pathCompletion.js +171 -244
  80. package/lib/umd/services/scssCompletion.js +367 -390
  81. package/lib/umd/services/scssNavigation.js +95 -166
  82. package/lib/umd/services/selectorPrinting.js +510 -550
  83. package/lib/umd/utils/arrays.js +55 -61
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -39
  86. package/lib/umd/utils/strings.js +120 -122
  87. package/package.json +11 -11
@@ -1,231 +1,157 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License. See License.txt in the project root for license information.
4
- *--------------------------------------------------------------------------------------------*/
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- var __generator = (this && this.__generator) || function (thisArg, body) {
15
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
16
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17
- function verb(n) { return function (v) { return step([n, v]); }; }
18
- function step(op) {
19
- if (f) throw new TypeError("Generator is already executing.");
20
- while (_) try {
21
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22
- if (y = 0, t) op = [op[0] & 2, t.value];
23
- switch (op[0]) {
24
- case 0: case 1: t = op; break;
25
- case 4: _.label++; return { value: op[1], done: false };
26
- case 5: _.label++; y = op[1]; op = [0]; continue;
27
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
28
- default:
29
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
30
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
31
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
32
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
33
- if (t[2]) _.ops.pop();
34
- _.trys.pop(); continue;
35
- }
36
- op = body.call(thisArg, _);
37
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
38
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
39
- }
40
- };
41
- import { FileType, CompletionItemKind, TextEdit, Range, Position } from '../cssLanguageTypes';
42
- import { startsWith, endsWith } from '../utils/strings';
43
- import { joinPath } from '../utils/resources';
44
- var PathCompletionParticipant = /** @class */ (function () {
45
- function PathCompletionParticipant(readDirectory) {
46
- this.readDirectory = readDirectory;
47
- this.literalCompletions = [];
48
- this.importCompletions = [];
49
- }
50
- PathCompletionParticipant.prototype.onCssURILiteralValue = function (context) {
51
- this.literalCompletions.push(context);
52
- };
53
- PathCompletionParticipant.prototype.onCssImportPath = function (context) {
54
- this.importCompletions.push(context);
55
- };
56
- PathCompletionParticipant.prototype.computeCompletions = function (document, documentContext) {
57
- return __awaiter(this, void 0, void 0, function () {
58
- var result, _i, _a, literalCompletion, uriValue, fullValue, items, _b, items_1, item, _c, _d, importCompletion, pathValue, fullValue, suggestions, _e, suggestions_1, item;
59
- return __generator(this, function (_f) {
60
- switch (_f.label) {
61
- case 0:
62
- result = { items: [], isIncomplete: false };
63
- _i = 0, _a = this.literalCompletions;
64
- _f.label = 1;
65
- case 1:
66
- if (!(_i < _a.length)) return [3 /*break*/, 5];
67
- literalCompletion = _a[_i];
68
- uriValue = literalCompletion.uriValue;
69
- fullValue = stripQuotes(uriValue);
70
- if (!(fullValue === '.' || fullValue === '..')) return [3 /*break*/, 2];
71
- result.isIncomplete = true;
72
- return [3 /*break*/, 4];
73
- case 2: return [4 /*yield*/, this.providePathSuggestions(uriValue, literalCompletion.position, literalCompletion.range, document, documentContext)];
74
- case 3:
75
- items = _f.sent();
76
- for (_b = 0, items_1 = items; _b < items_1.length; _b++) {
77
- item = items_1[_b];
78
- result.items.push(item);
79
- }
80
- _f.label = 4;
81
- case 4:
82
- _i++;
83
- return [3 /*break*/, 1];
84
- case 5:
85
- _c = 0, _d = this.importCompletions;
86
- _f.label = 6;
87
- case 6:
88
- if (!(_c < _d.length)) return [3 /*break*/, 10];
89
- importCompletion = _d[_c];
90
- pathValue = importCompletion.pathValue;
91
- fullValue = stripQuotes(pathValue);
92
- if (!(fullValue === '.' || fullValue === '..')) return [3 /*break*/, 7];
93
- result.isIncomplete = true;
94
- return [3 /*break*/, 9];
95
- case 7: return [4 /*yield*/, this.providePathSuggestions(pathValue, importCompletion.position, importCompletion.range, document, documentContext)];
96
- case 8:
97
- suggestions = _f.sent();
98
- if (document.languageId === 'scss') {
99
- suggestions.forEach(function (s) {
100
- if (startsWith(s.label, '_') && endsWith(s.label, '.scss')) {
101
- if (s.textEdit) {
102
- s.textEdit.newText = s.label.slice(1, -5);
103
- }
104
- else {
105
- s.label = s.label.slice(1, -5);
106
- }
107
- }
108
- });
109
- }
110
- for (_e = 0, suggestions_1 = suggestions; _e < suggestions_1.length; _e++) {
111
- item = suggestions_1[_e];
112
- result.items.push(item);
113
- }
114
- _f.label = 9;
115
- case 9:
116
- _c++;
117
- return [3 /*break*/, 6];
118
- case 10: return [2 /*return*/, result];
119
- }
120
- });
121
- });
122
- };
123
- PathCompletionParticipant.prototype.providePathSuggestions = function (pathValue, position, range, document, documentContext) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var fullValue, isValueQuoted, valueBeforeCursor, currentDocUri, fullValueRange, replaceRange, valueBeforeLastSlash, parentDir, result, infos, _i, infos_1, _a, name, type, e_1;
126
- return __generator(this, function (_b) {
127
- switch (_b.label) {
128
- case 0:
129
- fullValue = stripQuotes(pathValue);
130
- isValueQuoted = startsWith(pathValue, "'") || startsWith(pathValue, "\"");
131
- valueBeforeCursor = isValueQuoted
132
- ? fullValue.slice(0, position.character - (range.start.character + 1))
133
- : fullValue.slice(0, position.character - range.start.character);
134
- currentDocUri = document.uri;
135
- fullValueRange = isValueQuoted ? shiftRange(range, 1, -1) : range;
136
- replaceRange = pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange);
137
- valueBeforeLastSlash = valueBeforeCursor.substring(0, valueBeforeCursor.lastIndexOf('/') + 1);
138
- parentDir = documentContext.resolveReference(valueBeforeLastSlash || '.', currentDocUri);
139
- if (!parentDir) return [3 /*break*/, 4];
140
- _b.label = 1;
141
- case 1:
142
- _b.trys.push([1, 3, , 4]);
143
- result = [];
144
- return [4 /*yield*/, this.readDirectory(parentDir)];
145
- case 2:
146
- infos = _b.sent();
147
- for (_i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
148
- _a = infos_1[_i], name = _a[0], type = _a[1];
149
- // Exclude paths that start with `.`
150
- if (name.charCodeAt(0) !== CharCode_dot && (type === FileType.Directory || joinPath(parentDir, name) !== currentDocUri)) {
151
- result.push(createCompletionItem(name, type === FileType.Directory, replaceRange));
152
- }
153
- }
154
- return [2 /*return*/, result];
155
- case 3:
156
- e_1 = _b.sent();
157
- return [3 /*break*/, 4];
158
- case 4: return [2 /*return*/, []];
159
- }
160
- });
161
- });
162
- };
163
- return PathCompletionParticipant;
164
- }());
165
- export { PathCompletionParticipant };
166
- var CharCode_dot = '.'.charCodeAt(0);
167
- function stripQuotes(fullValue) {
168
- if (startsWith(fullValue, "'") || startsWith(fullValue, "\"")) {
169
- return fullValue.slice(1, -1);
170
- }
171
- else {
172
- return fullValue;
173
- }
174
- }
175
- function pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange) {
176
- var replaceRange;
177
- var lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
178
- if (lastIndexOfSlash === -1) {
179
- replaceRange = fullValueRange;
180
- }
181
- else {
182
- // For cases where cursor is in the middle of attribute value, like <script src="./s|rc/test.js">
183
- // Find the last slash before cursor, and calculate the start of replace range from there
184
- var valueAfterLastSlash = fullValue.slice(lastIndexOfSlash + 1);
185
- var startPos = shiftPosition(fullValueRange.end, -valueAfterLastSlash.length);
186
- // If whitespace exists, replace until it
187
- var whitespaceIndex = valueAfterLastSlash.indexOf(' ');
188
- var endPos = void 0;
189
- if (whitespaceIndex !== -1) {
190
- endPos = shiftPosition(startPos, whitespaceIndex);
191
- }
192
- else {
193
- endPos = fullValueRange.end;
194
- }
195
- replaceRange = Range.create(startPos, endPos);
196
- }
197
- return replaceRange;
198
- }
199
- function createCompletionItem(name, isDir, replaceRange) {
200
- if (isDir) {
201
- name = name + '/';
202
- return {
203
- label: escapePath(name),
204
- kind: CompletionItemKind.Folder,
205
- textEdit: TextEdit.replace(replaceRange, escapePath(name)),
206
- command: {
207
- title: 'Suggest',
208
- command: 'editor.action.triggerSuggest'
209
- }
210
- };
211
- }
212
- else {
213
- return {
214
- label: escapePath(name),
215
- kind: CompletionItemKind.File,
216
- textEdit: TextEdit.replace(replaceRange, escapePath(name))
217
- };
218
- }
219
- }
220
- // Escape https://www.w3.org/TR/CSS1/#url
221
- function escapePath(p) {
222
- return p.replace(/(\s|\(|\)|,|"|')/g, '\\$1');
223
- }
224
- function shiftPosition(pos, offset) {
225
- return Position.create(pos.line, pos.character + offset);
226
- }
227
- function shiftRange(range, startOffset, endOffset) {
228
- var start = shiftPosition(range.start, startOffset);
229
- var end = shiftPosition(range.end, endOffset);
230
- return Range.create(start, end);
231
- }
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { FileType, CompletionItemKind, TextEdit, Range, Position } from '../cssLanguageTypes';
6
+ import { startsWith, endsWith } from '../utils/strings';
7
+ import { joinPath } from '../utils/resources';
8
+ export class PathCompletionParticipant {
9
+ constructor(readDirectory) {
10
+ this.readDirectory = readDirectory;
11
+ this.literalCompletions = [];
12
+ this.importCompletions = [];
13
+ }
14
+ onCssURILiteralValue(context) {
15
+ this.literalCompletions.push(context);
16
+ }
17
+ onCssImportPath(context) {
18
+ this.importCompletions.push(context);
19
+ }
20
+ async computeCompletions(document, documentContext) {
21
+ const result = { items: [], isIncomplete: false };
22
+ for (const literalCompletion of this.literalCompletions) {
23
+ const uriValue = literalCompletion.uriValue;
24
+ const fullValue = stripQuotes(uriValue);
25
+ if (fullValue === '.' || fullValue === '..') {
26
+ result.isIncomplete = true;
27
+ }
28
+ else {
29
+ const items = await this.providePathSuggestions(uriValue, literalCompletion.position, literalCompletion.range, document, documentContext);
30
+ for (let item of items) {
31
+ result.items.push(item);
32
+ }
33
+ }
34
+ }
35
+ for (const importCompletion of this.importCompletions) {
36
+ const pathValue = importCompletion.pathValue;
37
+ const fullValue = stripQuotes(pathValue);
38
+ if (fullValue === '.' || fullValue === '..') {
39
+ result.isIncomplete = true;
40
+ }
41
+ else {
42
+ let suggestions = await this.providePathSuggestions(pathValue, importCompletion.position, importCompletion.range, document, documentContext);
43
+ if (document.languageId === 'scss') {
44
+ suggestions.forEach(s => {
45
+ if (startsWith(s.label, '_') && endsWith(s.label, '.scss')) {
46
+ if (s.textEdit) {
47
+ s.textEdit.newText = s.label.slice(1, -5);
48
+ }
49
+ else {
50
+ s.label = s.label.slice(1, -5);
51
+ }
52
+ }
53
+ });
54
+ }
55
+ for (let item of suggestions) {
56
+ result.items.push(item);
57
+ }
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ async providePathSuggestions(pathValue, position, range, document, documentContext) {
63
+ const fullValue = stripQuotes(pathValue);
64
+ const isValueQuoted = startsWith(pathValue, `'`) || startsWith(pathValue, `"`);
65
+ const valueBeforeCursor = isValueQuoted
66
+ ? fullValue.slice(0, position.character - (range.start.character + 1))
67
+ : fullValue.slice(0, position.character - range.start.character);
68
+ const currentDocUri = document.uri;
69
+ const fullValueRange = isValueQuoted ? shiftRange(range, 1, -1) : range;
70
+ const replaceRange = pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange);
71
+ const valueBeforeLastSlash = valueBeforeCursor.substring(0, valueBeforeCursor.lastIndexOf('/') + 1); // keep the last slash
72
+ let parentDir = documentContext.resolveReference(valueBeforeLastSlash || '.', currentDocUri);
73
+ if (parentDir) {
74
+ try {
75
+ const result = [];
76
+ const infos = await this.readDirectory(parentDir);
77
+ for (const [name, type] of infos) {
78
+ // Exclude paths that start with `.`
79
+ if (name.charCodeAt(0) !== CharCode_dot && (type === FileType.Directory || joinPath(parentDir, name) !== currentDocUri)) {
80
+ result.push(createCompletionItem(name, type === FileType.Directory, replaceRange));
81
+ }
82
+ }
83
+ return result;
84
+ }
85
+ catch (e) {
86
+ // ignore
87
+ }
88
+ }
89
+ return [];
90
+ }
91
+ }
92
+ const CharCode_dot = '.'.charCodeAt(0);
93
+ function stripQuotes(fullValue) {
94
+ if (startsWith(fullValue, `'`) || startsWith(fullValue, `"`)) {
95
+ return fullValue.slice(1, -1);
96
+ }
97
+ else {
98
+ return fullValue;
99
+ }
100
+ }
101
+ function pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange) {
102
+ let replaceRange;
103
+ const lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
104
+ if (lastIndexOfSlash === -1) {
105
+ replaceRange = fullValueRange;
106
+ }
107
+ else {
108
+ // For cases where cursor is in the middle of attribute value, like <script src="./s|rc/test.js">
109
+ // Find the last slash before cursor, and calculate the start of replace range from there
110
+ const valueAfterLastSlash = fullValue.slice(lastIndexOfSlash + 1);
111
+ const startPos = shiftPosition(fullValueRange.end, -valueAfterLastSlash.length);
112
+ // If whitespace exists, replace until it
113
+ const whitespaceIndex = valueAfterLastSlash.indexOf(' ');
114
+ let endPos;
115
+ if (whitespaceIndex !== -1) {
116
+ endPos = shiftPosition(startPos, whitespaceIndex);
117
+ }
118
+ else {
119
+ endPos = fullValueRange.end;
120
+ }
121
+ replaceRange = Range.create(startPos, endPos);
122
+ }
123
+ return replaceRange;
124
+ }
125
+ function createCompletionItem(name, isDir, replaceRange) {
126
+ if (isDir) {
127
+ name = name + '/';
128
+ return {
129
+ label: escapePath(name),
130
+ kind: CompletionItemKind.Folder,
131
+ textEdit: TextEdit.replace(replaceRange, escapePath(name)),
132
+ command: {
133
+ title: 'Suggest',
134
+ command: 'editor.action.triggerSuggest'
135
+ }
136
+ };
137
+ }
138
+ else {
139
+ return {
140
+ label: escapePath(name),
141
+ kind: CompletionItemKind.File,
142
+ textEdit: TextEdit.replace(replaceRange, escapePath(name))
143
+ };
144
+ }
145
+ }
146
+ // Escape https://www.w3.org/TR/CSS1/#url
147
+ function escapePath(p) {
148
+ return p.replace(/(\s|\(|\)|,|"|')/g, '\\$1');
149
+ }
150
+ function shiftPosition(pos, offset) {
151
+ return Position.create(pos.line, pos.character + offset);
152
+ }
153
+ function shiftRange(range, startOffset, endOffset) {
154
+ const start = shiftPosition(range.start, startOffset);
155
+ const end = shiftPosition(range.end, endOffset);
156
+ return Range.create(start, end);
157
+ }