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