vscode-css-languageservice 5.4.2 → 6.1.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 +7 -1
- package/SECURITY.md +41 -0
- package/lib/esm/beautify/beautify-css.js +11 -4
- package/lib/esm/cssLanguageService.d.ts +2 -1
- package/lib/esm/cssLanguageService.js +15 -17
- package/lib/esm/cssLanguageTypes.js +2 -2
- package/lib/esm/data/webCustomData.js +356 -232
- package/lib/esm/languageFacts/builtinData.js +15 -15
- package/lib/esm/languageFacts/colors.js +66 -69
- package/lib/esm/languageFacts/dataManager.js +38 -42
- package/lib/esm/languageFacts/dataProvider.js +17 -23
- package/lib/esm/languageFacts/entry.js +22 -23
- package/lib/esm/parser/cssErrors.js +5 -7
- package/lib/esm/parser/cssNodes.js +869 -1377
- package/lib/esm/parser/cssParser.js +419 -376
- package/lib/esm/parser/cssScanner.js +168 -175
- package/lib/esm/parser/cssSymbolScope.js +107 -137
- package/lib/esm/parser/lessParser.js +177 -202
- package/lib/esm/parser/lessScanner.js +22 -43
- package/lib/esm/parser/scssErrors.js +5 -7
- package/lib/esm/parser/scssParser.js +196 -208
- package/lib/esm/parser/scssScanner.js +33 -54
- package/lib/esm/services/cssCodeActions.js +36 -40
- package/lib/esm/services/cssCompletion.js +300 -395
- package/lib/esm/services/cssFolding.js +32 -35
- package/lib/esm/services/cssFormatter.js +22 -22
- package/lib/esm/services/cssHover.js +30 -33
- package/lib/esm/services/cssNavigation.js +260 -289
- package/lib/esm/services/cssSelectionRange.js +6 -6
- package/lib/esm/services/cssValidation.js +13 -16
- package/lib/esm/services/lessCompletion.js +351 -370
- package/lib/esm/services/lint.js +161 -175
- package/lib/esm/services/lintRules.js +20 -27
- package/lib/esm/services/lintUtil.js +19 -28
- package/lib/esm/services/pathCompletion.js +84 -158
- package/lib/esm/services/scssCompletion.js +283 -307
- package/lib/esm/services/scssNavigation.js +65 -137
- package/lib/esm/services/selectorPrinting.js +131 -175
- package/lib/esm/utils/arrays.js +6 -12
- package/lib/esm/utils/objects.js +1 -1
- package/lib/esm/utils/resources.js +3 -16
- package/lib/esm/utils/strings.js +10 -12
- package/lib/umd/beautify/beautify-css.js +11 -4
- package/lib/umd/cssLanguageService.d.ts +2 -1
- package/lib/umd/cssLanguageService.js +34 -32
- package/lib/umd/cssLanguageTypes.js +4 -3
- package/lib/umd/data/webCustomData.js +355 -231
- package/lib/umd/languageFacts/colors.js +65 -68
- package/lib/umd/languageFacts/dataManager.js +41 -44
- package/lib/umd/languageFacts/dataProvider.js +17 -22
- package/lib/umd/languageFacts/entry.js +22 -23
- package/lib/umd/languageFacts/facts.js +5 -1
- package/lib/umd/parser/cssErrors.js +5 -6
- package/lib/umd/parser/cssNodes.js +870 -1307
- package/lib/umd/parser/cssParser.js +424 -380
- package/lib/umd/parser/cssScanner.js +168 -173
- package/lib/umd/parser/cssSymbolScope.js +109 -134
- package/lib/umd/parser/lessParser.js +182 -206
- package/lib/umd/parser/lessScanner.js +22 -42
- package/lib/umd/parser/scssErrors.js +5 -6
- package/lib/umd/parser/scssParser.js +202 -213
- package/lib/umd/parser/scssScanner.js +25 -45
- package/lib/umd/services/cssCodeActions.js +41 -44
- package/lib/umd/services/cssCompletion.js +308 -402
- package/lib/umd/services/cssFolding.js +35 -38
- package/lib/umd/services/cssFormatter.js +25 -25
- package/lib/umd/services/cssHover.js +36 -38
- package/lib/umd/services/cssNavigation.js +267 -295
- package/lib/umd/services/cssSelectionRange.js +8 -8
- package/lib/umd/services/cssValidation.js +17 -19
- package/lib/umd/services/lessCompletion.js +354 -372
- package/lib/umd/services/lint.js +167 -180
- package/lib/umd/services/lintRules.js +20 -24
- package/lib/umd/services/lintUtil.js +20 -28
- package/lib/umd/services/pathCompletion.js +87 -160
- package/lib/umd/services/scssCompletion.js +287 -310
- package/lib/umd/services/scssNavigation.js +69 -140
- package/lib/umd/services/selectorPrinting.js +134 -174
- package/lib/umd/utils/arrays.js +6 -12
- package/lib/umd/utils/objects.js +1 -1
- package/lib/umd/utils/resources.js +4 -17
- package/lib/umd/utils/strings.js +10 -12
- package/package.json +16 -15
|
@@ -3,54 +3,35 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
'use strict';
|
|
6
|
-
var __extends = (this && this.__extends) || (function () {
|
|
7
|
-
var extendStatics = function (d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf ||
|
|
9
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
11
|
-
return extendStatics(d, b);
|
|
12
|
-
};
|
|
13
|
-
return function (d, b) {
|
|
14
|
-
if (typeof b !== "function" && b !== null)
|
|
15
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
-
extendStatics(d, b);
|
|
17
|
-
function __() { this.constructor = d; }
|
|
18
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
-
};
|
|
20
|
-
})();
|
|
21
6
|
import { TokenType, Scanner } from './cssScanner';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function SCSSScanner() {
|
|
48
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
49
|
-
}
|
|
50
|
-
SCSSScanner.prototype.scanNext = function (offset) {
|
|
7
|
+
const _FSL = '/'.charCodeAt(0);
|
|
8
|
+
const _NWL = '\n'.charCodeAt(0);
|
|
9
|
+
const _CAR = '\r'.charCodeAt(0);
|
|
10
|
+
const _LFD = '\f'.charCodeAt(0);
|
|
11
|
+
const _DLR = '$'.charCodeAt(0);
|
|
12
|
+
const _HSH = '#'.charCodeAt(0);
|
|
13
|
+
const _CUL = '{'.charCodeAt(0);
|
|
14
|
+
const _EQS = '='.charCodeAt(0);
|
|
15
|
+
const _BNG = '!'.charCodeAt(0);
|
|
16
|
+
const _LAN = '<'.charCodeAt(0);
|
|
17
|
+
const _RAN = '>'.charCodeAt(0);
|
|
18
|
+
const _DOT = '.'.charCodeAt(0);
|
|
19
|
+
const _ATS = '@'.charCodeAt(0);
|
|
20
|
+
let customTokenValue = TokenType.CustomToken;
|
|
21
|
+
export const VariableName = customTokenValue++;
|
|
22
|
+
export const InterpolationFunction = customTokenValue++;
|
|
23
|
+
export const Default = customTokenValue++;
|
|
24
|
+
export const EqualsOperator = customTokenValue++;
|
|
25
|
+
export const NotEqualsOperator = customTokenValue++;
|
|
26
|
+
export const GreaterEqualsOperator = customTokenValue++;
|
|
27
|
+
export const SmallerEqualsOperator = customTokenValue++;
|
|
28
|
+
export const Ellipsis = customTokenValue++;
|
|
29
|
+
export const Module = customTokenValue++;
|
|
30
|
+
export class SCSSScanner extends Scanner {
|
|
31
|
+
scanNext(offset) {
|
|
51
32
|
// scss variable
|
|
52
33
|
if (this.stream.advanceIfChar(_DLR)) {
|
|
53
|
-
|
|
34
|
+
const content = ['$'];
|
|
54
35
|
if (this.ident(content)) {
|
|
55
36
|
return this.finishToken(offset, VariableName, content.join(''));
|
|
56
37
|
}
|
|
@@ -88,14 +69,14 @@ var SCSSScanner = /** @class */ (function (_super) {
|
|
|
88
69
|
if (this.stream.advanceIfChars([_DOT, _DOT, _DOT])) {
|
|
89
70
|
return this.finishToken(offset, Ellipsis);
|
|
90
71
|
}
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (
|
|
72
|
+
return super.scanNext(offset);
|
|
73
|
+
}
|
|
74
|
+
comment() {
|
|
75
|
+
if (super.comment()) {
|
|
95
76
|
return true;
|
|
96
77
|
}
|
|
97
78
|
if (!this.inURL && this.stream.advanceIfChars([_FSL, _FSL])) {
|
|
98
|
-
this.stream.advanceWhileChar(
|
|
79
|
+
this.stream.advanceWhileChar((ch) => {
|
|
99
80
|
switch (ch) {
|
|
100
81
|
case _NWL:
|
|
101
82
|
case _CAR:
|
|
@@ -110,7 +91,5 @@ var SCSSScanner = /** @class */ (function (_super) {
|
|
|
110
91
|
else {
|
|
111
92
|
return false;
|
|
112
93
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
}(Scanner));
|
|
116
|
-
export { SCSSScanner };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -8,74 +8,70 @@ import { difference } from '../utils/strings';
|
|
|
8
8
|
import { Rules } from '../services/lintRules';
|
|
9
9
|
import { Command, TextEdit, CodeAction, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier } from '../cssLanguageTypes';
|
|
10
10
|
import * as nls from 'vscode-nls';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const localize = nls.loadMessageBundle();
|
|
12
|
+
export class CSSCodeActions {
|
|
13
|
+
constructor(cssDataManager) {
|
|
14
14
|
this.cssDataManager = cssDataManager;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
return this.doCodeActions2(document, range, context, stylesheet).map(
|
|
18
|
-
|
|
16
|
+
doCodeActions(document, range, context, stylesheet) {
|
|
17
|
+
return this.doCodeActions2(document, range, context, stylesheet).map(ca => {
|
|
18
|
+
const textDocumentEdit = ca.edit && ca.edit.documentChanges && ca.edit.documentChanges[0];
|
|
19
19
|
return Command.create(ca.title, '_css.applyCodeAction', document.uri, document.version, textDocumentEdit && textDocumentEdit.edits);
|
|
20
20
|
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
}
|
|
22
|
+
doCodeActions2(document, range, context, stylesheet) {
|
|
23
|
+
const result = [];
|
|
24
24
|
if (context.diagnostics) {
|
|
25
|
-
for (
|
|
26
|
-
var diagnostic = _a[_i];
|
|
25
|
+
for (const diagnostic of context.diagnostics) {
|
|
27
26
|
this.appendFixesForMarker(document, stylesheet, diagnostic, result);
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.cssDataManager.getProperties().forEach(
|
|
36
|
-
|
|
30
|
+
}
|
|
31
|
+
getFixesForUnknownProperty(document, property, marker, result) {
|
|
32
|
+
const propertyName = property.getName();
|
|
33
|
+
const candidates = [];
|
|
34
|
+
this.cssDataManager.getProperties().forEach(p => {
|
|
35
|
+
const score = difference(propertyName, p.name);
|
|
37
36
|
if (score >= propertyName.length / 2 /*score_lim*/) {
|
|
38
|
-
candidates.push({ property: p.name, score
|
|
37
|
+
candidates.push({ property: p.name, score });
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
40
|
// Sort in descending order.
|
|
42
|
-
candidates.sort(
|
|
41
|
+
candidates.sort((a, b) => {
|
|
43
42
|
return b.score - a.score || a.property.localeCompare(b.property);
|
|
44
43
|
});
|
|
45
|
-
|
|
46
|
-
for (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var codeAction = CodeAction.create(title, workspaceEdit, CodeActionKind.QuickFix);
|
|
44
|
+
let maxActions = 3;
|
|
45
|
+
for (const candidate of candidates) {
|
|
46
|
+
const propertyName = candidate.property;
|
|
47
|
+
const title = localize('css.codeaction.rename', "Rename to '{0}'", propertyName);
|
|
48
|
+
const edit = TextEdit.replace(marker.range, propertyName);
|
|
49
|
+
const documentIdentifier = VersionedTextDocumentIdentifier.create(document.uri, document.version);
|
|
50
|
+
const workspaceEdit = { documentChanges: [TextDocumentEdit.create(documentIdentifier, [edit])] };
|
|
51
|
+
const codeAction = CodeAction.create(title, workspaceEdit, CodeActionKind.QuickFix);
|
|
54
52
|
codeAction.diagnostics = [marker];
|
|
55
53
|
result.push(codeAction);
|
|
56
54
|
if (--maxActions <= 0) {
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
58
|
+
}
|
|
59
|
+
appendFixesForMarker(document, stylesheet, marker, result) {
|
|
62
60
|
if (marker.code !== Rules.UnknownProperty.id) {
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for (
|
|
69
|
-
|
|
63
|
+
const offset = document.offsetAt(marker.range.start);
|
|
64
|
+
const end = document.offsetAt(marker.range.end);
|
|
65
|
+
const nodepath = nodes.getNodePath(stylesheet, offset);
|
|
66
|
+
for (let i = nodepath.length - 1; i >= 0; i--) {
|
|
67
|
+
const node = nodepath[i];
|
|
70
68
|
if (node instanceof nodes.Declaration) {
|
|
71
|
-
|
|
69
|
+
const property = node.getProperty();
|
|
72
70
|
if (property && property.offset === offset && property.end === end) {
|
|
73
71
|
this.getFixesForUnknownProperty(document, property, marker, result);
|
|
74
72
|
return;
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
}());
|
|
81
|
-
export { CSSCodeActions };
|
|
76
|
+
}
|
|
77
|
+
}
|