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.
- package/CHANGELOG.md +8 -0
- package/lib/esm/beautify/beautify-css.js +1437 -1606
- package/lib/esm/cssLanguageService.d.ts +2 -2
- package/lib/esm/cssLanguageService.js +18 -18
- package/lib/esm/languageFacts/colors.js +1 -1
- package/lib/esm/languageFacts/dataManager.js +3 -3
- package/lib/esm/languageFacts/entry.js +1 -1
- package/lib/esm/languageFacts/facts.js +3 -3
- package/lib/esm/parser/cssNodes.js +1 -1
- package/lib/esm/parser/cssParser.js +5 -5
- package/lib/esm/parser/cssSymbolScope.js +2 -2
- package/lib/esm/parser/lessParser.js +5 -5
- package/lib/esm/parser/lessScanner.js +1 -1
- package/lib/esm/parser/scssParser.js +6 -6
- package/lib/esm/parser/scssScanner.js +1 -1
- package/lib/esm/services/cssCodeActions.js +4 -4
- package/lib/esm/services/cssCompletion.js +7 -7
- package/lib/esm/services/cssFolding.js +3 -3
- package/lib/esm/services/cssFormatter.js +3 -3
- package/lib/esm/services/cssHover.js +6 -6
- package/lib/esm/services/cssNavigation.js +6 -6
- package/lib/esm/services/cssSelectionRange.js +2 -2
- package/lib/esm/services/cssValidation.js +4 -4
- package/lib/esm/services/lessCompletion.js +2 -2
- package/lib/esm/services/lint.js +5 -5
- package/lib/esm/services/lintRules.js +1 -1
- package/lib/esm/services/lintUtil.js +1 -1
- package/lib/esm/services/pathCompletion.js +3 -3
- package/lib/esm/services/scssCompletion.js +3 -3
- package/lib/esm/services/scssNavigation.js +4 -4
- package/lib/esm/services/selectorPrinting.js +3 -3
- package/package.json +15 -15
- package/lib/umd/beautify/beautify-css.js +0 -1695
- package/lib/umd/cssLanguageService.d.ts +0 -39
- package/lib/umd/cssLanguageService.js +0 -105
- package/lib/umd/cssLanguageTypes.d.ts +0 -267
- package/lib/umd/cssLanguageTypes.js +0 -89
- package/lib/umd/data/webCustomData.js +0 -44613
- package/lib/umd/languageFacts/builtinData.js +0 -155
- package/lib/umd/languageFacts/colors.js +0 -949
- package/lib/umd/languageFacts/dataManager.js +0 -101
- package/lib/umd/languageFacts/dataProvider.js +0 -86
- package/lib/umd/languageFacts/entry.js +0 -217
- package/lib/umd/languageFacts/facts.js +0 -33
- package/lib/umd/parser/cssErrors.js +0 -61
- package/lib/umd/parser/cssNodes.js +0 -1676
- package/lib/umd/parser/cssParser.js +0 -2035
- package/lib/umd/parser/cssScanner.js +0 -619
- package/lib/umd/parser/cssSymbolScope.js +0 -328
- package/lib/umd/parser/lessParser.js +0 -732
- package/lib/umd/parser/lessScanner.js +0 -70
- package/lib/umd/parser/scssErrors.js +0 -30
- package/lib/umd/parser/scssParser.js +0 -874
- package/lib/umd/parser/scssScanner.js +0 -108
- package/lib/umd/services/cssCodeActions.js +0 -89
- package/lib/umd/services/cssCompletion.js +0 -1109
- package/lib/umd/services/cssFolding.js +0 -202
- package/lib/umd/services/cssFormatter.js +0 -149
- package/lib/umd/services/cssHover.js +0 -174
- package/lib/umd/services/cssNavigation.js +0 -539
- package/lib/umd/services/cssSelectionRange.js +0 -59
- package/lib/umd/services/cssValidation.js +0 -54
- package/lib/umd/services/lessCompletion.js +0 -390
- package/lib/umd/services/lint.js +0 -577
- package/lib/umd/services/lintRules.js +0 -90
- package/lib/umd/services/lintUtil.js +0 -210
- package/lib/umd/services/pathCompletion.js +0 -171
- package/lib/umd/services/scssCompletion.js +0 -367
- package/lib/umd/services/scssNavigation.js +0 -169
- package/lib/umd/services/selectorPrinting.js +0 -575
- package/lib/umd/utils/arrays.js +0 -54
- package/lib/umd/utils/objects.js +0 -24
- package/lib/umd/utils/resources.js +0 -25
- package/lib/umd/utils/strings.js +0 -123
|
@@ -1,539 +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", "../cssLanguageTypes", "@vscode/l10n", "../parser/cssNodes", "../parser/cssSymbolScope", "../languageFacts/facts", "../utils/strings", "../utils/resources"], 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.CSSNavigation = void 0;
|
|
17
|
-
exports.getModuleNameFromPath = getModuleNameFromPath;
|
|
18
|
-
const cssLanguageTypes_1 = require("../cssLanguageTypes");
|
|
19
|
-
const l10n = require("@vscode/l10n");
|
|
20
|
-
const nodes = require("../parser/cssNodes");
|
|
21
|
-
const cssSymbolScope_1 = require("../parser/cssSymbolScope");
|
|
22
|
-
const facts_1 = require("../languageFacts/facts");
|
|
23
|
-
const strings_1 = require("../utils/strings");
|
|
24
|
-
const resources_1 = require("../utils/resources");
|
|
25
|
-
const startsWithSchemeRegex = /^\w+:\/\//;
|
|
26
|
-
const startsWithData = /^data:/;
|
|
27
|
-
class CSSNavigation {
|
|
28
|
-
constructor(fileSystemProvider, resolveModuleReferences) {
|
|
29
|
-
this.fileSystemProvider = fileSystemProvider;
|
|
30
|
-
this.resolveModuleReferences = resolveModuleReferences;
|
|
31
|
-
}
|
|
32
|
-
configure(settings) {
|
|
33
|
-
this.defaultSettings = settings;
|
|
34
|
-
}
|
|
35
|
-
findDefinition(document, position, stylesheet) {
|
|
36
|
-
const symbols = new cssSymbolScope_1.Symbols(stylesheet);
|
|
37
|
-
const offset = document.offsetAt(position);
|
|
38
|
-
const node = nodes.getNodeAtOffset(stylesheet, offset);
|
|
39
|
-
if (!node) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const symbol = symbols.findSymbolFromNode(node);
|
|
43
|
-
if (!symbol) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
uri: document.uri,
|
|
48
|
-
range: getRange(symbol.node, document)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
findReferences(document, position, stylesheet) {
|
|
52
|
-
const highlights = this.findDocumentHighlights(document, position, stylesheet);
|
|
53
|
-
return highlights.map(h => {
|
|
54
|
-
return {
|
|
55
|
-
uri: document.uri,
|
|
56
|
-
range: h.range
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getHighlightNode(document, position, stylesheet) {
|
|
61
|
-
const offset = document.offsetAt(position);
|
|
62
|
-
let node = nodes.getNodeAtOffset(stylesheet, offset);
|
|
63
|
-
if (!node || node.type === nodes.NodeType.Stylesheet || node.type === nodes.NodeType.Declarations || node.type === nodes.NodeType.ModuleConfig) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (node.type === nodes.NodeType.Identifier && node.parent && node.parent.type === nodes.NodeType.ClassSelector) {
|
|
67
|
-
node = node.parent;
|
|
68
|
-
}
|
|
69
|
-
return node;
|
|
70
|
-
}
|
|
71
|
-
findDocumentHighlights(document, position, stylesheet) {
|
|
72
|
-
const result = [];
|
|
73
|
-
const node = this.getHighlightNode(document, position, stylesheet);
|
|
74
|
-
if (!node) {
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
const symbols = new cssSymbolScope_1.Symbols(stylesheet);
|
|
78
|
-
const symbol = symbols.findSymbolFromNode(node);
|
|
79
|
-
const name = node.getText();
|
|
80
|
-
stylesheet.accept(candidate => {
|
|
81
|
-
if (symbol) {
|
|
82
|
-
if (symbols.matchesSymbol(candidate, symbol)) {
|
|
83
|
-
result.push({
|
|
84
|
-
kind: getHighlightKind(candidate),
|
|
85
|
-
range: getRange(candidate, document)
|
|
86
|
-
});
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (node && node.type === candidate.type && candidate.matches(name)) {
|
|
91
|
-
// Same node type and data
|
|
92
|
-
result.push({
|
|
93
|
-
kind: getHighlightKind(candidate),
|
|
94
|
-
range: getRange(candidate, document)
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
isRawStringDocumentLinkNode(node) {
|
|
102
|
-
return node.type === nodes.NodeType.Import;
|
|
103
|
-
}
|
|
104
|
-
findDocumentLinks(document, stylesheet, documentContext) {
|
|
105
|
-
const linkData = this.findUnresolvedLinks(document, stylesheet);
|
|
106
|
-
const resolvedLinks = [];
|
|
107
|
-
for (let data of linkData) {
|
|
108
|
-
const link = data.link;
|
|
109
|
-
const target = link.target;
|
|
110
|
-
if (!target || startsWithData.test(target)) {
|
|
111
|
-
// no links for data:
|
|
112
|
-
}
|
|
113
|
-
else if (startsWithSchemeRegex.test(target)) {
|
|
114
|
-
resolvedLinks.push(link);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const resolved = documentContext.resolveReference(target, document.uri);
|
|
118
|
-
if (resolved) {
|
|
119
|
-
link.target = resolved;
|
|
120
|
-
}
|
|
121
|
-
resolvedLinks.push(link);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return resolvedLinks;
|
|
125
|
-
}
|
|
126
|
-
async findDocumentLinks2(document, stylesheet, documentContext) {
|
|
127
|
-
const linkData = this.findUnresolvedLinks(document, stylesheet);
|
|
128
|
-
const resolvedLinks = [];
|
|
129
|
-
for (let data of linkData) {
|
|
130
|
-
const link = data.link;
|
|
131
|
-
const target = link.target;
|
|
132
|
-
if (!target || startsWithData.test(target)) {
|
|
133
|
-
// no links for data:
|
|
134
|
-
}
|
|
135
|
-
else if (startsWithSchemeRegex.test(target)) {
|
|
136
|
-
resolvedLinks.push(link);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
const resolvedTarget = await this.resolveReference(target, document.uri, documentContext, data.isRawLink);
|
|
140
|
-
if (resolvedTarget !== undefined) {
|
|
141
|
-
link.target = resolvedTarget;
|
|
142
|
-
resolvedLinks.push(link);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return resolvedLinks;
|
|
147
|
-
}
|
|
148
|
-
findUnresolvedLinks(document, stylesheet) {
|
|
149
|
-
const result = [];
|
|
150
|
-
const collect = (uriStringNode) => {
|
|
151
|
-
let rawUri = uriStringNode.getText();
|
|
152
|
-
const range = getRange(uriStringNode, document);
|
|
153
|
-
// Make sure the range is not empty
|
|
154
|
-
if (range.start.line === range.end.line && range.start.character === range.end.character) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if ((0, strings_1.startsWith)(rawUri, `'`) || (0, strings_1.startsWith)(rawUri, `"`)) {
|
|
158
|
-
rawUri = rawUri.slice(1, -1);
|
|
159
|
-
}
|
|
160
|
-
const isRawLink = uriStringNode.parent ? this.isRawStringDocumentLinkNode(uriStringNode.parent) : false;
|
|
161
|
-
result.push({ link: { target: rawUri, range }, isRawLink });
|
|
162
|
-
};
|
|
163
|
-
stylesheet.accept(candidate => {
|
|
164
|
-
if (candidate.type === nodes.NodeType.URILiteral) {
|
|
165
|
-
const first = candidate.getChild(0);
|
|
166
|
-
if (first) {
|
|
167
|
-
collect(first);
|
|
168
|
-
}
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* In @import, it is possible to include links that do not use `url()`
|
|
173
|
-
* For example, `@import 'foo.css';`
|
|
174
|
-
*/
|
|
175
|
-
if (candidate.parent && this.isRawStringDocumentLinkNode(candidate.parent)) {
|
|
176
|
-
const rawText = candidate.getText();
|
|
177
|
-
if ((0, strings_1.startsWith)(rawText, `'`) || (0, strings_1.startsWith)(rawText, `"`)) {
|
|
178
|
-
collect(candidate);
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
return true;
|
|
183
|
-
});
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
findSymbolInformations(document, stylesheet) {
|
|
187
|
-
const result = [];
|
|
188
|
-
const addSymbolInformation = (name, kind, symbolNodeOrRange) => {
|
|
189
|
-
const range = symbolNodeOrRange instanceof nodes.Node ? getRange(symbolNodeOrRange, document) : symbolNodeOrRange;
|
|
190
|
-
const entry = {
|
|
191
|
-
name: name || l10n.t('<undefined>'),
|
|
192
|
-
kind,
|
|
193
|
-
location: cssLanguageTypes_1.Location.create(document.uri, range)
|
|
194
|
-
};
|
|
195
|
-
result.push(entry);
|
|
196
|
-
};
|
|
197
|
-
this.collectDocumentSymbols(document, stylesheet, addSymbolInformation);
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
findDocumentSymbols(document, stylesheet) {
|
|
201
|
-
const result = [];
|
|
202
|
-
const parents = [];
|
|
203
|
-
const addDocumentSymbol = (name, kind, symbolNodeOrRange, nameNodeOrRange, bodyNode) => {
|
|
204
|
-
const range = symbolNodeOrRange instanceof nodes.Node ? getRange(symbolNodeOrRange, document) : symbolNodeOrRange;
|
|
205
|
-
let selectionRange = nameNodeOrRange instanceof nodes.Node ? getRange(nameNodeOrRange, document) : nameNodeOrRange;
|
|
206
|
-
if (!selectionRange || !containsRange(range, selectionRange)) {
|
|
207
|
-
selectionRange = cssLanguageTypes_1.Range.create(range.start, range.start);
|
|
208
|
-
}
|
|
209
|
-
const entry = {
|
|
210
|
-
name: name || l10n.t('<undefined>'),
|
|
211
|
-
kind,
|
|
212
|
-
range,
|
|
213
|
-
selectionRange
|
|
214
|
-
};
|
|
215
|
-
let top = parents.pop();
|
|
216
|
-
while (top && !containsRange(top[1], range)) {
|
|
217
|
-
top = parents.pop();
|
|
218
|
-
}
|
|
219
|
-
if (top) {
|
|
220
|
-
const topSymbol = top[0];
|
|
221
|
-
if (!topSymbol.children) {
|
|
222
|
-
topSymbol.children = [];
|
|
223
|
-
}
|
|
224
|
-
topSymbol.children.push(entry);
|
|
225
|
-
parents.push(top); // put back top
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
result.push(entry);
|
|
229
|
-
}
|
|
230
|
-
if (bodyNode) {
|
|
231
|
-
parents.push([entry, getRange(bodyNode, document)]);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
this.collectDocumentSymbols(document, stylesheet, addDocumentSymbol);
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
collectDocumentSymbols(document, stylesheet, collect) {
|
|
238
|
-
stylesheet.accept(node => {
|
|
239
|
-
if (node instanceof nodes.RuleSet) {
|
|
240
|
-
for (const selector of node.getSelectors().getChildren()) {
|
|
241
|
-
if (selector instanceof nodes.Selector) {
|
|
242
|
-
const range = cssLanguageTypes_1.Range.create(document.positionAt(selector.offset), document.positionAt(node.end));
|
|
243
|
-
collect(selector.getText(), cssLanguageTypes_1.SymbolKind.Class, range, selector, node.getDeclarations());
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
else if (node instanceof nodes.VariableDeclaration) {
|
|
248
|
-
collect(node.getName(), cssLanguageTypes_1.SymbolKind.Variable, node, node.getVariable(), undefined);
|
|
249
|
-
}
|
|
250
|
-
else if (node instanceof nodes.MixinDeclaration) {
|
|
251
|
-
collect(node.getName(), cssLanguageTypes_1.SymbolKind.Method, node, node.getIdentifier(), node.getDeclarations());
|
|
252
|
-
}
|
|
253
|
-
else if (node instanceof nodes.FunctionDeclaration) {
|
|
254
|
-
collect(node.getName(), cssLanguageTypes_1.SymbolKind.Function, node, node.getIdentifier(), node.getDeclarations());
|
|
255
|
-
}
|
|
256
|
-
else if (node instanceof nodes.Keyframe) {
|
|
257
|
-
const name = l10n.t("@keyframes {0}", node.getName());
|
|
258
|
-
collect(name, cssLanguageTypes_1.SymbolKind.Class, node, node.getIdentifier(), node.getDeclarations());
|
|
259
|
-
}
|
|
260
|
-
else if (node instanceof nodes.FontFace) {
|
|
261
|
-
const name = l10n.t("@font-face");
|
|
262
|
-
collect(name, cssLanguageTypes_1.SymbolKind.Class, node, undefined, node.getDeclarations());
|
|
263
|
-
}
|
|
264
|
-
else if (node instanceof nodes.Media) {
|
|
265
|
-
const mediaList = node.getChild(0);
|
|
266
|
-
if (mediaList instanceof nodes.Medialist) {
|
|
267
|
-
const name = '@media ' + mediaList.getText();
|
|
268
|
-
collect(name, cssLanguageTypes_1.SymbolKind.Module, node, mediaList, node.getDeclarations());
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
else if (node instanceof nodes.Scope) {
|
|
272
|
-
let scopeName = '';
|
|
273
|
-
const scopeLimits = node.getChild(0);
|
|
274
|
-
if (scopeLimits instanceof nodes.ScopeLimits) {
|
|
275
|
-
scopeName = `${scopeLimits.getName()}`;
|
|
276
|
-
}
|
|
277
|
-
collect(`@scope${scopeName ? ` ${scopeName}` : ''}`, cssLanguageTypes_1.SymbolKind.Module, node, scopeLimits ?? undefined, node.getDeclarations());
|
|
278
|
-
}
|
|
279
|
-
return true;
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
findDocumentColors(document, stylesheet) {
|
|
283
|
-
const result = [];
|
|
284
|
-
stylesheet.accept((node) => {
|
|
285
|
-
const colorInfo = getColorInformation(node, document);
|
|
286
|
-
if (colorInfo) {
|
|
287
|
-
result.push(colorInfo);
|
|
288
|
-
}
|
|
289
|
-
return true;
|
|
290
|
-
});
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
getColorPresentations(document, stylesheet, color, range) {
|
|
294
|
-
const result = [];
|
|
295
|
-
const red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
|
|
296
|
-
let label;
|
|
297
|
-
if (color.alpha === 1) {
|
|
298
|
-
label = `rgb(${red256}, ${green256}, ${blue256})`;
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
label = `rgba(${red256}, ${green256}, ${blue256}, ${color.alpha})`;
|
|
302
|
-
}
|
|
303
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
304
|
-
if (color.alpha === 1) {
|
|
305
|
-
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}`;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}${toTwoDigitHex(Math.round(color.alpha * 255))}`;
|
|
309
|
-
}
|
|
310
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
311
|
-
const hsl = (0, facts_1.hslFromColor)(color);
|
|
312
|
-
if (hsl.a === 1) {
|
|
313
|
-
label = `hsl(${hsl.h}, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%)`;
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
label = `hsla(${hsl.h}, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%, ${hsl.a})`;
|
|
317
|
-
}
|
|
318
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
319
|
-
const hwb = (0, facts_1.hwbFromColor)(color);
|
|
320
|
-
if (hwb.a === 1) {
|
|
321
|
-
label = `hwb(${hwb.h} ${Math.round(hwb.w * 100)}% ${Math.round(hwb.b * 100)}%)`;
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
label = `hwb(${hwb.h} ${Math.round(hwb.w * 100)}% ${Math.round(hwb.b * 100)}% / ${hwb.a})`;
|
|
325
|
-
}
|
|
326
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
327
|
-
const lab = (0, facts_1.labFromColor)(color);
|
|
328
|
-
if (lab.alpha === 1) {
|
|
329
|
-
label = `lab(${lab.l}% ${lab.a} ${lab.b})`;
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
label = `lab(${lab.l}% ${lab.a} ${lab.b} / ${lab.alpha})`;
|
|
333
|
-
}
|
|
334
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
335
|
-
const lch = (0, facts_1.lchFromColor)(color);
|
|
336
|
-
if (lch.alpha === 1) {
|
|
337
|
-
label = `lch(${lch.l}% ${lch.c} ${lch.h})`;
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
label = `lch(${lch.l}% ${lch.c} ${lch.h} / ${lch.alpha})`;
|
|
341
|
-
}
|
|
342
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
343
|
-
const oklab = (0, facts_1.oklabFromColor)(color);
|
|
344
|
-
label = (oklab.alpha === 1) ? `oklab(${oklab.l}% ${oklab.a} ${oklab.b})` : `oklab(${oklab.l}% ${oklab.a} ${oklab.b} / ${oklab.alpha})`;
|
|
345
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
346
|
-
const oklch = (0, facts_1.oklchFromColor)(color);
|
|
347
|
-
label = (oklch.alpha === 1) ? `oklch(${oklch.l}% ${oklch.c} ${oklch.h})` : `oklch(${oklch.l}% ${oklch.c} ${oklch.h} / ${oklch.alpha})`;
|
|
348
|
-
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
|
|
349
|
-
return result;
|
|
350
|
-
}
|
|
351
|
-
prepareRename(document, position, stylesheet) {
|
|
352
|
-
const node = this.getHighlightNode(document, position, stylesheet);
|
|
353
|
-
if (node) {
|
|
354
|
-
return cssLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.end));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
doRename(document, position, newName, stylesheet) {
|
|
358
|
-
const highlights = this.findDocumentHighlights(document, position, stylesheet);
|
|
359
|
-
const edits = highlights.map(h => cssLanguageTypes_1.TextEdit.replace(h.range, newName));
|
|
360
|
-
return {
|
|
361
|
-
changes: { [document.uri]: edits }
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
async resolveModuleReference(ref, documentUri, documentContext) {
|
|
365
|
-
if ((0, strings_1.startsWith)(documentUri, 'file://')) {
|
|
366
|
-
const moduleName = getModuleNameFromPath(ref);
|
|
367
|
-
if (moduleName && moduleName !== '.' && moduleName !== '..') {
|
|
368
|
-
const rootFolderUri = documentContext.resolveReference('/', documentUri);
|
|
369
|
-
const documentFolderUri = (0, resources_1.dirname)(documentUri);
|
|
370
|
-
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
|
|
371
|
-
if (modulePath) {
|
|
372
|
-
const pathWithinModule = ref.substring(moduleName.length + 1);
|
|
373
|
-
return (0, resources_1.joinPath)(modulePath, pathWithinModule);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return undefined;
|
|
378
|
-
}
|
|
379
|
-
async mapReference(target, isRawLink) {
|
|
380
|
-
return target;
|
|
381
|
-
}
|
|
382
|
-
async resolveReference(target, documentUri, documentContext, isRawLink = false, settings = this.defaultSettings) {
|
|
383
|
-
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)
|
|
384
|
-
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)
|
|
385
|
-
// convention, if an import path starts with ~ then use node module resolution
|
|
386
|
-
// *unless* it starts with "~/" as this refers to the user's home directory.
|
|
387
|
-
if (target[0] === '~' && target[1] !== '/' && this.fileSystemProvider) {
|
|
388
|
-
target = target.substring(1);
|
|
389
|
-
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
390
|
-
}
|
|
391
|
-
const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
|
|
392
|
-
// Following [less-loader](https://github.com/webpack-contrib/less-loader#imports)
|
|
393
|
-
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules)
|
|
394
|
-
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
|
|
395
|
-
// then the loader will try to resolve @import inside node_modules.
|
|
396
|
-
if (this.resolveModuleReferences) {
|
|
397
|
-
if (ref && await this.fileExists(ref)) {
|
|
398
|
-
return ref;
|
|
399
|
-
}
|
|
400
|
-
const moduleReference = await this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
401
|
-
if (moduleReference) {
|
|
402
|
-
return moduleReference;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
// Try resolving the reference from the language configuration alias settings
|
|
406
|
-
if (ref && !(await this.fileExists(ref))) {
|
|
407
|
-
const rootFolderUri = documentContext.resolveReference('/', documentUri);
|
|
408
|
-
if (settings && rootFolderUri) {
|
|
409
|
-
// Specific file reference
|
|
410
|
-
if (target in settings) {
|
|
411
|
-
return this.mapReference((0, resources_1.joinPath)(rootFolderUri, settings[target]), isRawLink);
|
|
412
|
-
}
|
|
413
|
-
// Reference folder
|
|
414
|
-
const firstSlash = target.indexOf('/');
|
|
415
|
-
const prefix = `${target.substring(0, firstSlash)}/`;
|
|
416
|
-
if (prefix in settings) {
|
|
417
|
-
const aliasPath = (settings[prefix]).slice(0, -1);
|
|
418
|
-
let newPath = (0, resources_1.joinPath)(rootFolderUri, aliasPath);
|
|
419
|
-
return this.mapReference(newPath = (0, resources_1.joinPath)(newPath, target.substring(prefix.length - 1)), isRawLink);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
// fall back. it might not exists
|
|
424
|
-
return ref;
|
|
425
|
-
}
|
|
426
|
-
async resolvePathToModule(_moduleName, documentFolderUri, rootFolderUri) {
|
|
427
|
-
// resolve the module relative to the document. We can't use `require` here as the code is webpacked.
|
|
428
|
-
const packPath = (0, resources_1.joinPath)(documentFolderUri, 'node_modules', _moduleName, 'package.json');
|
|
429
|
-
if (await this.fileExists(packPath)) {
|
|
430
|
-
return (0, resources_1.dirname)(packPath);
|
|
431
|
-
}
|
|
432
|
-
else if (rootFolderUri && documentFolderUri.startsWith(rootFolderUri) && (documentFolderUri.length !== rootFolderUri.length)) {
|
|
433
|
-
return this.resolvePathToModule(_moduleName, (0, resources_1.dirname)(documentFolderUri), rootFolderUri);
|
|
434
|
-
}
|
|
435
|
-
return undefined;
|
|
436
|
-
}
|
|
437
|
-
async fileExists(uri) {
|
|
438
|
-
if (!this.fileSystemProvider) {
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
try {
|
|
442
|
-
const stat = await this.fileSystemProvider.stat(uri);
|
|
443
|
-
if (stat.type === cssLanguageTypes_1.FileType.Unknown && stat.size === -1) {
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
return true;
|
|
447
|
-
}
|
|
448
|
-
catch (err) {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
async getContent(uri) {
|
|
453
|
-
if (!this.fileSystemProvider || !this.fileSystemProvider.getContent) {
|
|
454
|
-
return null;
|
|
455
|
-
}
|
|
456
|
-
try {
|
|
457
|
-
return await this.fileSystemProvider.getContent(uri);
|
|
458
|
-
}
|
|
459
|
-
catch (err) {
|
|
460
|
-
return null;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
exports.CSSNavigation = CSSNavigation;
|
|
465
|
-
function getColorInformation(node, document) {
|
|
466
|
-
const color = (0, facts_1.getColorValue)(node);
|
|
467
|
-
if (color) {
|
|
468
|
-
const range = getRange(node, document);
|
|
469
|
-
return { color, range };
|
|
470
|
-
}
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
function getRange(node, document) {
|
|
474
|
-
return cssLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.end));
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Test if `otherRange` is in `range`. If the ranges are equal, will return true.
|
|
478
|
-
*/
|
|
479
|
-
function containsRange(range, otherRange) {
|
|
480
|
-
const otherStartLine = otherRange.start.line, otherEndLine = otherRange.end.line;
|
|
481
|
-
const rangeStartLine = range.start.line, rangeEndLine = range.end.line;
|
|
482
|
-
if (otherStartLine < rangeStartLine || otherEndLine < rangeStartLine) {
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
if (otherStartLine > rangeEndLine || otherEndLine > rangeEndLine) {
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
if (otherStartLine === rangeStartLine && otherRange.start.character < range.start.character) {
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
if (otherEndLine === rangeEndLine && otherRange.end.character > range.end.character) {
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
|
-
function getHighlightKind(node) {
|
|
497
|
-
if (node.type === nodes.NodeType.Selector) {
|
|
498
|
-
return cssLanguageTypes_1.DocumentHighlightKind.Write;
|
|
499
|
-
}
|
|
500
|
-
if (node instanceof nodes.Identifier) {
|
|
501
|
-
if (node.parent && node.parent instanceof nodes.Property) {
|
|
502
|
-
if (node.isCustomProperty) {
|
|
503
|
-
return cssLanguageTypes_1.DocumentHighlightKind.Write;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (node.parent) {
|
|
508
|
-
switch (node.parent.type) {
|
|
509
|
-
case nodes.NodeType.FunctionDeclaration:
|
|
510
|
-
case nodes.NodeType.MixinDeclaration:
|
|
511
|
-
case nodes.NodeType.Keyframe:
|
|
512
|
-
case nodes.NodeType.VariableDeclaration:
|
|
513
|
-
case nodes.NodeType.FunctionParameter:
|
|
514
|
-
return cssLanguageTypes_1.DocumentHighlightKind.Write;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return cssLanguageTypes_1.DocumentHighlightKind.Read;
|
|
518
|
-
}
|
|
519
|
-
function toTwoDigitHex(n) {
|
|
520
|
-
const r = n.toString(16);
|
|
521
|
-
return r.length !== 2 ? '0' + r : r;
|
|
522
|
-
}
|
|
523
|
-
function getModuleNameFromPath(path) {
|
|
524
|
-
const firstSlash = path.indexOf('/');
|
|
525
|
-
if (firstSlash === -1) {
|
|
526
|
-
return '';
|
|
527
|
-
}
|
|
528
|
-
// If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports.
|
|
529
|
-
if (path[0] === '@') {
|
|
530
|
-
const secondSlash = path.indexOf('/', firstSlash + 1);
|
|
531
|
-
if (secondSlash === -1) {
|
|
532
|
-
return path;
|
|
533
|
-
}
|
|
534
|
-
return path.substring(0, secondSlash);
|
|
535
|
-
}
|
|
536
|
-
// Otherwise get until first instance of '/'
|
|
537
|
-
return path.substring(0, firstSlash);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
@@ -1,59 +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", "../cssLanguageTypes", "../parser/cssNodes"], 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.getSelectionRanges = getSelectionRanges;
|
|
17
|
-
const cssLanguageTypes_1 = require("../cssLanguageTypes");
|
|
18
|
-
const cssNodes_1 = require("../parser/cssNodes");
|
|
19
|
-
function getSelectionRanges(document, positions, stylesheet) {
|
|
20
|
-
function getSelectionRange(position) {
|
|
21
|
-
const applicableRanges = getApplicableRanges(position);
|
|
22
|
-
let current = undefined;
|
|
23
|
-
for (let index = applicableRanges.length - 1; index >= 0; index--) {
|
|
24
|
-
current = cssLanguageTypes_1.SelectionRange.create(cssLanguageTypes_1.Range.create(document.positionAt(applicableRanges[index][0]), document.positionAt(applicableRanges[index][1])), current);
|
|
25
|
-
}
|
|
26
|
-
if (!current) {
|
|
27
|
-
current = cssLanguageTypes_1.SelectionRange.create(cssLanguageTypes_1.Range.create(position, position));
|
|
28
|
-
}
|
|
29
|
-
return current;
|
|
30
|
-
}
|
|
31
|
-
return positions.map(getSelectionRange);
|
|
32
|
-
function getApplicableRanges(position) {
|
|
33
|
-
const offset = document.offsetAt(position);
|
|
34
|
-
let currNode = stylesheet.findChildAtOffset(offset, true);
|
|
35
|
-
if (!currNode) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const result = [];
|
|
39
|
-
while (currNode) {
|
|
40
|
-
if (currNode.parent &&
|
|
41
|
-
currNode.offset === currNode.parent.offset &&
|
|
42
|
-
currNode.end === currNode.parent.end) {
|
|
43
|
-
currNode = currNode.parent;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
// The `{ }` part of `.a { }`
|
|
47
|
-
if (currNode.type === cssNodes_1.NodeType.Declarations) {
|
|
48
|
-
if (offset > currNode.offset && offset < currNode.end) {
|
|
49
|
-
// Return `{ }` and the range inside `{` and `}`
|
|
50
|
-
result.push([currNode.offset + 1, currNode.end - 1]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
result.push([currNode.offset, currNode.end]);
|
|
54
|
-
currNode = currNode.parent;
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
@@ -1,54 +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", "./lintRules", "./lint", "../cssLanguageTypes"], 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.CSSValidation = void 0;
|
|
17
|
-
const nodes = require("../parser/cssNodes");
|
|
18
|
-
const lintRules_1 = require("./lintRules");
|
|
19
|
-
const lint_1 = require("./lint");
|
|
20
|
-
const cssLanguageTypes_1 = require("../cssLanguageTypes");
|
|
21
|
-
class CSSValidation {
|
|
22
|
-
constructor(cssDataManager) {
|
|
23
|
-
this.cssDataManager = cssDataManager;
|
|
24
|
-
}
|
|
25
|
-
configure(settings) {
|
|
26
|
-
this.settings = settings;
|
|
27
|
-
}
|
|
28
|
-
doValidation(document, stylesheet, settings = this.settings) {
|
|
29
|
-
if (settings && settings.validate === false) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const entries = [];
|
|
33
|
-
entries.push.apply(entries, nodes.ParseErrorCollector.entries(stylesheet));
|
|
34
|
-
entries.push.apply(entries, lint_1.LintVisitor.entries(stylesheet, document, new lintRules_1.LintConfigurationSettings(settings && settings.lint), this.cssDataManager));
|
|
35
|
-
const ruleIds = [];
|
|
36
|
-
for (const r in lintRules_1.Rules) {
|
|
37
|
-
ruleIds.push(lintRules_1.Rules[r].id);
|
|
38
|
-
}
|
|
39
|
-
function toDiagnostic(marker) {
|
|
40
|
-
const range = cssLanguageTypes_1.Range.create(document.positionAt(marker.getOffset()), document.positionAt(marker.getOffset() + marker.getLength()));
|
|
41
|
-
const source = document.languageId;
|
|
42
|
-
return {
|
|
43
|
-
code: marker.getRule().id,
|
|
44
|
-
source: source,
|
|
45
|
-
message: marker.getMessage(),
|
|
46
|
-
severity: marker.getLevel() === nodes.Level.Warning ? cssLanguageTypes_1.DiagnosticSeverity.Warning : cssLanguageTypes_1.DiagnosticSeverity.Error,
|
|
47
|
-
range: range
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return entries.filter(entry => entry.getLevel() !== nodes.Level.Ignore).map(toDiagnostic);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.CSSValidation = CSSValidation;
|
|
54
|
-
});
|