vscode-css-languageservice 5.2.0 → 5.4.2
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 +9 -0
- package/README.md +1 -0
- package/lib/esm/beautify/beautify-css.js +57 -15
- package/lib/esm/cssLanguageTypes.d.ts +14 -2
- package/lib/esm/data/webCustomData.js +145 -139
- package/lib/esm/parser/cssParser.js +0 -3
- package/lib/esm/services/cssFormatter.js +33 -14
- package/lib/esm/services/selectorPrinting.js +2 -2
- package/lib/umd/beautify/beautify-css.js +57 -15
- package/lib/umd/cssLanguageTypes.d.ts +14 -2
- package/lib/umd/data/webCustomData.js +145 -139
- package/lib/umd/parser/cssParser.js +0 -3
- package/lib/umd/services/cssFormatter.js +33 -14
- package/lib/umd/services/selectorPrinting.js +2 -2
- package/package.json +5 -5
|
@@ -9,6 +9,7 @@ export function format(document, range, options) {
|
|
|
9
9
|
var value = document.getText();
|
|
10
10
|
var includesEnd = true;
|
|
11
11
|
var initialIndentLevel = 0;
|
|
12
|
+
var inRule = false;
|
|
12
13
|
var tabSize = options.tabSize || 4;
|
|
13
14
|
if (range) {
|
|
14
15
|
var startOffset = document.offsetAt(range.start);
|
|
@@ -36,23 +37,17 @@ export function format(document, range, options) {
|
|
|
36
37
|
endOffset = extendedEnd;
|
|
37
38
|
}
|
|
38
39
|
range = Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
var firstHalf = value.substring(0, startOffset);
|
|
42
|
-
if (new RegExp(/.*[<][^>]*$/).test(firstHalf)) {
|
|
43
|
-
//return without modification
|
|
44
|
-
value = value.substring(startOffset, endOffset);
|
|
45
|
-
return [{
|
|
46
|
-
range: range,
|
|
47
|
-
newText: value
|
|
48
|
-
}];
|
|
49
|
-
}
|
|
40
|
+
// Test if inside a rule
|
|
41
|
+
inRule = isInRule(value, startOffset);
|
|
50
42
|
includesEnd = endOffset === value.length;
|
|
51
43
|
value = value.substring(startOffset, endOffset);
|
|
52
44
|
if (startOffset !== 0) {
|
|
53
45
|
var startOfLineOffset = document.offsetAt(Position.create(range.start.line, 0));
|
|
54
46
|
initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
|
|
55
47
|
}
|
|
48
|
+
if (inRule) {
|
|
49
|
+
value = "{\n".concat(trimLeft(value));
|
|
50
|
+
}
|
|
56
51
|
}
|
|
57
52
|
else {
|
|
58
53
|
range = Range.create(Position.create(0, 0), document.positionAt(value.length));
|
|
@@ -61,11 +56,20 @@ export function format(document, range, options) {
|
|
|
61
56
|
indent_size: tabSize,
|
|
62
57
|
indent_char: options.insertSpaces ? ' ' : '\t',
|
|
63
58
|
end_with_newline: includesEnd && getFormatOption(options, 'insertFinalNewline', false),
|
|
64
|
-
selector_separator_newline: getFormatOption(options, '
|
|
59
|
+
selector_separator_newline: getFormatOption(options, 'newlineBetweenSelectors', true),
|
|
65
60
|
newline_between_rules: getFormatOption(options, 'newlineBetweenRules', true),
|
|
66
|
-
space_around_selector_separator: getFormatOption(options, 'spaceAroundSelectorSeparator', false)
|
|
61
|
+
space_around_selector_separator: getFormatOption(options, 'spaceAroundSelectorSeparator', false),
|
|
62
|
+
brace_style: getFormatOption(options, 'braceStyle', 'collapse'),
|
|
63
|
+
indent_empty_lines: getFormatOption(options, 'indentEmptyLines', false),
|
|
64
|
+
max_preserve_newlines: getFormatOption(options, 'maxPreserveNewLines', undefined),
|
|
65
|
+
preserve_newlines: getFormatOption(options, 'preserveNewLines', true),
|
|
66
|
+
wrap_line_length: getFormatOption(options, 'wrapLineLength', undefined),
|
|
67
|
+
eol: '\n'
|
|
67
68
|
};
|
|
68
|
-
var result = css_beautify(
|
|
69
|
+
var result = css_beautify(value, cssOptions);
|
|
70
|
+
if (inRule) {
|
|
71
|
+
result = trimLeft(result.substring(2));
|
|
72
|
+
}
|
|
69
73
|
if (initialIndentLevel > 0) {
|
|
70
74
|
var indent = options.insertSpaces ? repeat(' ', tabSize * initialIndentLevel) : repeat('\t', initialIndentLevel);
|
|
71
75
|
result = result.split('\n').join('\n' + indent);
|
|
@@ -81,6 +85,21 @@ export function format(document, range, options) {
|
|
|
81
85
|
function trimLeft(str) {
|
|
82
86
|
return str.replace(/^\s+/, '');
|
|
83
87
|
}
|
|
88
|
+
var _CUL = '{'.charCodeAt(0);
|
|
89
|
+
var _CUR = '}'.charCodeAt(0);
|
|
90
|
+
function isInRule(str, offset) {
|
|
91
|
+
while (offset >= 0) {
|
|
92
|
+
var ch = str.charCodeAt(offset);
|
|
93
|
+
if (ch === _CUL) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
else if (ch === _CUR) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
offset--;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
84
103
|
function getFormatOption(options, key, dflt) {
|
|
85
104
|
if (options && options.hasOwnProperty(key)) {
|
|
86
105
|
var value = options[key];
|
|
@@ -384,7 +384,7 @@ var SelectorPrinting = /** @class */ (function () {
|
|
|
384
384
|
var text = element.getText();
|
|
385
385
|
if (_this.isPseudoElementIdentifier(text)) {
|
|
386
386
|
specificity.tag++; // pseudo element
|
|
387
|
-
|
|
387
|
+
continue elementLoop;
|
|
388
388
|
}
|
|
389
389
|
// where and child selectors have zero specificity
|
|
390
390
|
if (text.match(/^:where/i)) {
|
|
@@ -431,7 +431,7 @@ var SelectorPrinting = /** @class */ (function () {
|
|
|
431
431
|
continue elementLoop;
|
|
432
432
|
}
|
|
433
433
|
specificity.attr++; //pseudo class
|
|
434
|
-
|
|
434
|
+
continue elementLoop;
|
|
435
435
|
}
|
|
436
436
|
if (element.getChildren().length > 0) {
|
|
437
437
|
var itemSpecificity = calculateScore(element);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// copied from js-beautify/js/lib/beautify-css.js
|
|
2
|
-
// version: 1.14.
|
|
2
|
+
// version: 1.14.3
|
|
3
3
|
/* AUTO-GENERATED. DO NOT MODIFY. */
|
|
4
4
|
/*
|
|
5
5
|
|
|
@@ -1005,8 +1005,8 @@ module.exports.Directives = Directives;
|
|
|
1005
1005
|
|
|
1006
1006
|
|
|
1007
1007
|
|
|
1008
|
-
var Beautifier = __webpack_require__(16).Beautifier,
|
|
1009
|
-
Options = __webpack_require__(17).Options;
|
|
1008
|
+
var Beautifier = (__webpack_require__(16).Beautifier),
|
|
1009
|
+
Options = (__webpack_require__(17).Options);
|
|
1010
1010
|
|
|
1011
1011
|
function css_beautify(source_text, options) {
|
|
1012
1012
|
var beautifier = new Beautifier(source_text, options);
|
|
@@ -1053,10 +1053,10 @@ module.exports.defaultOptions = function() {
|
|
|
1053
1053
|
|
|
1054
1054
|
|
|
1055
1055
|
|
|
1056
|
-
var Options = __webpack_require__(17).Options;
|
|
1057
|
-
var Output = __webpack_require__(2).Output;
|
|
1058
|
-
var InputScanner = __webpack_require__(8).InputScanner;
|
|
1059
|
-
var Directives = __webpack_require__(13).Directives;
|
|
1056
|
+
var Options = (__webpack_require__(17).Options);
|
|
1057
|
+
var Output = (__webpack_require__(2).Output);
|
|
1058
|
+
var InputScanner = (__webpack_require__(8).InputScanner);
|
|
1059
|
+
var Directives = (__webpack_require__(13).Directives);
|
|
1060
1060
|
|
|
1061
1061
|
var directives_core = new Directives(/\/\*/, /\*\//);
|
|
1062
1062
|
|
|
@@ -1092,6 +1092,9 @@ function Beautifier(source_text, options) {
|
|
|
1092
1092
|
"@supports": true,
|
|
1093
1093
|
"@document": true
|
|
1094
1094
|
};
|
|
1095
|
+
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
|
|
1096
|
+
"grid-template"
|
|
1097
|
+
];
|
|
1095
1098
|
|
|
1096
1099
|
}
|
|
1097
1100
|
|
|
@@ -1216,7 +1219,9 @@ Beautifier.prototype.beautify = function() {
|
|
|
1216
1219
|
var enteringConditionalGroup = false;
|
|
1217
1220
|
var insideAtExtend = false;
|
|
1218
1221
|
var insideAtImport = false;
|
|
1222
|
+
var insideScssMap = false;
|
|
1219
1223
|
var topCharacter = this._ch;
|
|
1224
|
+
var insideNonSemiColonValues = false;
|
|
1220
1225
|
var whitespace;
|
|
1221
1226
|
var isAfterSpace;
|
|
1222
1227
|
var previous_ch;
|
|
@@ -1268,7 +1273,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
1268
1273
|
|
|
1269
1274
|
// Ensures any new lines following the comment are preserved
|
|
1270
1275
|
this.eatWhitespace(true);
|
|
1271
|
-
} else if (this._ch === '@') {
|
|
1276
|
+
} else if (this._ch === '@' || this._ch === '$') {
|
|
1272
1277
|
this.preserveSingleSpace(isAfterSpace);
|
|
1273
1278
|
|
|
1274
1279
|
// deal with less propery mixins @{...}
|
|
@@ -1339,7 +1344,12 @@ Beautifier.prototype.beautify = function() {
|
|
|
1339
1344
|
this.indent();
|
|
1340
1345
|
this._output.set_indent(this._indentLevel);
|
|
1341
1346
|
} else {
|
|
1342
|
-
|
|
1347
|
+
// inside mixin and first param is object
|
|
1348
|
+
if (previous_ch === '(') {
|
|
1349
|
+
this._output.space_before_token = false;
|
|
1350
|
+
} else if (previous_ch !== ',') {
|
|
1351
|
+
this.indent();
|
|
1352
|
+
}
|
|
1343
1353
|
this.print_string(this._ch);
|
|
1344
1354
|
}
|
|
1345
1355
|
|
|
@@ -1371,7 +1381,21 @@ Beautifier.prototype.beautify = function() {
|
|
|
1371
1381
|
this._output.add_new_line(true);
|
|
1372
1382
|
}
|
|
1373
1383
|
}
|
|
1384
|
+
if (this._input.peek() === ')') {
|
|
1385
|
+
this._output.trim(true);
|
|
1386
|
+
if (this._options.brace_style === "expand") {
|
|
1387
|
+
this._output.add_new_line(true);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1374
1390
|
} else if (this._ch === ":") {
|
|
1391
|
+
|
|
1392
|
+
for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
|
|
1393
|
+
if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
|
|
1394
|
+
insideNonSemiColonValues = true;
|
|
1395
|
+
break;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1375
1399
|
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
|
|
1376
1400
|
// 'property: value' delimiter
|
|
1377
1401
|
// which could be in a conditional group query
|
|
@@ -1404,6 +1428,7 @@ Beautifier.prototype.beautify = function() {
|
|
|
1404
1428
|
this.print_string(this._ch + this.eatString(this._ch));
|
|
1405
1429
|
this.eatWhitespace(true);
|
|
1406
1430
|
} else if (this._ch === ';') {
|
|
1431
|
+
insideNonSemiColonValues = false;
|
|
1407
1432
|
if (parenLevel === 0) {
|
|
1408
1433
|
if (insidePropertyValue) {
|
|
1409
1434
|
this.outdent();
|
|
@@ -1445,20 +1470,32 @@ Beautifier.prototype.beautify = function() {
|
|
|
1445
1470
|
} else {
|
|
1446
1471
|
this.preserveSingleSpace(isAfterSpace);
|
|
1447
1472
|
this.print_string(this._ch);
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
this.
|
|
1473
|
+
|
|
1474
|
+
// handle scss/sass map
|
|
1475
|
+
if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
|
|
1476
|
+
this._output.add_new_line();
|
|
1477
|
+
insideScssMap = true;
|
|
1478
|
+
} else {
|
|
1479
|
+
this.eatWhitespace();
|
|
1480
|
+
parenLevel++;
|
|
1481
|
+
this.indent();
|
|
1482
|
+
}
|
|
1451
1483
|
}
|
|
1452
1484
|
} else if (this._ch === ')') {
|
|
1453
1485
|
if (parenLevel) {
|
|
1454
1486
|
parenLevel--;
|
|
1455
1487
|
this.outdent();
|
|
1456
1488
|
}
|
|
1489
|
+
if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
|
|
1490
|
+
insideScssMap = false;
|
|
1491
|
+
this.outdent();
|
|
1492
|
+
this._output.add_new_line();
|
|
1493
|
+
}
|
|
1457
1494
|
this.print_string(this._ch);
|
|
1458
1495
|
} else if (this._ch === ',') {
|
|
1459
1496
|
this.print_string(this._ch);
|
|
1460
1497
|
this.eatWhitespace(true);
|
|
1461
|
-
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
|
|
1498
|
+
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
|
|
1462
1499
|
this._output.add_new_line();
|
|
1463
1500
|
} else {
|
|
1464
1501
|
this._output.space_before_token = true;
|
|
@@ -1492,8 +1529,13 @@ Beautifier.prototype.beautify = function() {
|
|
|
1492
1529
|
this.print_string(' ');
|
|
1493
1530
|
this.print_string(this._ch);
|
|
1494
1531
|
} else {
|
|
1495
|
-
|
|
1532
|
+
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
|
|
1533
|
+
this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
|
|
1496
1534
|
this.print_string(this._ch);
|
|
1535
|
+
|
|
1536
|
+
if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
|
|
1537
|
+
this._output.add_new_line();
|
|
1538
|
+
}
|
|
1497
1539
|
}
|
|
1498
1540
|
}
|
|
1499
1541
|
|
|
@@ -1539,7 +1581,7 @@ module.exports.Beautifier = Beautifier;
|
|
|
1539
1581
|
|
|
1540
1582
|
|
|
1541
1583
|
|
|
1542
|
-
var BaseOptions = __webpack_require__(6).Options;
|
|
1584
|
+
var BaseOptions = (__webpack_require__(6).Options);
|
|
1543
1585
|
|
|
1544
1586
|
function Options(options) {
|
|
1545
1587
|
BaseOptions.call(this, options, 'css');
|
|
@@ -217,10 +217,22 @@ export interface CSSFormatConfiguration {
|
|
|
217
217
|
insertSpaces?: boolean;
|
|
218
218
|
/** end with a newline: Default: false */
|
|
219
219
|
insertFinalNewline?: boolean;
|
|
220
|
-
/** separate selectors with newline
|
|
221
|
-
|
|
220
|
+
/** separate selectors with newline (e.g. "a,\nbr" or "a, br"): Default: true */
|
|
221
|
+
newlineBetweenSelectors?: boolean;
|
|
222
222
|
/** add a new line after every css rule: Default: true */
|
|
223
223
|
newlineBetweenRules?: boolean;
|
|
224
224
|
/** ensure space around selector separators: '>', '+', '~' (e.g. "a>b" -> "a > b"): Default: false */
|
|
225
225
|
spaceAroundSelectorSeparator?: boolean;
|
|
226
|
+
/** put braces on the same line as rules (`collapse`), or put braces on own line, Allman / ANSI style (`expand`). Default `collapse` */
|
|
227
|
+
braceStyle?: 'collapse' | 'expand';
|
|
228
|
+
/** whether existing line breaks before elements should be preserved. Default: true */
|
|
229
|
+
preserveNewLines?: boolean;
|
|
230
|
+
/** maximum number of line breaks to be preserved in one chunk. Default: unlimited */
|
|
231
|
+
maxPreserveNewLines?: number;
|
|
232
|
+
/** maximum amount of characters per line (0/undefined = disabled). Default: disabled. */
|
|
233
|
+
wrapLineLength?: number;
|
|
234
|
+
/** add indenting whitespace to empty lines. Default: false */
|
|
235
|
+
indentEmptyLines?: boolean;
|
|
236
|
+
/** @deprecated Use newlineBetweenSelectors instead*/
|
|
237
|
+
selectorSeparatorNewline?: boolean;
|
|
226
238
|
}
|