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.
- package/CHANGELOG.md +5 -1
- package/lib/esm/cssLanguageService.d.ts +37 -37
- package/lib/esm/cssLanguageService.js +72 -75
- package/lib/esm/cssLanguageTypes.d.ts +238 -238
- package/lib/esm/cssLanguageTypes.js +42 -42
- package/lib/esm/data/webCustomData.js +21965 -21965
- package/lib/esm/languageFacts/builtinData.js +142 -142
- package/lib/esm/languageFacts/colors.js +469 -472
- package/lib/esm/languageFacts/dataManager.js +88 -92
- package/lib/esm/languageFacts/dataProvider.js +73 -79
- package/lib/esm/languageFacts/entry.js +137 -138
- package/lib/esm/languageFacts/facts.js +8 -8
- package/lib/esm/parser/cssErrors.js +48 -50
- package/lib/esm/parser/cssNodes.js +1502 -2019
- package/lib/esm/parser/cssParser.js +1534 -1563
- package/lib/esm/parser/cssScanner.js +592 -599
- package/lib/esm/parser/cssSymbolScope.js +311 -341
- package/lib/esm/parser/lessParser.js +714 -740
- package/lib/esm/parser/lessScanner.js +57 -78
- package/lib/esm/parser/scssErrors.js +18 -20
- package/lib/esm/parser/scssParser.js +796 -818
- package/lib/esm/parser/scssScanner.js +95 -116
- package/lib/esm/services/cssCodeActions.js +77 -81
- package/lib/esm/services/cssCompletion.js +1054 -1149
- package/lib/esm/services/cssFolding.js +190 -193
- package/lib/esm/services/cssFormatter.js +136 -136
- package/lib/esm/services/cssHover.js +148 -151
- package/lib/esm/services/cssNavigation.js +378 -470
- package/lib/esm/services/cssSelectionRange.js +47 -47
- package/lib/esm/services/cssValidation.js +41 -44
- package/lib/esm/services/lessCompletion.js +378 -397
- package/lib/esm/services/lint.js +518 -532
- package/lib/esm/services/lintRules.js +76 -83
- package/lib/esm/services/lintUtil.js +196 -205
- package/lib/esm/services/pathCompletion.js +157 -231
- package/lib/esm/services/scssCompletion.js +354 -378
- package/lib/esm/services/scssNavigation.js +82 -154
- package/lib/esm/services/selectorPrinting.js +492 -536
- package/lib/esm/utils/arrays.js +40 -46
- package/lib/esm/utils/objects.js +11 -11
- package/lib/esm/utils/resources.js +11 -24
- package/lib/esm/utils/strings.js +102 -104
- package/lib/umd/cssLanguageService.d.ts +37 -37
- package/lib/umd/cssLanguageService.js +99 -102
- package/lib/umd/cssLanguageTypes.d.ts +238 -238
- package/lib/umd/cssLanguageTypes.js +89 -88
- package/lib/umd/data/webCustomData.js +21978 -21978
- package/lib/umd/languageFacts/builtinData.js +154 -154
- package/lib/umd/languageFacts/colors.js +492 -495
- package/lib/umd/languageFacts/dataManager.js +101 -104
- package/lib/umd/languageFacts/dataProvider.js +86 -91
- package/lib/umd/languageFacts/entry.js +152 -153
- package/lib/umd/languageFacts/facts.js +29 -29
- package/lib/umd/parser/cssErrors.js +61 -62
- package/lib/umd/parser/cssNodes.js +1587 -2034
- package/lib/umd/parser/cssParser.js +1547 -1575
- package/lib/umd/parser/cssScanner.js +606 -611
- package/lib/umd/parser/cssSymbolScope.js +328 -353
- package/lib/umd/parser/lessParser.js +727 -752
- package/lib/umd/parser/lessScanner.js +70 -90
- package/lib/umd/parser/scssErrors.js +31 -32
- package/lib/umd/parser/scssParser.js +809 -830
- package/lib/umd/parser/scssScanner.js +108 -128
- package/lib/umd/services/cssCodeActions.js +90 -93
- package/lib/umd/services/cssCompletion.js +1067 -1161
- package/lib/umd/services/cssFolding.js +203 -206
- package/lib/umd/services/cssFormatter.js +150 -150
- package/lib/umd/services/cssHover.js +161 -163
- package/lib/umd/services/cssNavigation.js +391 -482
- package/lib/umd/services/cssSelectionRange.js +60 -60
- package/lib/umd/services/cssValidation.js +54 -56
- package/lib/umd/services/lessCompletion.js +391 -409
- package/lib/umd/services/lint.js +531 -544
- package/lib/umd/services/lintRules.js +91 -95
- package/lib/umd/services/lintUtil.js +210 -218
- package/lib/umd/services/pathCompletion.js +171 -244
- package/lib/umd/services/scssCompletion.js +367 -390
- package/lib/umd/services/scssNavigation.js +95 -166
- package/lib/umd/services/selectorPrinting.js +510 -550
- package/lib/umd/utils/arrays.js +55 -61
- package/lib/umd/utils/objects.js +25 -25
- package/lib/umd/utils/resources.js +26 -39
- package/lib/umd/utils/strings.js +120 -122
- 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function format(document, range, options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (range) {
|
|
27
|
-
|
|
28
|
-
// include all leading whitespace iff at the beginning of the line
|
|
29
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
58
|
-
initialIndentLevel = computeIndentLevel(document.getText(), startOfLineOffset, options);
|
|
59
|
-
}
|
|
60
|
-
if (inRule) {
|
|
61
|
-
value =
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
range = cssLanguageTypes_1.Range.create(cssLanguageTypes_1.Position.create(0, 0), document.positionAt(value.length));
|
|
66
|
-
}
|
|
67
|
-
|
|
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
|
-
|
|
82
|
-
if (inRule) {
|
|
83
|
-
result = trimLeft(result.substring(2));
|
|
84
|
-
}
|
|
85
|
-
if (initialIndentLevel > 0) {
|
|
86
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
function isInRule(str, offset) {
|
|
104
|
-
while (offset >= 0) {
|
|
105
|
-
|
|
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
|
-
|
|
119
|
-
if (value !== null) {
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return dflt;
|
|
124
|
-
}
|
|
125
|
-
function computeIndentLevel(content, offset, options) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
while (i < content.length) {
|
|
130
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.clientCapabilities = clientCapabilities;
|
|
26
|
-
this.cssDataManager = cssDataManager;
|
|
27
|
-
this.selectorPrinting = new selectorPrinting_1.SelectorPrinting(cssDataManager);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.defaultSettings = settings;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.supportsMarkdown
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
+
});
|