vscode-css-languageservice 5.1.11 → 5.2.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.
@@ -1,4 +1,4 @@
1
- import { LanguageSettings, ICompletionParticipant, DocumentContext, LanguageServiceOptions, Diagnostic, Position, CompletionList, Hover, Location, DocumentHighlight, DocumentLink, SymbolInformation, Range, CodeActionContext, Command, CodeAction, ColorInformation, Color, ColorPresentation, WorkspaceEdit, FoldingRange, SelectionRange, TextDocument, ICSSDataProvider, CSSDataV1, HoverSettings, CompletionSettings } from './cssLanguageTypes';
1
+ import { LanguageSettings, ICompletionParticipant, DocumentContext, LanguageServiceOptions, Diagnostic, Position, CompletionList, Hover, Location, DocumentHighlight, DocumentLink, SymbolInformation, Range, CodeActionContext, Command, CodeAction, ColorInformation, Color, ColorPresentation, WorkspaceEdit, FoldingRange, SelectionRange, TextDocument, ICSSDataProvider, CSSDataV1, HoverSettings, CompletionSettings, TextEdit, CSSFormatConfiguration } from './cssLanguageTypes';
2
2
  export declare type Stylesheet = {};
3
3
  export * from './cssLanguageTypes';
4
4
  export interface LanguageService {
@@ -28,6 +28,7 @@ export interface LanguageService {
28
28
  rangeLimit?: number;
29
29
  }): FoldingRange[];
30
30
  getSelectionRanges(document: TextDocument, positions: Position[], stylesheet: Stylesheet): SelectionRange[];
31
+ format(document: TextDocument, range: Range | undefined, options: CSSFormatConfiguration): TextEdit[];
31
32
  }
32
33
  export declare function getDefaultCSSDataProvider(): ICSSDataProvider;
33
34
  export declare function newCSSDataProvider(data: CSSDataV1): ICSSDataProvider;
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  if (v !== undefined) module.exports = v;
15
15
  }
16
16
  else if (typeof define === "function" && define.amd) {
17
- define(["require", "exports", "./parser/cssParser", "./services/cssCompletion", "./services/cssHover", "./services/cssNavigation", "./services/cssCodeActions", "./services/cssValidation", "./parser/scssParser", "./services/scssCompletion", "./parser/lessParser", "./services/lessCompletion", "./services/cssFolding", "./languageFacts/dataManager", "./languageFacts/dataProvider", "./services/cssSelectionRange", "./services/scssNavigation", "./data/webCustomData", "./cssLanguageTypes"], factory);
17
+ define(["require", "exports", "./parser/cssParser", "./services/cssCompletion", "./services/cssHover", "./services/cssNavigation", "./services/cssCodeActions", "./services/cssValidation", "./parser/scssParser", "./services/scssCompletion", "./parser/lessParser", "./services/lessCompletion", "./services/cssFolding", "./services/cssFormatter", "./languageFacts/dataManager", "./languageFacts/dataProvider", "./services/cssSelectionRange", "./services/scssNavigation", "./data/webCustomData", "./cssLanguageTypes"], factory);
18
18
  }
19
19
  })(function (require, exports) {
20
20
  /*---------------------------------------------------------------------------------------------
@@ -35,6 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
35
  var lessParser_1 = require("./parser/lessParser");
36
36
  var lessCompletion_1 = require("./services/lessCompletion");
37
37
  var cssFolding_1 = require("./services/cssFolding");
38
+ var cssFormatter_1 = require("./services/cssFormatter");
38
39
  var dataManager_1 = require("./languageFacts/dataManager");
39
40
  var dataProvider_1 = require("./languageFacts/dataProvider");
40
41
  var cssSelectionRange_1 = require("./services/cssSelectionRange");
@@ -63,6 +64,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
63
64
  doComplete2: completion.doComplete2.bind(completion),
64
65
  setCompletionParticipants: completion.setCompletionParticipants.bind(completion),
65
66
  doHover: hover.doHover.bind(hover),
67
+ format: cssFormatter_1.format,
66
68
  findDefinition: navigation.findDefinition.bind(navigation),
67
69
  findReferences: navigation.findReferences.bind(navigation),
68
70
  findDocumentHighlights: navigation.findDocumentHighlights.bind(navigation),
@@ -210,3 +210,17 @@ export interface FileSystemProvider {
210
210
  stat(uri: DocumentUri): Promise<FileStat>;
211
211
  readDirectory?(uri: DocumentUri): Promise<[string, FileType][]>;
212
212
  }
213
+ export interface CSSFormatConfiguration {
214
+ /** indentation size. Default: 4 */
215
+ tabSize?: number;
216
+ /** Whether to use spaces or tabs */
217
+ insertSpaces?: boolean;
218
+ /** end with a newline: Default: false */
219
+ insertFinalNewline?: boolean;
220
+ /** separate selectors with newline or not (e.g. "a,\nbr" or "a, br"): Default: true */
221
+ selectorSeparatorNewline?: boolean;
222
+ /** add a new line after every css rule: Default: true */
223
+ newlineBetweenRules?: boolean;
224
+ /** ensure space around selector separators: '>', '+', '~' (e.g. "a>b" -> "a > b"): Default: false */
225
+ spaceAroundSelectorSeparator?: boolean;
226
+ }
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- // file generated from vscode-web-custom-data NPM package
5
+ // file generated from @vscode/web-custom-data NPM package
6
6
  (function (factory) {
7
7
  if (typeof module === "object" && typeof module.exports === "object") {
8
8
  var v = factory(require, exports);
@@ -13,7 +13,7 @@
13
13
  })(function (require, exports) {
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getColorValue = exports.hslFromColor = exports.colorFromHSL = exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = exports.isColorValue = exports.isColorConstructor = exports.colorKeywords = exports.colors = exports.colorFunctions = void 0;
16
+ exports.getColorValue = exports.hwbFromColor = exports.colorFromHWB = exports.hslFromColor = exports.colorFromHSL = exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = exports.isColorValue = exports.isColorConstructor = exports.colorKeywords = exports.colors = exports.colorFunctions = void 0;
17
17
  var nodes = require("../parser/cssNodes");
18
18
  var nls = require("vscode-nls");
19
19
  var localize = nls.loadMessageBundle();
@@ -21,7 +21,8 @@
21
21
  { func: 'rgb($red, $green, $blue)', desc: localize('css.builtin.rgb', 'Creates a Color from red, green, and blue values.') },
22
22
  { func: 'rgba($red, $green, $blue, $alpha)', desc: localize('css.builtin.rgba', 'Creates a Color from red, green, blue, and alpha values.') },
23
23
  { func: 'hsl($hue, $saturation, $lightness)', desc: localize('css.builtin.hsl', 'Creates a Color from hue, saturation, and lightness values.') },
24
- { func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') }
24
+ { func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') },
25
+ { func: 'hwb($hue $white $black)', desc: localize('css.builtin.hwb', 'Creates a Color from hue, white and black.') }
25
26
  ];
26
27
  exports.colors = {
27
28
  aliceblue: '#f0f8ff',
@@ -217,7 +218,7 @@
217
218
  if (!name) {
218
219
  return false;
219
220
  }
220
- return /^(rgb|rgba|hsl|hsla)$/gi.test(name);
221
+ return /^(rgb|rgba|hsl|hsla|hwb)$/gi.test(name);
221
222
  }
222
223
  exports.isColorConstructor = isColorConstructor;
223
224
  /**
@@ -377,6 +378,42 @@
377
378
  return { h: h, s: s, l: l, a: a };
378
379
  }
379
380
  exports.hslFromColor = hslFromColor;
381
+ function colorFromHWB(hue, white, black, alpha) {
382
+ if (alpha === void 0) { alpha = 1.0; }
383
+ if (white + black >= 1) {
384
+ var gray = white / (white + black);
385
+ return { red: gray, green: gray, blue: gray, alpha: alpha };
386
+ }
387
+ var rgb = colorFromHSL(hue, 1, 0.5, alpha);
388
+ var red = rgb.red;
389
+ red *= (1 - white - black);
390
+ red += white;
391
+ var green = rgb.green;
392
+ green *= (1 - white - black);
393
+ green += white;
394
+ var blue = rgb.blue;
395
+ blue *= (1 - white - black);
396
+ blue += white;
397
+ return {
398
+ red: red,
399
+ green: green,
400
+ blue: blue,
401
+ alpha: alpha
402
+ };
403
+ }
404
+ exports.colorFromHWB = colorFromHWB;
405
+ function hwbFromColor(rgba) {
406
+ var hsl = hslFromColor(rgba);
407
+ var white = Math.min(rgba.red, rgba.green, rgba.blue);
408
+ var black = 1 - Math.max(rgba.red, rgba.green, rgba.blue);
409
+ return {
410
+ h: hsl.h,
411
+ w: white,
412
+ b: black,
413
+ a: hsl.a
414
+ };
415
+ }
416
+ exports.hwbFromColor = hwbFromColor;
380
417
  function getColorValue(node) {
381
418
  if (node.type === nodes.NodeType.HexColorValue) {
382
419
  var text = node.getText();
@@ -420,6 +457,12 @@
420
457
  var l = getNumericValue(colorValues[2], 100.0);
421
458
  return colorFromHSL(h, s, l, alpha);
422
459
  }
460
+ else if (name === 'hwb') {
461
+ var h = getAngle(colorValues[0]);
462
+ var w = getNumericValue(colorValues[1], 100.0);
463
+ var b = getNumericValue(colorValues[2], 100.0);
464
+ return colorFromHWB(h, w, b, alpha);
465
+ }
423
466
  }
424
467
  catch (e) {
425
468
  // parse error on numeric value
@@ -28,7 +28,7 @@ var __extends = (this && this.__extends) || (function () {
28
28
  *--------------------------------------------------------------------------------------------*/
29
29
  'use strict';
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
31
+ exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
32
32
  var strings_1 = require("../utils/strings");
33
33
  /// <summary>
34
34
  /// Nodes for the css 2.1 specification. See for reference:
@@ -118,6 +118,7 @@ var __extends = (this && this.__extends) || (function () {
118
118
  NodeType[NodeType["Forward"] = 79] = "Forward";
119
119
  NodeType[NodeType["ForwardVisibility"] = 80] = "ForwardVisibility";
120
120
  NodeType[NodeType["Module"] = 81] = "Module";
121
+ NodeType[NodeType["UnicodeRange"] = 82] = "UnicodeRange";
121
122
  })(NodeType = exports.NodeType || (exports.NodeType = {}));
122
123
  var ReferenceType;
123
124
  (function (ReferenceType) {
@@ -408,6 +409,33 @@ var __extends = (this && this.__extends) || (function () {
408
409
  return Nodelist;
409
410
  }(Node));
410
411
  exports.Nodelist = Nodelist;
412
+ var UnicodeRange = /** @class */ (function (_super) {
413
+ __extends(UnicodeRange, _super);
414
+ function UnicodeRange(offset, length) {
415
+ return _super.call(this, offset, length) || this;
416
+ }
417
+ Object.defineProperty(UnicodeRange.prototype, "type", {
418
+ get: function () {
419
+ return NodeType.UnicodeRange;
420
+ },
421
+ enumerable: false,
422
+ configurable: true
423
+ });
424
+ UnicodeRange.prototype.setRangeStart = function (rangeStart) {
425
+ return this.setNode('rangeStart', rangeStart);
426
+ };
427
+ UnicodeRange.prototype.getRangeStart = function () {
428
+ return this.rangeStart;
429
+ };
430
+ UnicodeRange.prototype.setRangeEnd = function (rangeEnd) {
431
+ return this.setNode('rangeEnd', rangeEnd);
432
+ };
433
+ UnicodeRange.prototype.getRangeEnd = function () {
434
+ return this.rangeEnd;
435
+ };
436
+ return UnicodeRange;
437
+ }(Node));
438
+ exports.UnicodeRange = UnicodeRange;
411
439
  var Identifier = /** @class */ (function (_super) {
412
440
  __extends(Identifier, _super);
413
441
  function Identifier(offset, length) {
@@ -73,6 +73,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
73
  this.prevToken = this.token;
74
74
  this.token = this.scanner.scan();
75
75
  };
76
+ Parser.prototype.acceptUnicodeRange = function () {
77
+ var token = this.scanner.tryScanUnicode();
78
+ if (token) {
79
+ this.prevToken = token;
80
+ this.token = this.scanner.scan();
81
+ return true;
82
+ }
83
+ return false;
84
+ };
76
85
  Parser.prototype.mark = function () {
77
86
  return {
78
87
  prev: this.prevToken,
@@ -327,7 +336,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
327
336
  return this._parseUnknownAtRule();
328
337
  };
329
338
  Parser.prototype._parseRuleSetDeclaration = function () {
330
- // https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-declarations0
339
+ // https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-declarations
331
340
  if (this.peek(cssScanner_1.TokenType.AtKeyword)) {
332
341
  return this._parseRuleSetDeclarationAtStatement();
333
342
  }
@@ -1355,12 +1364,25 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
1355
1364
  }
1356
1365
  this.consumeToken();
1357
1366
  }
1367
+ else if (!this.hasWhitespace()) {
1368
+ break;
1369
+ }
1358
1370
  if (!node.addChild(this._parseBinaryExpr())) {
1359
1371
  break;
1360
1372
  }
1361
1373
  }
1362
1374
  return this.finish(node);
1363
1375
  };
1376
+ Parser.prototype._parseUnicodeRange = function () {
1377
+ if (!this.peekIdent('u')) {
1378
+ return null;
1379
+ }
1380
+ var node = this.create(nodes.UnicodeRange);
1381
+ if (!this.acceptUnicodeRange()) {
1382
+ return null;
1383
+ }
1384
+ return this.finish(node);
1385
+ };
1364
1386
  Parser.prototype._parseNamedLine = function () {
1365
1387
  // https://www.w3.org/TR/css-grid-1/#named-lines
1366
1388
  if (!this.peek(cssScanner_1.TokenType.BracketL)) {
@@ -1405,6 +1427,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
1405
1427
  };
1406
1428
  Parser.prototype._parseTermExpression = function () {
1407
1429
  return this._parseURILiteral() || // url before function
1430
+ this._parseUnicodeRange() ||
1408
1431
  this._parseFunction() || // function before ident
1409
1432
  this._parseIdent() ||
1410
1433
  this._parseStringLiteral() ||
@@ -129,6 +129,7 @@
129
129
  var _a = 'a'.charCodeAt(0);
130
130
  var _f = 'f'.charCodeAt(0);
131
131
  var _z = 'z'.charCodeAt(0);
132
+ var _u = 'u'.charCodeAt(0);
132
133
  var _A = 'A'.charCodeAt(0);
133
134
  var _F = 'F'.charCodeAt(0);
134
135
  var _Z = 'Z'.charCodeAt(0);
@@ -167,6 +168,8 @@
167
168
  var _CMA = ','.charCodeAt(0);
168
169
  var _DOT = '.'.charCodeAt(0);
169
170
  var _BNG = '!'.charCodeAt(0);
171
+ var _QSM = '?'.charCodeAt(0);
172
+ var _PLS = '+'.charCodeAt(0);
170
173
  var staticTokenTable = {};
171
174
  staticTokenTable[_SEM] = TokenType.SemiColon;
172
175
  staticTokenTable[_COL] = TokenType.Colon;
@@ -245,6 +248,19 @@
245
248
  }
246
249
  return this.scanNext(offset);
247
250
  };
251
+ /**
252
+ * Read the range as described in https://www.w3.org/TR/CSS21/syndata.html#tokenization
253
+ * Assume the `u` has aleady been consumed
254
+ * @returns if reading the unicode was successful
255
+ */
256
+ Scanner.prototype.tryScanUnicode = function () {
257
+ var offset = this.stream.pos();
258
+ if (!this.stream.eos() && this._unicodeRange()) {
259
+ return this.finishToken(offset, TokenType.UnicodeRange);
260
+ }
261
+ this.stream.goBackTo(offset);
262
+ return undefined;
263
+ };
248
264
  Scanner.prototype.scanNext = function (offset) {
249
265
  // CDO <!--
250
266
  if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) {
@@ -569,6 +585,26 @@
569
585
  }
570
586
  return false;
571
587
  };
588
+ Scanner.prototype._unicodeRange = function () {
589
+ // follow https://www.w3.org/TR/CSS21/syndata.html#tokenization and https://www.w3.org/TR/css-syntax-3/#urange-syntax
590
+ // assume u has already been parsed
591
+ if (this.stream.advanceIfChar(_PLS)) {
592
+ var isHexDigit = function (ch) { return (ch >= _0 && ch <= _9 || ch >= _a && ch <= _f || ch >= _A && ch <= _F); };
593
+ var codePoints = this.stream.advanceWhileChar(isHexDigit) + this.stream.advanceWhileChar(function (ch) { return ch === _QSM; });
594
+ if (codePoints >= 1 && codePoints <= 6) {
595
+ if (this.stream.advanceIfChar(_MIN)) {
596
+ var digits = this.stream.advanceWhileChar(isHexDigit);
597
+ if (digits >= 1 && digits <= 6) {
598
+ return true;
599
+ }
600
+ }
601
+ else {
602
+ return true;
603
+ }
604
+ }
605
+ }
606
+ return false;
607
+ };
572
608
  return Scanner;
573
609
  }());
574
610
  exports.Scanner = Scanner;
@@ -0,0 +1,131 @@
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", "../beautify/beautify-css", "../utils/strings"], factory);
12
+ }
13
+ })(function (require, exports) {
14
+ "use strict";
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.format = void 0;
17
+ var cssLanguageTypes_1 = require("../cssLanguageTypes");
18
+ var beautify_css_1 = require("../beautify/beautify-css");
19
+ var strings_1 = require("../utils/strings");
20
+ function format(document, range, options) {
21
+ var value = document.getText();
22
+ var includesEnd = true;
23
+ var initialIndentLevel = 0;
24
+ var tabSize = options.tabSize || 4;
25
+ if (range) {
26
+ var startOffset = document.offsetAt(range.start);
27
+ // include all leading whitespace iff at the beginning of the line
28
+ var extendedStart = startOffset;
29
+ while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) {
30
+ extendedStart--;
31
+ }
32
+ if (extendedStart === 0 || isEOL(value, extendedStart - 1)) {
33
+ startOffset = extendedStart;
34
+ }
35
+ else {
36
+ // else keep at least one whitespace
37
+ if (extendedStart < startOffset) {
38
+ startOffset = extendedStart + 1;
39
+ }
40
+ }
41
+ // include all following whitespace until the end of the line
42
+ var endOffset = document.offsetAt(range.end);
43
+ var extendedEnd = endOffset;
44
+ while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) {
45
+ extendedEnd++;
46
+ }
47
+ if (extendedEnd === value.length || isEOL(value, extendedEnd)) {
48
+ endOffset = extendedEnd;
49
+ }
50
+ range = cssLanguageTypes_1.Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
51
+ // Do not modify if substring starts in inside an element
52
+ // Ending inside an element is fine as it doesn't cause formatting errors
53
+ var firstHalf = value.substring(0, startOffset);
54
+ if (new RegExp(/.*[<][^>]*$/).test(firstHalf)) {
55
+ //return without modification
56
+ value = value.substring(startOffset, endOffset);
57
+ return [{
58
+ range: range,
59
+ newText: value
60
+ }];
61
+ }
62
+ includesEnd = endOffset === value.length;
63
+ value = value.substring(startOffset, endOffset);
64
+ if (startOffset !== 0) {
65
+ var startOfLineOffset = document.offsetAt(cssLanguageTypes_1.Position.create(range.start.line, 0));
66
+ initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
67
+ }
68
+ }
69
+ else {
70
+ range = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(0, 0), document.positionAt(value.length));
71
+ }
72
+ var cssOptions = {
73
+ indent_size: tabSize,
74
+ indent_char: options.insertSpaces ? ' ' : '\t',
75
+ end_with_newline: includesEnd && getFormatOption(options, 'insertFinalNewline', false),
76
+ selector_separator_newline: getFormatOption(options, 'selectorSeparatorNewline', true),
77
+ newline_between_rules: getFormatOption(options, 'newlineBetweenRules', true),
78
+ space_around_selector_separator: getFormatOption(options, 'spaceAroundSelectorSeparator', false)
79
+ };
80
+ var result = (0, beautify_css_1.css_beautify)(trimLeft(value), cssOptions);
81
+ if (initialIndentLevel > 0) {
82
+ var indent = options.insertSpaces ? (0, strings_1.repeat)(' ', tabSize * initialIndentLevel) : (0, strings_1.repeat)('\t', initialIndentLevel);
83
+ result = result.split('\n').join('\n' + indent);
84
+ if (range.start.character === 0) {
85
+ result = indent + result; // keep the indent
86
+ }
87
+ }
88
+ return [{
89
+ range: range,
90
+ newText: result
91
+ }];
92
+ }
93
+ exports.format = format;
94
+ function trimLeft(str) {
95
+ return str.replace(/^\s+/, '');
96
+ }
97
+ function getFormatOption(options, key, dflt) {
98
+ if (options && options.hasOwnProperty(key)) {
99
+ var value = options[key];
100
+ if (value !== null) {
101
+ return value;
102
+ }
103
+ }
104
+ return dflt;
105
+ }
106
+ function computeIndentLevel(content, offset, options) {
107
+ var i = offset;
108
+ var nChars = 0;
109
+ var tabSize = options.tabSize || 4;
110
+ while (i < content.length) {
111
+ var ch = content.charAt(i);
112
+ if (ch === ' ') {
113
+ nChars++;
114
+ }
115
+ else if (ch === '\t') {
116
+ nChars += tabSize;
117
+ }
118
+ else {
119
+ break;
120
+ }
121
+ i++;
122
+ }
123
+ return Math.floor(nChars / tabSize);
124
+ }
125
+ function isEOL(text, offset) {
126
+ return '\r\n'.indexOf(text.charAt(offset)) !== -1;
127
+ }
128
+ function isWhitespace(text, offset) {
129
+ return ' \t'.indexOf(text.charAt(offset)) !== -1;
130
+ }
131
+ });
@@ -314,6 +314,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
314
314
  label = "hsla(".concat(hsl.h, ", ").concat(Math.round(hsl.s * 100), "%, ").concat(Math.round(hsl.l * 100), "%, ").concat(hsl.a, ")");
315
315
  }
316
316
  result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
317
+ var hwb = (0, facts_1.hwbFromColor)(color);
318
+ if (hwb.a === 1) {
319
+ label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "%)");
320
+ }
321
+ else {
322
+ label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "% / ").concat(hwb.a, ")");
323
+ }
324
+ result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) });
317
325
  return result;
318
326
  };
319
327
  CSSNavigation.prototype.doRename = function (document, position, newName, stylesheet) {
@@ -374,7 +374,8 @@ var __extends = (this && this.__extends) || (function () {
374
374
  var _this = this;
375
375
  //https://www.w3.org/TR/selectors-3/#specificity
376
376
  var calculateScore = function (node) {
377
- for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
377
+ var specificity = new Specificity();
378
+ elementLoop: for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
378
379
  var element = _a[_i];
379
380
  switch (element.type) {
380
381
  case nodes.NodeType.IdentifierSelector:
@@ -395,23 +396,66 @@ var __extends = (this && this.__extends) || (function () {
395
396
  var text = element.getText();
396
397
  if (_this.isPseudoElementIdentifier(text)) {
397
398
  specificity.tag++; // pseudo element
399
+ break;
398
400
  }
399
- else {
400
- //ignore psuedo class NOT
401
- if (text.match(/^:not/i)) {
402
- break;
401
+ // where and child selectors have zero specificity
402
+ if (text.match(/^:where/i)) {
403
+ continue elementLoop;
404
+ }
405
+ // the most specific child selector
406
+ if (text.match(/^:(not|has|is)/i) && element.getChildren().length > 0) {
407
+ var mostSpecificListItem = new Specificity();
408
+ for (var _b = 0, _c = element.getChildren(); _b < _c.length; _b++) {
409
+ var containerElement = _c[_b];
410
+ var list = void 0;
411
+ if (containerElement.type === nodes.NodeType.Undefined) { // containerElement is a list of selectors
412
+ list = containerElement.getChildren();
413
+ }
414
+ else { // containerElement is a selector
415
+ list = [containerElement];
416
+ }
417
+ for (var _d = 0, _e = containerElement.getChildren(); _d < _e.length; _d++) {
418
+ var childElement = _e[_d];
419
+ var itemSpecificity = calculateScore(childElement);
420
+ if (itemSpecificity.id > mostSpecificListItem.id) {
421
+ mostSpecificListItem = itemSpecificity;
422
+ continue;
423
+ }
424
+ else if (itemSpecificity.id < mostSpecificListItem.id) {
425
+ continue;
426
+ }
427
+ if (itemSpecificity.attr > mostSpecificListItem.attr) {
428
+ mostSpecificListItem = itemSpecificity;
429
+ continue;
430
+ }
431
+ else if (itemSpecificity.attr < mostSpecificListItem.attr) {
432
+ continue;
433
+ }
434
+ if (itemSpecificity.tag > mostSpecificListItem.tag) {
435
+ mostSpecificListItem = itemSpecificity;
436
+ continue;
437
+ }
438
+ }
403
439
  }
404
- specificity.attr++; //pseudo class
440
+ specificity.id += mostSpecificListItem.id;
441
+ specificity.attr += mostSpecificListItem.attr;
442
+ specificity.tag += mostSpecificListItem.tag;
443
+ continue elementLoop;
405
444
  }
445
+ specificity.attr++; //pseudo class
406
446
  break;
407
447
  }
408
448
  if (element.getChildren().length > 0) {
409
- calculateScore(element);
449
+ var itemSpecificity = calculateScore(element);
450
+ specificity.id += itemSpecificity.id;
451
+ specificity.attr += itemSpecificity.attr;
452
+ specificity.tag += itemSpecificity.tag;
410
453
  }
411
454
  }
455
+ return specificity;
412
456
  };
413
- var specificity = new Specificity();
414
- calculateScore(node);
457
+ var specificity = calculateScore(node);
458
+ ;
415
459
  return localize('specificity', "[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): ({0}, {1}, {2})", specificity.id, specificity.attr, specificity.tag);
416
460
  };
417
461
  return SelectorPrinting;
@@ -13,7 +13,7 @@
13
13
  *--------------------------------------------------------------------------------------------*/
14
14
  'use strict';
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.trim = exports.getLimitedString = exports.difference = exports.endsWith = exports.startsWith = void 0;
16
+ exports.repeat = exports.trim = exports.getLimitedString = exports.difference = exports.endsWith = exports.startsWith = void 0;
17
17
  function startsWith(haystack, needle) {
18
18
  if (haystack.length < needle.length) {
19
19
  return false;
@@ -107,4 +107,16 @@
107
107
  return str;
108
108
  }
109
109
  exports.trim = trim;
110
+ function repeat(value, count) {
111
+ var s = '';
112
+ while (count > 0) {
113
+ if ((count & 1) === 1) {
114
+ s += value;
115
+ }
116
+ value += value;
117
+ count = count >>> 1;
118
+ }
119
+ return s;
120
+ }
121
+ exports.repeat = repeat;
110
122
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vscode-css-languageservice",
3
- "version": "5.1.11",
3
+ "version": "5.2.0",
4
4
  "description": "Language service for CSS, LESS and SCSS",
5
5
  "main": "./lib/umd/cssLanguageService.js",
6
6
  "typings": "./lib/umd/cssLanguageService",
@@ -17,34 +17,38 @@
17
17
  "devDependencies": {
18
18
  "@types/mocha": "^9.1.0",
19
19
  "@types/node": "^10.12.21",
20
- "@typescript-eslint/eslint-plugin": "^5.10.1",
21
- "@typescript-eslint/parser": "^5.10.1",
22
- "@vscode/web-custom-data": "^0.3.6",
23
- "eslint": "^8.7.0",
24
- "mocha": "^9.2.0",
20
+ "@typescript-eslint/eslint-plugin": "^5.15.0",
21
+ "@typescript-eslint/parser": "^5.15.0",
22
+ "@vscode/web-custom-data": "^0.3.8",
23
+ "eslint": "^8.11.0",
24
+ "js-beautify": "^1.14.0",
25
+ "mocha": "^9.2.2",
25
26
  "rimraf": "^3.0.2",
26
27
  "typescript": "^4.5.5"
27
28
  },
28
29
  "dependencies": {
29
- "vscode-languageserver-textdocument": "^1.0.1",
30
+ "vscode-languageserver-textdocument": "^1.0.4",
30
31
  "vscode-languageserver-types": "^3.16.0",
31
32
  "vscode-nls": "^5.0.0",
32
- "vscode-uri": "^3.0.2"
33
+ "vscode-uri": "^3.0.3"
33
34
  },
34
35
  "scripts": {
35
36
  "prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
36
37
  "postpublish": "node ./build/post-publish.js",
37
- "compile": "tsc -p ./src && npm run lint",
38
+ "compile": "tsc -p ./src && npm run copy-jsbeautify && npm run lint ",
38
39
  "compile-esm": "tsc -p ./src/tsconfig.esm.json",
39
40
  "clean": "rimraf lib",
40
41
  "remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
41
- "watch": "tsc -w -p ./src",
42
+ "watch": "npm run copy-jsbeautify && tsc -w -p ./src",
42
43
  "test": "npm run compile && mocha",
43
44
  "mocha": "mocha",
44
45
  "coverage": "npm run compile && npx nyc --reporter=html --reporter=text mocha",
45
46
  "lint": "eslint src/**/*.ts",
46
47
  "update-data": "yarn add @vscode/web-custom-data -D && node ./build/generateData.js",
47
48
  "install-types-next": "yarn add vscode-languageserver-types@next -f -S && yarn add vscode-languageserver-textdocument@next -f -S",
49
+ "copy-jsbeautify": "node ./build/copy-jsbeautify.js",
50
+ "update-jsbeautify": "yarn add js-beautify && node ./build/update-jsbeautify.js",
51
+ "update-jsbeautify-next": "yarn add js-beautify@next && node ./build/update-jsbeautify.js",
48
52
  "preversion": "npm test",
49
53
  "postversion": "git push && git push --tags"
50
54
  }