vscode-css-languageservice 5.4.2 → 6.0.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 (84) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/lib/esm/cssLanguageService.d.ts +37 -37
  3. package/lib/esm/cssLanguageService.js +72 -75
  4. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  5. package/lib/esm/cssLanguageTypes.js +42 -42
  6. package/lib/esm/data/webCustomData.js +21965 -21965
  7. package/lib/esm/languageFacts/builtinData.js +142 -142
  8. package/lib/esm/languageFacts/colors.js +469 -472
  9. package/lib/esm/languageFacts/dataManager.js +88 -92
  10. package/lib/esm/languageFacts/dataProvider.js +73 -79
  11. package/lib/esm/languageFacts/entry.js +137 -138
  12. package/lib/esm/languageFacts/facts.js +8 -8
  13. package/lib/esm/parser/cssErrors.js +48 -50
  14. package/lib/esm/parser/cssNodes.js +1502 -2019
  15. package/lib/esm/parser/cssParser.js +1534 -1563
  16. package/lib/esm/parser/cssScanner.js +592 -599
  17. package/lib/esm/parser/cssSymbolScope.js +311 -341
  18. package/lib/esm/parser/lessParser.js +714 -740
  19. package/lib/esm/parser/lessScanner.js +57 -78
  20. package/lib/esm/parser/scssErrors.js +18 -20
  21. package/lib/esm/parser/scssParser.js +796 -818
  22. package/lib/esm/parser/scssScanner.js +95 -116
  23. package/lib/esm/services/cssCodeActions.js +77 -81
  24. package/lib/esm/services/cssCompletion.js +1054 -1149
  25. package/lib/esm/services/cssFolding.js +190 -193
  26. package/lib/esm/services/cssFormatter.js +136 -136
  27. package/lib/esm/services/cssHover.js +148 -151
  28. package/lib/esm/services/cssNavigation.js +378 -470
  29. package/lib/esm/services/cssSelectionRange.js +47 -47
  30. package/lib/esm/services/cssValidation.js +41 -44
  31. package/lib/esm/services/lessCompletion.js +378 -397
  32. package/lib/esm/services/lint.js +518 -532
  33. package/lib/esm/services/lintRules.js +76 -83
  34. package/lib/esm/services/lintUtil.js +196 -205
  35. package/lib/esm/services/pathCompletion.js +157 -231
  36. package/lib/esm/services/scssCompletion.js +354 -378
  37. package/lib/esm/services/scssNavigation.js +82 -154
  38. package/lib/esm/services/selectorPrinting.js +492 -536
  39. package/lib/esm/utils/arrays.js +40 -46
  40. package/lib/esm/utils/objects.js +11 -11
  41. package/lib/esm/utils/resources.js +11 -24
  42. package/lib/esm/utils/strings.js +102 -104
  43. package/lib/umd/cssLanguageService.d.ts +37 -37
  44. package/lib/umd/cssLanguageService.js +99 -102
  45. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  46. package/lib/umd/cssLanguageTypes.js +89 -88
  47. package/lib/umd/data/webCustomData.js +21978 -21978
  48. package/lib/umd/languageFacts/builtinData.js +154 -154
  49. package/lib/umd/languageFacts/colors.js +492 -495
  50. package/lib/umd/languageFacts/dataManager.js +101 -104
  51. package/lib/umd/languageFacts/dataProvider.js +86 -91
  52. package/lib/umd/languageFacts/entry.js +152 -153
  53. package/lib/umd/languageFacts/facts.js +29 -29
  54. package/lib/umd/parser/cssErrors.js +61 -62
  55. package/lib/umd/parser/cssNodes.js +1587 -2034
  56. package/lib/umd/parser/cssParser.js +1547 -1575
  57. package/lib/umd/parser/cssScanner.js +606 -611
  58. package/lib/umd/parser/cssSymbolScope.js +328 -353
  59. package/lib/umd/parser/lessParser.js +727 -752
  60. package/lib/umd/parser/lessScanner.js +70 -90
  61. package/lib/umd/parser/scssErrors.js +31 -32
  62. package/lib/umd/parser/scssParser.js +809 -830
  63. package/lib/umd/parser/scssScanner.js +108 -128
  64. package/lib/umd/services/cssCodeActions.js +90 -93
  65. package/lib/umd/services/cssCompletion.js +1067 -1161
  66. package/lib/umd/services/cssFolding.js +203 -206
  67. package/lib/umd/services/cssFormatter.js +150 -150
  68. package/lib/umd/services/cssHover.js +161 -163
  69. package/lib/umd/services/cssNavigation.js +391 -482
  70. package/lib/umd/services/cssSelectionRange.js +60 -60
  71. package/lib/umd/services/cssValidation.js +54 -56
  72. package/lib/umd/services/lessCompletion.js +391 -409
  73. package/lib/umd/services/lint.js +531 -544
  74. package/lib/umd/services/lintRules.js +91 -95
  75. package/lib/umd/services/lintUtil.js +210 -218
  76. package/lib/umd/services/pathCompletion.js +171 -244
  77. package/lib/umd/services/scssCompletion.js +367 -390
  78. package/lib/umd/services/scssNavigation.js +95 -166
  79. package/lib/umd/services/selectorPrinting.js +510 -550
  80. package/lib/umd/utils/arrays.js +55 -61
  81. package/lib/umd/utils/objects.js +25 -25
  82. package/lib/umd/utils/resources.js +26 -39
  83. package/lib/umd/utils/strings.js +120 -122
  84. package/package.json +10 -10
@@ -1,150 +1,150 @@
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 inRule = false;
25
- var tabSize = options.tabSize || 4;
26
- if (range) {
27
- var startOffset = document.offsetAt(range.start);
28
- // include all leading whitespace iff at the beginning of the line
29
- var extendedStart = startOffset;
30
- while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) {
31
- extendedStart--;
32
- }
33
- if (extendedStart === 0 || isEOL(value, extendedStart - 1)) {
34
- startOffset = extendedStart;
35
- }
36
- else {
37
- // else keep at least one whitespace
38
- if (extendedStart < startOffset) {
39
- startOffset = extendedStart + 1;
40
- }
41
- }
42
- // include all following whitespace until the end of the line
43
- var endOffset = document.offsetAt(range.end);
44
- var extendedEnd = endOffset;
45
- while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) {
46
- extendedEnd++;
47
- }
48
- if (extendedEnd === value.length || isEOL(value, extendedEnd)) {
49
- endOffset = extendedEnd;
50
- }
51
- range = cssLanguageTypes_1.Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
52
- // Test if inside a rule
53
- inRule = isInRule(value, startOffset);
54
- includesEnd = endOffset === value.length;
55
- value = value.substring(startOffset, endOffset);
56
- if (startOffset !== 0) {
57
- var startOfLineOffset = document.offsetAt(cssLanguageTypes_1.Position.create(range.start.line, 0));
58
- initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
59
- }
60
- if (inRule) {
61
- value = "{\n".concat(trimLeft(value));
62
- }
63
- }
64
- else {
65
- range = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(0, 0), document.positionAt(value.length));
66
- }
67
- var cssOptions = {
68
- indent_size: tabSize,
69
- indent_char: options.insertSpaces ? ' ' : '\t',
70
- end_with_newline: includesEnd && getFormatOption(options, 'insertFinalNewline', false),
71
- selector_separator_newline: getFormatOption(options, 'newlineBetweenSelectors', true),
72
- newline_between_rules: getFormatOption(options, 'newlineBetweenRules', true),
73
- space_around_selector_separator: getFormatOption(options, 'spaceAroundSelectorSeparator', false),
74
- brace_style: getFormatOption(options, 'braceStyle', 'collapse'),
75
- indent_empty_lines: getFormatOption(options, 'indentEmptyLines', false),
76
- max_preserve_newlines: getFormatOption(options, 'maxPreserveNewLines', undefined),
77
- preserve_newlines: getFormatOption(options, 'preserveNewLines', true),
78
- wrap_line_length: getFormatOption(options, 'wrapLineLength', undefined),
79
- eol: '\n'
80
- };
81
- var result = (0, beautify_css_1.css_beautify)(value, cssOptions);
82
- if (inRule) {
83
- result = trimLeft(result.substring(2));
84
- }
85
- if (initialIndentLevel > 0) {
86
- var indent = options.insertSpaces ? (0, strings_1.repeat)(' ', tabSize * initialIndentLevel) : (0, strings_1.repeat)('\t', initialIndentLevel);
87
- result = result.split('\n').join('\n' + indent);
88
- if (range.start.character === 0) {
89
- result = indent + result; // keep the indent
90
- }
91
- }
92
- return [{
93
- range: range,
94
- newText: result
95
- }];
96
- }
97
- exports.format = format;
98
- function trimLeft(str) {
99
- return str.replace(/^\s+/, '');
100
- }
101
- var _CUL = '{'.charCodeAt(0);
102
- var _CUR = '}'.charCodeAt(0);
103
- function isInRule(str, offset) {
104
- while (offset >= 0) {
105
- var ch = str.charCodeAt(offset);
106
- if (ch === _CUL) {
107
- return true;
108
- }
109
- else if (ch === _CUR) {
110
- return false;
111
- }
112
- offset--;
113
- }
114
- return false;
115
- }
116
- function getFormatOption(options, key, dflt) {
117
- if (options && options.hasOwnProperty(key)) {
118
- var value = options[key];
119
- if (value !== null) {
120
- return value;
121
- }
122
- }
123
- return dflt;
124
- }
125
- function computeIndentLevel(content, offset, options) {
126
- var i = offset;
127
- var nChars = 0;
128
- var tabSize = options.tabSize || 4;
129
- while (i < content.length) {
130
- var ch = content.charAt(i);
131
- if (ch === ' ') {
132
- nChars++;
133
- }
134
- else if (ch === '\t') {
135
- nChars += tabSize;
136
- }
137
- else {
138
- break;
139
- }
140
- i++;
141
- }
142
- return Math.floor(nChars / tabSize);
143
- }
144
- function isEOL(text, offset) {
145
- return '\r\n'.indexOf(text.charAt(offset)) !== -1;
146
- }
147
- function isWhitespace(text, offset) {
148
- return ' \t'.indexOf(text.charAt(offset)) !== -1;
149
- }
150
- });
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
+ const cssLanguageTypes_1 = require("../cssLanguageTypes");
18
+ const beautify_css_1 = require("../beautify/beautify-css");
19
+ const strings_1 = require("../utils/strings");
20
+ function format(document, range, options) {
21
+ let value = document.getText();
22
+ let includesEnd = true;
23
+ let initialIndentLevel = 0;
24
+ let inRule = false;
25
+ const tabSize = options.tabSize || 4;
26
+ if (range) {
27
+ let startOffset = document.offsetAt(range.start);
28
+ // include all leading whitespace iff at the beginning of the line
29
+ let extendedStart = startOffset;
30
+ while (extendedStart > 0 && isWhitespace(value, extendedStart - 1)) {
31
+ extendedStart--;
32
+ }
33
+ if (extendedStart === 0 || isEOL(value, extendedStart - 1)) {
34
+ startOffset = extendedStart;
35
+ }
36
+ else {
37
+ // else keep at least one whitespace
38
+ if (extendedStart < startOffset) {
39
+ startOffset = extendedStart + 1;
40
+ }
41
+ }
42
+ // include all following whitespace until the end of the line
43
+ let endOffset = document.offsetAt(range.end);
44
+ let extendedEnd = endOffset;
45
+ while (extendedEnd < value.length && isWhitespace(value, extendedEnd)) {
46
+ extendedEnd++;
47
+ }
48
+ if (extendedEnd === value.length || isEOL(value, extendedEnd)) {
49
+ endOffset = extendedEnd;
50
+ }
51
+ range = cssLanguageTypes_1.Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
52
+ // Test if inside a rule
53
+ inRule = isInRule(value, startOffset);
54
+ includesEnd = endOffset === value.length;
55
+ value = value.substring(startOffset, endOffset);
56
+ if (startOffset !== 0) {
57
+ const startOfLineOffset = document.offsetAt(cssLanguageTypes_1.Position.create(range.start.line, 0));
58
+ initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
59
+ }
60
+ if (inRule) {
61
+ value = `{\n${trimLeft(value)}`;
62
+ }
63
+ }
64
+ else {
65
+ range = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(0, 0), document.positionAt(value.length));
66
+ }
67
+ const cssOptions = {
68
+ indent_size: tabSize,
69
+ indent_char: options.insertSpaces ? ' ' : '\t',
70
+ end_with_newline: includesEnd && getFormatOption(options, 'insertFinalNewline', false),
71
+ selector_separator_newline: getFormatOption(options, 'newlineBetweenSelectors', true),
72
+ newline_between_rules: getFormatOption(options, 'newlineBetweenRules', true),
73
+ space_around_selector_separator: getFormatOption(options, 'spaceAroundSelectorSeparator', false),
74
+ brace_style: getFormatOption(options, 'braceStyle', 'collapse'),
75
+ indent_empty_lines: getFormatOption(options, 'indentEmptyLines', false),
76
+ max_preserve_newlines: getFormatOption(options, 'maxPreserveNewLines', undefined),
77
+ preserve_newlines: getFormatOption(options, 'preserveNewLines', true),
78
+ wrap_line_length: getFormatOption(options, 'wrapLineLength', undefined),
79
+ eol: '\n'
80
+ };
81
+ let result = (0, beautify_css_1.css_beautify)(value, cssOptions);
82
+ if (inRule) {
83
+ result = trimLeft(result.substring(2));
84
+ }
85
+ if (initialIndentLevel > 0) {
86
+ const indent = options.insertSpaces ? (0, strings_1.repeat)(' ', tabSize * initialIndentLevel) : (0, strings_1.repeat)('\t', initialIndentLevel);
87
+ result = result.split('\n').join('\n' + indent);
88
+ if (range.start.character === 0) {
89
+ result = indent + result; // keep the indent
90
+ }
91
+ }
92
+ return [{
93
+ range: range,
94
+ newText: result
95
+ }];
96
+ }
97
+ exports.format = format;
98
+ function trimLeft(str) {
99
+ return str.replace(/^\s+/, '');
100
+ }
101
+ const _CUL = '{'.charCodeAt(0);
102
+ const _CUR = '}'.charCodeAt(0);
103
+ function isInRule(str, offset) {
104
+ while (offset >= 0) {
105
+ const ch = str.charCodeAt(offset);
106
+ if (ch === _CUL) {
107
+ return true;
108
+ }
109
+ else if (ch === _CUR) {
110
+ return false;
111
+ }
112
+ offset--;
113
+ }
114
+ return false;
115
+ }
116
+ function getFormatOption(options, key, dflt) {
117
+ if (options && options.hasOwnProperty(key)) {
118
+ const value = options[key];
119
+ if (value !== null) {
120
+ return value;
121
+ }
122
+ }
123
+ return dflt;
124
+ }
125
+ function computeIndentLevel(content, offset, options) {
126
+ let i = offset;
127
+ let nChars = 0;
128
+ const tabSize = options.tabSize || 4;
129
+ while (i < content.length) {
130
+ const ch = content.charAt(i);
131
+ if (ch === ' ') {
132
+ nChars++;
133
+ }
134
+ else if (ch === '\t') {
135
+ nChars += tabSize;
136
+ }
137
+ else {
138
+ break;
139
+ }
140
+ i++;
141
+ }
142
+ return Math.floor(nChars / tabSize);
143
+ }
144
+ function isEOL(text, offset) {
145
+ return '\r\n'.indexOf(text.charAt(offset)) !== -1;
146
+ }
147
+ function isWhitespace(text, offset) {
148
+ return ' \t'.indexOf(text.charAt(offset)) !== -1;
149
+ }
150
+ });
@@ -1,163 +1,161 @@
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", "../languageFacts/facts", "./selectorPrinting", "../utils/strings", "../cssLanguageTypes", "../utils/objects"], 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.CSSHover = void 0;
17
- var nodes = require("../parser/cssNodes");
18
- var languageFacts = require("../languageFacts/facts");
19
- var selectorPrinting_1 = require("./selectorPrinting");
20
- var strings_1 = require("../utils/strings");
21
- var cssLanguageTypes_1 = require("../cssLanguageTypes");
22
- var objects_1 = require("../utils/objects");
23
- var CSSHover = /** @class */ (function () {
24
- function CSSHover(clientCapabilities, cssDataManager) {
25
- this.clientCapabilities = clientCapabilities;
26
- this.cssDataManager = cssDataManager;
27
- this.selectorPrinting = new selectorPrinting_1.SelectorPrinting(cssDataManager);
28
- }
29
- CSSHover.prototype.configure = function (settings) {
30
- this.defaultSettings = settings;
31
- };
32
- CSSHover.prototype.doHover = function (document, position, stylesheet, settings) {
33
- if (settings === void 0) { settings = this.defaultSettings; }
34
- function getRange(node) {
35
- return cssLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.end));
36
- }
37
- var offset = document.offsetAt(position);
38
- var nodepath = nodes.getNodePath(stylesheet, offset);
39
- /**
40
- * nodepath is top-down
41
- * Build up the hover by appending inner node's information
42
- */
43
- var hover = null;
44
- for (var i = 0; i < nodepath.length; i++) {
45
- var node = nodepath[i];
46
- if (node instanceof nodes.Selector) {
47
- hover = {
48
- contents: this.selectorPrinting.selectorToMarkedString(node),
49
- range: getRange(node)
50
- };
51
- break;
52
- }
53
- if (node instanceof nodes.SimpleSelector) {
54
- /**
55
- * Some sass specific at rules such as `@at-root` are parsed as `SimpleSelector`
56
- */
57
- if (!(0, strings_1.startsWith)(node.getText(), '@')) {
58
- hover = {
59
- contents: this.selectorPrinting.simpleSelectorToMarkedString(node),
60
- range: getRange(node)
61
- };
62
- }
63
- break;
64
- }
65
- if (node instanceof nodes.Declaration) {
66
- var propertyName = node.getFullPropertyName();
67
- var entry = this.cssDataManager.getProperty(propertyName);
68
- if (entry) {
69
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
70
- if (contents) {
71
- hover = {
72
- contents: contents,
73
- range: getRange(node)
74
- };
75
- }
76
- else {
77
- hover = null;
78
- }
79
- }
80
- continue;
81
- }
82
- if (node instanceof nodes.UnknownAtRule) {
83
- var atRuleName = node.getText();
84
- var entry = this.cssDataManager.getAtDirective(atRuleName);
85
- if (entry) {
86
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
87
- if (contents) {
88
- hover = {
89
- contents: contents,
90
- range: getRange(node)
91
- };
92
- }
93
- else {
94
- hover = null;
95
- }
96
- }
97
- continue;
98
- }
99
- if (node instanceof nodes.Node && node.type === nodes.NodeType.PseudoSelector) {
100
- var selectorName = node.getText();
101
- var entry = selectorName.slice(0, 2) === '::'
102
- ? this.cssDataManager.getPseudoElement(selectorName)
103
- : this.cssDataManager.getPseudoClass(selectorName);
104
- if (entry) {
105
- var contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
106
- if (contents) {
107
- hover = {
108
- contents: contents,
109
- range: getRange(node)
110
- };
111
- }
112
- else {
113
- hover = null;
114
- }
115
- }
116
- continue;
117
- }
118
- }
119
- if (hover) {
120
- hover.contents = this.convertContents(hover.contents);
121
- }
122
- return hover;
123
- };
124
- CSSHover.prototype.convertContents = function (contents) {
125
- if (!this.doesSupportMarkdown()) {
126
- if (typeof contents === 'string') {
127
- return contents;
128
- }
129
- // MarkupContent
130
- else if ('kind' in contents) {
131
- return {
132
- kind: 'plaintext',
133
- value: contents.value
134
- };
135
- }
136
- // MarkedString[]
137
- else if (Array.isArray(contents)) {
138
- return contents.map(function (c) {
139
- return typeof c === 'string' ? c : c.value;
140
- });
141
- }
142
- // MarkedString
143
- else {
144
- return contents.value;
145
- }
146
- }
147
- return contents;
148
- };
149
- CSSHover.prototype.doesSupportMarkdown = function () {
150
- if (!(0, objects_1.isDefined)(this.supportsMarkdown)) {
151
- if (!(0, objects_1.isDefined)(this.clientCapabilities)) {
152
- this.supportsMarkdown = true;
153
- return this.supportsMarkdown;
154
- }
155
- var hover = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.hover;
156
- this.supportsMarkdown = hover && hover.contentFormat && Array.isArray(hover.contentFormat) && hover.contentFormat.indexOf(cssLanguageTypes_1.MarkupKind.Markdown) !== -1;
157
- }
158
- return this.supportsMarkdown;
159
- };
160
- return CSSHover;
161
- }());
162
- exports.CSSHover = CSSHover;
163
- });
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", "../languageFacts/facts", "./selectorPrinting", "../utils/strings", "../cssLanguageTypes", "../utils/objects"], 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.CSSHover = void 0;
17
+ const nodes = require("../parser/cssNodes");
18
+ const languageFacts = require("../languageFacts/facts");
19
+ const selectorPrinting_1 = require("./selectorPrinting");
20
+ const strings_1 = require("../utils/strings");
21
+ const cssLanguageTypes_1 = require("../cssLanguageTypes");
22
+ const objects_1 = require("../utils/objects");
23
+ class CSSHover {
24
+ constructor(clientCapabilities, cssDataManager) {
25
+ this.clientCapabilities = clientCapabilities;
26
+ this.cssDataManager = cssDataManager;
27
+ this.selectorPrinting = new selectorPrinting_1.SelectorPrinting(cssDataManager);
28
+ }
29
+ configure(settings) {
30
+ this.defaultSettings = settings;
31
+ }
32
+ doHover(document, position, stylesheet, settings = this.defaultSettings) {
33
+ function getRange(node) {
34
+ return cssLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.end));
35
+ }
36
+ const offset = document.offsetAt(position);
37
+ const nodepath = nodes.getNodePath(stylesheet, offset);
38
+ /**
39
+ * nodepath is top-down
40
+ * Build up the hover by appending inner node's information
41
+ */
42
+ let hover = null;
43
+ for (let i = 0; i < nodepath.length; i++) {
44
+ const node = nodepath[i];
45
+ if (node instanceof nodes.Selector) {
46
+ hover = {
47
+ contents: this.selectorPrinting.selectorToMarkedString(node),
48
+ range: getRange(node)
49
+ };
50
+ break;
51
+ }
52
+ if (node instanceof nodes.SimpleSelector) {
53
+ /**
54
+ * Some sass specific at rules such as `@at-root` are parsed as `SimpleSelector`
55
+ */
56
+ if (!(0, strings_1.startsWith)(node.getText(), '@')) {
57
+ hover = {
58
+ contents: this.selectorPrinting.simpleSelectorToMarkedString(node),
59
+ range: getRange(node)
60
+ };
61
+ }
62
+ break;
63
+ }
64
+ if (node instanceof nodes.Declaration) {
65
+ const propertyName = node.getFullPropertyName();
66
+ const entry = this.cssDataManager.getProperty(propertyName);
67
+ if (entry) {
68
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
69
+ if (contents) {
70
+ hover = {
71
+ contents,
72
+ range: getRange(node)
73
+ };
74
+ }
75
+ else {
76
+ hover = null;
77
+ }
78
+ }
79
+ continue;
80
+ }
81
+ if (node instanceof nodes.UnknownAtRule) {
82
+ const atRuleName = node.getText();
83
+ const entry = this.cssDataManager.getAtDirective(atRuleName);
84
+ if (entry) {
85
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
86
+ if (contents) {
87
+ hover = {
88
+ contents,
89
+ range: getRange(node)
90
+ };
91
+ }
92
+ else {
93
+ hover = null;
94
+ }
95
+ }
96
+ continue;
97
+ }
98
+ if (node instanceof nodes.Node && node.type === nodes.NodeType.PseudoSelector) {
99
+ const selectorName = node.getText();
100
+ const entry = selectorName.slice(0, 2) === '::'
101
+ ? this.cssDataManager.getPseudoElement(selectorName)
102
+ : this.cssDataManager.getPseudoClass(selectorName);
103
+ if (entry) {
104
+ const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
105
+ if (contents) {
106
+ hover = {
107
+ contents,
108
+ range: getRange(node)
109
+ };
110
+ }
111
+ else {
112
+ hover = null;
113
+ }
114
+ }
115
+ continue;
116
+ }
117
+ }
118
+ if (hover) {
119
+ hover.contents = this.convertContents(hover.contents);
120
+ }
121
+ return hover;
122
+ }
123
+ convertContents(contents) {
124
+ if (!this.doesSupportMarkdown()) {
125
+ if (typeof contents === 'string') {
126
+ return contents;
127
+ }
128
+ // MarkupContent
129
+ else if ('kind' in contents) {
130
+ return {
131
+ kind: 'plaintext',
132
+ value: contents.value
133
+ };
134
+ }
135
+ // MarkedString[]
136
+ else if (Array.isArray(contents)) {
137
+ return contents.map(c => {
138
+ return typeof c === 'string' ? c : c.value;
139
+ });
140
+ }
141
+ // MarkedString
142
+ else {
143
+ return contents.value;
144
+ }
145
+ }
146
+ return contents;
147
+ }
148
+ doesSupportMarkdown() {
149
+ if (!(0, objects_1.isDefined)(this.supportsMarkdown)) {
150
+ if (!(0, objects_1.isDefined)(this.clientCapabilities)) {
151
+ this.supportsMarkdown = true;
152
+ return this.supportsMarkdown;
153
+ }
154
+ const hover = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.hover;
155
+ this.supportsMarkdown = hover && hover.contentFormat && Array.isArray(hover.contentFormat) && hover.contentFormat.indexOf(cssLanguageTypes_1.MarkupKind.Markdown) !== -1;
156
+ }
157
+ return this.supportsMarkdown;
158
+ }
159
+ }
160
+ exports.CSSHover = CSSHover;
161
+ });