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.
Files changed (83) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +2 -1
  5. package/lib/esm/cssLanguageService.js +15 -17
  6. package/lib/esm/cssLanguageTypes.js +2 -2
  7. package/lib/esm/data/webCustomData.js +356 -232
  8. package/lib/esm/languageFacts/builtinData.js +15 -15
  9. package/lib/esm/languageFacts/colors.js +66 -69
  10. package/lib/esm/languageFacts/dataManager.js +38 -42
  11. package/lib/esm/languageFacts/dataProvider.js +17 -23
  12. package/lib/esm/languageFacts/entry.js +22 -23
  13. package/lib/esm/parser/cssErrors.js +5 -7
  14. package/lib/esm/parser/cssNodes.js +869 -1377
  15. package/lib/esm/parser/cssParser.js +419 -376
  16. package/lib/esm/parser/cssScanner.js +168 -175
  17. package/lib/esm/parser/cssSymbolScope.js +107 -137
  18. package/lib/esm/parser/lessParser.js +177 -202
  19. package/lib/esm/parser/lessScanner.js +22 -43
  20. package/lib/esm/parser/scssErrors.js +5 -7
  21. package/lib/esm/parser/scssParser.js +196 -208
  22. package/lib/esm/parser/scssScanner.js +33 -54
  23. package/lib/esm/services/cssCodeActions.js +36 -40
  24. package/lib/esm/services/cssCompletion.js +300 -395
  25. package/lib/esm/services/cssFolding.js +32 -35
  26. package/lib/esm/services/cssFormatter.js +22 -22
  27. package/lib/esm/services/cssHover.js +30 -33
  28. package/lib/esm/services/cssNavigation.js +260 -289
  29. package/lib/esm/services/cssSelectionRange.js +6 -6
  30. package/lib/esm/services/cssValidation.js +13 -16
  31. package/lib/esm/services/lessCompletion.js +351 -370
  32. package/lib/esm/services/lint.js +161 -175
  33. package/lib/esm/services/lintRules.js +20 -27
  34. package/lib/esm/services/lintUtil.js +19 -28
  35. package/lib/esm/services/pathCompletion.js +84 -158
  36. package/lib/esm/services/scssCompletion.js +283 -307
  37. package/lib/esm/services/scssNavigation.js +65 -137
  38. package/lib/esm/services/selectorPrinting.js +131 -175
  39. package/lib/esm/utils/arrays.js +6 -12
  40. package/lib/esm/utils/objects.js +1 -1
  41. package/lib/esm/utils/resources.js +3 -16
  42. package/lib/esm/utils/strings.js +10 -12
  43. package/lib/umd/beautify/beautify-css.js +11 -4
  44. package/lib/umd/cssLanguageService.d.ts +2 -1
  45. package/lib/umd/cssLanguageService.js +34 -32
  46. package/lib/umd/cssLanguageTypes.js +4 -3
  47. package/lib/umd/data/webCustomData.js +355 -231
  48. package/lib/umd/languageFacts/colors.js +65 -68
  49. package/lib/umd/languageFacts/dataManager.js +41 -44
  50. package/lib/umd/languageFacts/dataProvider.js +17 -22
  51. package/lib/umd/languageFacts/entry.js +22 -23
  52. package/lib/umd/languageFacts/facts.js +5 -1
  53. package/lib/umd/parser/cssErrors.js +5 -6
  54. package/lib/umd/parser/cssNodes.js +870 -1307
  55. package/lib/umd/parser/cssParser.js +424 -380
  56. package/lib/umd/parser/cssScanner.js +168 -173
  57. package/lib/umd/parser/cssSymbolScope.js +109 -134
  58. package/lib/umd/parser/lessParser.js +182 -206
  59. package/lib/umd/parser/lessScanner.js +22 -42
  60. package/lib/umd/parser/scssErrors.js +5 -6
  61. package/lib/umd/parser/scssParser.js +202 -213
  62. package/lib/umd/parser/scssScanner.js +25 -45
  63. package/lib/umd/services/cssCodeActions.js +41 -44
  64. package/lib/umd/services/cssCompletion.js +308 -402
  65. package/lib/umd/services/cssFolding.js +35 -38
  66. package/lib/umd/services/cssFormatter.js +25 -25
  67. package/lib/umd/services/cssHover.js +36 -38
  68. package/lib/umd/services/cssNavigation.js +267 -295
  69. package/lib/umd/services/cssSelectionRange.js +8 -8
  70. package/lib/umd/services/cssValidation.js +17 -19
  71. package/lib/umd/services/lessCompletion.js +354 -372
  72. package/lib/umd/services/lint.js +167 -180
  73. package/lib/umd/services/lintRules.js +20 -24
  74. package/lib/umd/services/lintUtil.js +20 -28
  75. package/lib/umd/services/pathCompletion.js +87 -160
  76. package/lib/umd/services/scssCompletion.js +287 -310
  77. package/lib/umd/services/scssNavigation.js +69 -140
  78. package/lib/umd/services/selectorPrinting.js +134 -174
  79. package/lib/umd/utils/arrays.js +6 -12
  80. package/lib/umd/utils/objects.js +1 -1
  81. package/lib/umd/utils/resources.js +4 -17
  82. package/lib/umd/utils/strings.js +10 -12
  83. package/package.json +16 -15
@@ -7,7 +7,7 @@ import { TokenType, Scanner } from '../parser/cssScanner';
7
7
  import { SCSSScanner, InterpolationFunction } from '../parser/scssScanner';
8
8
  import { LESSScanner } from '../parser/lessScanner';
9
9
  export function getFoldingRanges(document, context) {
10
- var ranges = computeFoldingRanges(document);
10
+ const ranges = computeFoldingRanges(document);
11
11
  return limitFoldingRanges(ranges, context);
12
12
  }
13
13
  function computeFoldingRanges(document) {
@@ -28,27 +28,27 @@ function computeFoldingRanges(document) {
28
28
  }
29
29
  }
30
30
  function tokenToRange(t, kind) {
31
- var startLine = getStartLine(t);
32
- var endLine = getEndLine(t);
31
+ const startLine = getStartLine(t);
32
+ const endLine = getEndLine(t);
33
33
  if (startLine !== endLine) {
34
34
  return {
35
- startLine: startLine,
36
- endLine: endLine,
37
- kind: kind
35
+ startLine,
36
+ endLine,
37
+ kind
38
38
  };
39
39
  }
40
40
  else {
41
41
  return null;
42
42
  }
43
43
  }
44
- var ranges = [];
45
- var delimiterStack = [];
46
- var scanner = getScanner();
44
+ const ranges = [];
45
+ const delimiterStack = [];
46
+ const scanner = getScanner();
47
47
  scanner.ignoreComment = false;
48
48
  scanner.setSource(document.getText());
49
- var token = scanner.scan();
50
- var prevToken = null;
51
- var _loop_1 = function () {
49
+ let token = scanner.scan();
50
+ let prevToken = null;
51
+ while (token.type !== TokenType.EOF) {
52
52
  switch (token.type) {
53
53
  case TokenType.CurlyL:
54
54
  case InterpolationFunction:
@@ -58,11 +58,11 @@ function computeFoldingRanges(document) {
58
58
  }
59
59
  case TokenType.CurlyR: {
60
60
  if (delimiterStack.length !== 0) {
61
- var prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'brace');
61
+ const prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'brace');
62
62
  if (!prevDelimiter) {
63
63
  break;
64
64
  }
65
- var endLine = getEndLine(token);
65
+ let endLine = getEndLine(token);
66
66
  if (prevDelimiter.type === 'brace') {
67
67
  /**
68
68
  * Other than the case when curly brace is not on a new line by itself, for example
@@ -76,7 +76,7 @@ function computeFoldingRanges(document) {
76
76
  if (prevDelimiter.line !== endLine) {
77
77
  ranges.push({
78
78
  startLine: prevDelimiter.line,
79
- endLine: endLine,
79
+ endLine,
80
80
  kind: undefined
81
81
  });
82
82
  }
@@ -89,7 +89,7 @@ function computeFoldingRanges(document) {
89
89
  * All comments are marked as `Comment`
90
90
  */
91
91
  case TokenType.Comment: {
92
- var commentRegionMarkerToDelimiter_1 = function (marker) {
92
+ const commentRegionMarkerToDelimiter = (marker) => {
93
93
  if (marker === '#region') {
94
94
  return { line: getStartLine(token), type: 'comment', isStart: true };
95
95
  }
@@ -97,20 +97,20 @@ function computeFoldingRanges(document) {
97
97
  return { line: getEndLine(token), type: 'comment', isStart: false };
98
98
  }
99
99
  };
100
- var getCurrDelimiter = function (token) {
101
- var matches = token.text.match(/^\s*\/\*\s*(#region|#endregion)\b\s*(.*?)\s*\*\//);
100
+ const getCurrDelimiter = (token) => {
101
+ const matches = token.text.match(/^\s*\/\*\s*(#region|#endregion)\b\s*(.*?)\s*\*\//);
102
102
  if (matches) {
103
- return commentRegionMarkerToDelimiter_1(matches[1]);
103
+ return commentRegionMarkerToDelimiter(matches[1]);
104
104
  }
105
105
  else if (document.languageId === 'scss' || document.languageId === 'less') {
106
- var matches_1 = token.text.match(/^\s*\/\/\s*(#region|#endregion)\b\s*(.*?)\s*/);
107
- if (matches_1) {
108
- return commentRegionMarkerToDelimiter_1(matches_1[1]);
106
+ const matches = token.text.match(/^\s*\/\/\s*(#region|#endregion)\b\s*(.*?)\s*/);
107
+ if (matches) {
108
+ return commentRegionMarkerToDelimiter(matches[1]);
109
109
  }
110
110
  }
111
111
  return null;
112
112
  };
113
- var currDelimiter = getCurrDelimiter(token);
113
+ const currDelimiter = getCurrDelimiter(token);
114
114
  // /* */ comment region folding
115
115
  // All #region and #endregion cases
116
116
  if (currDelimiter) {
@@ -118,7 +118,7 @@ function computeFoldingRanges(document) {
118
118
  delimiterStack.push(currDelimiter);
119
119
  }
120
120
  else {
121
- var prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'comment');
121
+ const prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'comment');
122
122
  if (!prevDelimiter) {
123
123
  break;
124
124
  }
@@ -135,7 +135,7 @@ function computeFoldingRanges(document) {
135
135
  }
136
136
  // Multiline comment case
137
137
  else {
138
- var range = tokenToRange(token, 'comment');
138
+ const range = tokenToRange(token, 'comment');
139
139
  if (range) {
140
140
  ranges.push(range);
141
141
  }
@@ -145,9 +145,6 @@ function computeFoldingRanges(document) {
145
145
  }
146
146
  prevToken = token;
147
147
  token = scanner.scan();
148
- };
149
- while (token.type !== TokenType.EOF) {
150
- _loop_1();
151
148
  }
152
149
  return ranges;
153
150
  }
@@ -155,7 +152,7 @@ function popPrevStartDelimiterOfType(stack, type) {
155
152
  if (stack.length === 0) {
156
153
  return null;
157
154
  }
158
- for (var i = stack.length - 1; i >= 0; i--) {
155
+ for (let i = stack.length - 1; i >= 0; i--) {
159
156
  if (stack[i].type === type && stack[i].isStart) {
160
157
  return stack.splice(i, 1)[0];
161
158
  }
@@ -168,17 +165,17 @@ function popPrevStartDelimiterOfType(stack, type) {
168
165
  * - If limit exceeds, only return `rangeLimit` amount of ranges
169
166
  */
170
167
  function limitFoldingRanges(ranges, context) {
171
- var maxRanges = context && context.rangeLimit || Number.MAX_VALUE;
172
- var sortedRanges = ranges.sort(function (r1, r2) {
173
- var diff = r1.startLine - r2.startLine;
168
+ const maxRanges = context && context.rangeLimit || Number.MAX_VALUE;
169
+ const sortedRanges = ranges.sort((r1, r2) => {
170
+ let diff = r1.startLine - r2.startLine;
174
171
  if (diff === 0) {
175
172
  diff = r1.endLine - r2.endLine;
176
173
  }
177
174
  return diff;
178
175
  });
179
- var validRanges = [];
180
- var prevEndLine = -1;
181
- sortedRanges.forEach(function (r) {
176
+ const validRanges = [];
177
+ let prevEndLine = -1;
178
+ sortedRanges.forEach(r => {
182
179
  if (!(r.startLine < prevEndLine && prevEndLine < r.endLine)) {
183
180
  validRanges.push(r);
184
181
  prevEndLine = r.endLine;
@@ -6,15 +6,15 @@ import { Range, Position } from '../cssLanguageTypes';
6
6
  import { css_beautify } from '../beautify/beautify-css';
7
7
  import { repeat } from '../utils/strings';
8
8
  export function format(document, range, options) {
9
- var value = document.getText();
10
- var includesEnd = true;
11
- var initialIndentLevel = 0;
12
- var inRule = false;
13
- var tabSize = options.tabSize || 4;
9
+ let value = document.getText();
10
+ let includesEnd = true;
11
+ let initialIndentLevel = 0;
12
+ let inRule = false;
13
+ const tabSize = options.tabSize || 4;
14
14
  if (range) {
15
- var startOffset = document.offsetAt(range.start);
15
+ let startOffset = document.offsetAt(range.start);
16
16
  // include all leading whitespace iff at the beginning of the line
17
- var extendedStart = startOffset;
17
+ let extendedStart = startOffset;
18
18
  while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) {
19
19
  extendedStart--;
20
20
  }
@@ -28,8 +28,8 @@ export function format(document, range, options) {
28
28
  }
29
29
  }
30
30
  // include all following whitespace until the end of the line
31
- var endOffset = document.offsetAt(range.end);
32
- var extendedEnd = endOffset;
31
+ let endOffset = document.offsetAt(range.end);
32
+ let extendedEnd = endOffset;
33
33
  while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) {
34
34
  extendedEnd++;
35
35
  }
@@ -42,17 +42,17 @@ export function format(document, range, options) {
42
42
  includesEnd = endOffset === value.length;
43
43
  value = value.substring(startOffset, endOffset);
44
44
  if (startOffset !== 0) {
45
- var startOfLineOffset = document.offsetAt(Position.create(range.start.line, 0));
45
+ const startOfLineOffset = document.offsetAt(Position.create(range.start.line, 0));
46
46
  initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
47
47
  }
48
48
  if (inRule) {
49
- value = "{\n".concat(trimLeft(value));
49
+ value = `{\n${trimLeft(value)}`;
50
50
  }
51
51
  }
52
52
  else {
53
53
  range = Range.create(Position.create(0, 0), document.positionAt(value.length));
54
54
  }
55
- var cssOptions = {
55
+ const cssOptions = {
56
56
  indent_size: tabSize,
57
57
  indent_char: options.insertSpaces ? ' ' : '\t',
58
58
  end_with_newline: includesEnd && getFormatOption(options, 'insertFinalNewline', false),
@@ -66,12 +66,12 @@ export function format(document, range, options) {
66
66
  wrap_line_length: getFormatOption(options, 'wrapLineLength', undefined),
67
67
  eol: '\n'
68
68
  };
69
- var result = css_beautify(value, cssOptions);
69
+ let result = css_beautify(value, cssOptions);
70
70
  if (inRule) {
71
71
  result = trimLeft(result.substring(2));
72
72
  }
73
73
  if (initialIndentLevel > 0) {
74
- var indent = options.insertSpaces ? repeat(' ', tabSize * initialIndentLevel) : repeat('\t', initialIndentLevel);
74
+ const indent = options.insertSpaces ? repeat(' ', tabSize * initialIndentLevel) : repeat('\t', initialIndentLevel);
75
75
  result = result.split('\n').join('\n' + indent);
76
76
  if (range.start.character === 0) {
77
77
  result = indent + result; // keep the indent
@@ -85,11 +85,11 @@ export function format(document, range, options) {
85
85
  function trimLeft(str) {
86
86
  return str.replace(/^\s+/, '');
87
87
  }
88
- var _CUL = '{'.charCodeAt(0);
89
- var _CUR = '}'.charCodeAt(0);
88
+ const _CUL = '{'.charCodeAt(0);
89
+ const _CUR = '}'.charCodeAt(0);
90
90
  function isInRule(str, offset) {
91
91
  while (offset >= 0) {
92
- var ch = str.charCodeAt(offset);
92
+ const ch = str.charCodeAt(offset);
93
93
  if (ch === _CUL) {
94
94
  return true;
95
95
  }
@@ -102,7 +102,7 @@ function isInRule(str, offset) {
102
102
  }
103
103
  function getFormatOption(options, key, dflt) {
104
104
  if (options && options.hasOwnProperty(key)) {
105
- var value = options[key];
105
+ const value = options[key];
106
106
  if (value !== null) {
107
107
  return value;
108
108
  }
@@ -110,11 +110,11 @@ function getFormatOption(options, key, dflt) {
110
110
  return dflt;
111
111
  }
112
112
  function computeIndentLevel(content, offset, options) {
113
- var i = offset;
114
- var nChars = 0;
115
- var tabSize = options.tabSize || 4;
113
+ let i = offset;
114
+ let nChars = 0;
115
+ const tabSize = options.tabSize || 4;
116
116
  while (i < content.length) {
117
- var ch = content.charAt(i);
117
+ const ch = content.charAt(i);
118
118
  if (ch === ' ') {
119
119
  nChars++;
120
120
  }
@@ -9,29 +9,28 @@ import { SelectorPrinting } from './selectorPrinting';
9
9
  import { startsWith } from '../utils/strings';
10
10
  import { Range, MarkupKind } from '../cssLanguageTypes';
11
11
  import { isDefined } from '../utils/objects';
12
- var CSSHover = /** @class */ (function () {
13
- function CSSHover(clientCapabilities, cssDataManager) {
12
+ export class CSSHover {
13
+ constructor(clientCapabilities, cssDataManager) {
14
14
  this.clientCapabilities = clientCapabilities;
15
15
  this.cssDataManager = cssDataManager;
16
16
  this.selectorPrinting = new SelectorPrinting(cssDataManager);
17
17
  }
18
- CSSHover.prototype.configure = function (settings) {
18
+ configure(settings) {
19
19
  this.defaultSettings = settings;
20
- };
21
- CSSHover.prototype.doHover = function (document, position, stylesheet, settings) {
22
- if (settings === void 0) { settings = this.defaultSettings; }
20
+ }
21
+ doHover(document, position, stylesheet, settings = this.defaultSettings) {
23
22
  function getRange(node) {
24
23
  return Range.create(document.positionAt(node.offset), document.positionAt(node.end));
25
24
  }
26
- var offset = document.offsetAt(position);
27
- var nodepath = nodes.getNodePath(stylesheet, offset);
25
+ const offset = document.offsetAt(position);
26
+ const nodepath = nodes.getNodePath(stylesheet, offset);
28
27
  /**
29
28
  * nodepath is top-down
30
29
  * Build up the hover by appending inner node's information
31
30
  */
32
- var hover = null;
33
- for (var i = 0; i < nodepath.length; i++) {
34
- var node = nodepath[i];
31
+ let hover = null;
32
+ for (let i = 0; i < nodepath.length; i++) {
33
+ const node = nodepath[i];
35
34
  if (node instanceof nodes.Selector) {
36
35
  hover = {
37
36
  contents: this.selectorPrinting.selectorToMarkedString(node),
@@ -52,13 +51,13 @@ var CSSHover = /** @class */ (function () {
52
51
  break;
53
52
  }
54
53
  if (node instanceof nodes.Declaration) {
55
- var propertyName = node.getFullPropertyName();
56
- var entry = this.cssDataManager.getProperty(propertyName);
54
+ const propertyName = node.getFullPropertyName();
55
+ const entry = this.cssDataManager.getProperty(propertyName);
57
56
  if (entry) {
58
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
57
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
59
58
  if (contents) {
60
59
  hover = {
61
- contents: contents,
60
+ contents,
62
61
  range: getRange(node)
63
62
  };
64
63
  }
@@ -69,13 +68,13 @@ var CSSHover = /** @class */ (function () {
69
68
  continue;
70
69
  }
71
70
  if (node instanceof nodes.UnknownAtRule) {
72
- var atRuleName = node.getText();
73
- var entry = this.cssDataManager.getAtDirective(atRuleName);
71
+ const atRuleName = node.getText();
72
+ const entry = this.cssDataManager.getAtDirective(atRuleName);
74
73
  if (entry) {
75
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
74
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
76
75
  if (contents) {
77
76
  hover = {
78
- contents: contents,
77
+ contents,
79
78
  range: getRange(node)
80
79
  };
81
80
  }
@@ -86,15 +85,15 @@ var CSSHover = /** @class */ (function () {
86
85
  continue;
87
86
  }
88
87
  if (node instanceof nodes.Node && node.type === nodes.NodeType.PseudoSelector) {
89
- var selectorName = node.getText();
90
- var entry = selectorName.slice(0, 2) === '::'
88
+ const selectorName = node.getText();
89
+ const entry = selectorName.slice(0, 2) === '::'
91
90
  ? this.cssDataManager.getPseudoElement(selectorName)
92
91
  : this.cssDataManager.getPseudoClass(selectorName);
93
92
  if (entry) {
94
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
93
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
95
94
  if (contents) {
96
95
  hover = {
97
- contents: contents,
96
+ contents,
98
97
  range: getRange(node)
99
98
  };
100
99
  }
@@ -109,8 +108,8 @@ var CSSHover = /** @class */ (function () {
109
108
  hover.contents = this.convertContents(hover.contents);
110
109
  }
111
110
  return hover;
112
- };
113
- CSSHover.prototype.convertContents = function (contents) {
111
+ }
112
+ convertContents(contents) {
114
113
  if (!this.doesSupportMarkdown()) {
115
114
  if (typeof contents === 'string') {
116
115
  return contents;
@@ -124,7 +123,7 @@ var CSSHover = /** @class */ (function () {
124
123
  }
125
124
  // MarkedString[]
126
125
  else if (Array.isArray(contents)) {
127
- return contents.map(function (c) {
126
+ return contents.map(c => {
128
127
  return typeof c === 'string' ? c : c.value;
129
128
  });
130
129
  }
@@ -134,18 +133,16 @@ var CSSHover = /** @class */ (function () {
134
133
  }
135
134
  }
136
135
  return contents;
137
- };
138
- CSSHover.prototype.doesSupportMarkdown = function () {
136
+ }
137
+ doesSupportMarkdown() {
139
138
  if (!isDefined(this.supportsMarkdown)) {
140
139
  if (!isDefined(this.clientCapabilities)) {
141
140
  this.supportsMarkdown = true;
142
141
  return this.supportsMarkdown;
143
142
  }
144
- var hover = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.hover;
143
+ const hover = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.hover;
145
144
  this.supportsMarkdown = hover && hover.contentFormat && Array.isArray(hover.contentFormat) && hover.contentFormat.indexOf(MarkupKind.Markdown) !== -1;
146
145
  }
147
146
  return this.supportsMarkdown;
148
- };
149
- return CSSHover;
150
- }());
151
- export { CSSHover };
147
+ }
148
+ }