vscode-css-languageservice 6.3.10 → 7.0.0-next.1
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 +8 -0
- package/lib/esm/beautify/beautify-css.js +1437 -1606
- package/lib/esm/cssLanguageService.d.ts +2 -2
- package/lib/esm/cssLanguageService.js +18 -18
- package/lib/esm/languageFacts/colors.js +1 -1
- package/lib/esm/languageFacts/dataManager.js +3 -3
- package/lib/esm/languageFacts/entry.js +1 -1
- package/lib/esm/languageFacts/facts.js +3 -3
- package/lib/esm/parser/cssNodes.js +1 -1
- package/lib/esm/parser/cssParser.js +5 -5
- package/lib/esm/parser/cssSymbolScope.js +2 -2
- package/lib/esm/parser/lessParser.js +5 -5
- package/lib/esm/parser/lessScanner.js +1 -1
- package/lib/esm/parser/scssParser.js +6 -6
- package/lib/esm/parser/scssScanner.js +1 -1
- package/lib/esm/services/cssCodeActions.js +4 -4
- package/lib/esm/services/cssCompletion.js +7 -7
- package/lib/esm/services/cssFolding.js +3 -3
- package/lib/esm/services/cssFormatter.js +3 -3
- package/lib/esm/services/cssHover.js +6 -6
- package/lib/esm/services/cssNavigation.js +6 -6
- package/lib/esm/services/cssSelectionRange.js +2 -2
- package/lib/esm/services/cssValidation.js +4 -4
- package/lib/esm/services/lessCompletion.js +2 -2
- package/lib/esm/services/lint.js +5 -5
- package/lib/esm/services/lintRules.js +1 -1
- package/lib/esm/services/lintUtil.js +1 -1
- package/lib/esm/services/pathCompletion.js +3 -3
- package/lib/esm/services/scssCompletion.js +3 -3
- package/lib/esm/services/scssNavigation.js +4 -4
- package/lib/esm/services/selectorPrinting.js +3 -3
- package/package.json +15 -15
- package/lib/umd/beautify/beautify-css.js +0 -1695
- package/lib/umd/cssLanguageService.d.ts +0 -39
- package/lib/umd/cssLanguageService.js +0 -105
- package/lib/umd/cssLanguageTypes.d.ts +0 -267
- package/lib/umd/cssLanguageTypes.js +0 -89
- package/lib/umd/data/webCustomData.js +0 -44613
- package/lib/umd/languageFacts/builtinData.js +0 -155
- package/lib/umd/languageFacts/colors.js +0 -949
- package/lib/umd/languageFacts/dataManager.js +0 -101
- package/lib/umd/languageFacts/dataProvider.js +0 -86
- package/lib/umd/languageFacts/entry.js +0 -217
- package/lib/umd/languageFacts/facts.js +0 -33
- package/lib/umd/parser/cssErrors.js +0 -61
- package/lib/umd/parser/cssNodes.js +0 -1676
- package/lib/umd/parser/cssParser.js +0 -2035
- package/lib/umd/parser/cssScanner.js +0 -619
- package/lib/umd/parser/cssSymbolScope.js +0 -328
- package/lib/umd/parser/lessParser.js +0 -732
- package/lib/umd/parser/lessScanner.js +0 -70
- package/lib/umd/parser/scssErrors.js +0 -30
- package/lib/umd/parser/scssParser.js +0 -874
- package/lib/umd/parser/scssScanner.js +0 -108
- package/lib/umd/services/cssCodeActions.js +0 -89
- package/lib/umd/services/cssCompletion.js +0 -1109
- package/lib/umd/services/cssFolding.js +0 -202
- package/lib/umd/services/cssFormatter.js +0 -149
- package/lib/umd/services/cssHover.js +0 -174
- package/lib/umd/services/cssNavigation.js +0 -539
- package/lib/umd/services/cssSelectionRange.js +0 -59
- package/lib/umd/services/cssValidation.js +0 -54
- package/lib/umd/services/lessCompletion.js +0 -390
- package/lib/umd/services/lint.js +0 -577
- package/lib/umd/services/lintRules.js +0 -90
- package/lib/umd/services/lintUtil.js +0 -210
- package/lib/umd/services/pathCompletion.js +0 -171
- package/lib/umd/services/scssCompletion.js +0 -367
- package/lib/umd/services/scssNavigation.js +0 -169
- package/lib/umd/services/selectorPrinting.js +0 -575
- package/lib/umd/utils/arrays.js +0 -54
- package/lib/umd/utils/objects.js +0 -24
- package/lib/umd/utils/resources.js +0 -25
- package/lib/umd/utils/strings.js +0 -123
|
@@ -1,202 +0,0 @@
|
|
|
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/cssScanner", "../parser/scssScanner", "../parser/lessScanner"], 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.getFoldingRanges = getFoldingRanges;
|
|
17
|
-
const cssScanner_1 = require("../parser/cssScanner");
|
|
18
|
-
const scssScanner_1 = require("../parser/scssScanner");
|
|
19
|
-
const lessScanner_1 = require("../parser/lessScanner");
|
|
20
|
-
function getFoldingRanges(document, context) {
|
|
21
|
-
const ranges = computeFoldingRanges(document);
|
|
22
|
-
return limitFoldingRanges(ranges, context);
|
|
23
|
-
}
|
|
24
|
-
function computeFoldingRanges(document) {
|
|
25
|
-
function getStartLine(t) {
|
|
26
|
-
return document.positionAt(t.offset).line;
|
|
27
|
-
}
|
|
28
|
-
function getEndLine(t) {
|
|
29
|
-
return document.positionAt(t.offset + t.len).line;
|
|
30
|
-
}
|
|
31
|
-
function getScanner() {
|
|
32
|
-
switch (document.languageId) {
|
|
33
|
-
case 'scss':
|
|
34
|
-
return new scssScanner_1.SCSSScanner();
|
|
35
|
-
case 'less':
|
|
36
|
-
return new lessScanner_1.LESSScanner();
|
|
37
|
-
default:
|
|
38
|
-
return new cssScanner_1.Scanner();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function tokenToRange(t, kind) {
|
|
42
|
-
const startLine = getStartLine(t);
|
|
43
|
-
const endLine = getEndLine(t);
|
|
44
|
-
if (startLine !== endLine) {
|
|
45
|
-
return {
|
|
46
|
-
startLine,
|
|
47
|
-
endLine,
|
|
48
|
-
kind
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const ranges = [];
|
|
56
|
-
const delimiterStack = [];
|
|
57
|
-
const scanner = getScanner();
|
|
58
|
-
scanner.ignoreComment = false;
|
|
59
|
-
scanner.setSource(document.getText());
|
|
60
|
-
let token = scanner.scan();
|
|
61
|
-
let prevToken = null;
|
|
62
|
-
while (token.type !== cssScanner_1.TokenType.EOF) {
|
|
63
|
-
switch (token.type) {
|
|
64
|
-
case cssScanner_1.TokenType.CurlyL:
|
|
65
|
-
case scssScanner_1.InterpolationFunction:
|
|
66
|
-
{
|
|
67
|
-
delimiterStack.push({ line: getStartLine(token), type: 'brace', isStart: true });
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case cssScanner_1.TokenType.CurlyR: {
|
|
71
|
-
if (delimiterStack.length !== 0) {
|
|
72
|
-
const prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'brace');
|
|
73
|
-
if (!prevDelimiter) {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
let endLine = getEndLine(token);
|
|
77
|
-
if (prevDelimiter.type === 'brace') {
|
|
78
|
-
/**
|
|
79
|
-
* Other than the case when curly brace is not on a new line by itself, for example
|
|
80
|
-
* .foo {
|
|
81
|
-
* color: red; }
|
|
82
|
-
* Use endLine minus one to show ending curly brace
|
|
83
|
-
*/
|
|
84
|
-
if (prevToken && getEndLine(prevToken) !== endLine) {
|
|
85
|
-
endLine--;
|
|
86
|
-
}
|
|
87
|
-
if (prevDelimiter.line !== endLine) {
|
|
88
|
-
ranges.push({
|
|
89
|
-
startLine: prevDelimiter.line,
|
|
90
|
-
endLine,
|
|
91
|
-
kind: undefined
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* In CSS, there is no single line comment prefixed with //
|
|
100
|
-
* All comments are marked as `Comment`
|
|
101
|
-
*/
|
|
102
|
-
case cssScanner_1.TokenType.Comment: {
|
|
103
|
-
const commentRegionMarkerToDelimiter = (marker) => {
|
|
104
|
-
if (marker === '#region') {
|
|
105
|
-
return { line: getStartLine(token), type: 'comment', isStart: true };
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return { line: getEndLine(token), type: 'comment', isStart: false };
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const getCurrDelimiter = (token) => {
|
|
112
|
-
const matches = token.text.match(/^\s*\/\*\s*(#region|#endregion)\b\s*(.*?)\s*\*\//);
|
|
113
|
-
if (matches) {
|
|
114
|
-
return commentRegionMarkerToDelimiter(matches[1]);
|
|
115
|
-
}
|
|
116
|
-
else if (document.languageId === 'scss' || document.languageId === 'less') {
|
|
117
|
-
const matches = token.text.match(/^\s*\/\/\s*(#region|#endregion)\b\s*(.*?)\s*/);
|
|
118
|
-
if (matches) {
|
|
119
|
-
return commentRegionMarkerToDelimiter(matches[1]);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
};
|
|
124
|
-
const currDelimiter = getCurrDelimiter(token);
|
|
125
|
-
// /* */ comment region folding
|
|
126
|
-
// All #region and #endregion cases
|
|
127
|
-
if (currDelimiter) {
|
|
128
|
-
if (currDelimiter.isStart) {
|
|
129
|
-
delimiterStack.push(currDelimiter);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
const prevDelimiter = popPrevStartDelimiterOfType(delimiterStack, 'comment');
|
|
133
|
-
if (!prevDelimiter) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
if (prevDelimiter.type === 'comment') {
|
|
137
|
-
if (prevDelimiter.line !== currDelimiter.line) {
|
|
138
|
-
ranges.push({
|
|
139
|
-
startLine: prevDelimiter.line,
|
|
140
|
-
endLine: currDelimiter.line,
|
|
141
|
-
kind: 'region'
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// Multiline comment case
|
|
148
|
-
else {
|
|
149
|
-
const range = tokenToRange(token, 'comment');
|
|
150
|
-
if (range) {
|
|
151
|
-
ranges.push(range);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
prevToken = token;
|
|
158
|
-
token = scanner.scan();
|
|
159
|
-
}
|
|
160
|
-
return ranges;
|
|
161
|
-
}
|
|
162
|
-
function popPrevStartDelimiterOfType(stack, type) {
|
|
163
|
-
if (stack.length === 0) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
for (let i = stack.length - 1; i >= 0; i--) {
|
|
167
|
-
if (stack[i].type === type && stack[i].isStart) {
|
|
168
|
-
return stack.splice(i, 1)[0];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* - Sort regions
|
|
175
|
-
* - Remove invalid regions (intersections)
|
|
176
|
-
* - If limit exceeds, only return `rangeLimit` amount of ranges
|
|
177
|
-
*/
|
|
178
|
-
function limitFoldingRanges(ranges, context) {
|
|
179
|
-
const maxRanges = context && context.rangeLimit || Number.MAX_VALUE;
|
|
180
|
-
const sortedRanges = ranges.sort((r1, r2) => {
|
|
181
|
-
let diff = r1.startLine - r2.startLine;
|
|
182
|
-
if (diff === 0) {
|
|
183
|
-
diff = r1.endLine - r2.endLine;
|
|
184
|
-
}
|
|
185
|
-
return diff;
|
|
186
|
-
});
|
|
187
|
-
const validRanges = [];
|
|
188
|
-
let prevEndLine = -1;
|
|
189
|
-
sortedRanges.forEach(r => {
|
|
190
|
-
if (!(r.startLine < prevEndLine && prevEndLine < r.endLine)) {
|
|
191
|
-
validRanges.push(r);
|
|
192
|
-
prevEndLine = r.endLine;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
if (validRanges.length < maxRanges) {
|
|
196
|
-
return validRanges;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
return validRanges.slice(0, maxRanges);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
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 = format;
|
|
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
|
-
function trimLeft(str) {
|
|
98
|
-
return str.replace(/^\s+/, '');
|
|
99
|
-
}
|
|
100
|
-
const _CUL = '{'.charCodeAt(0);
|
|
101
|
-
const _CUR = '}'.charCodeAt(0);
|
|
102
|
-
function isInRule(str, offset) {
|
|
103
|
-
while (offset >= 0) {
|
|
104
|
-
const ch = str.charCodeAt(offset);
|
|
105
|
-
if (ch === _CUL) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
else if (ch === _CUR) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
offset--;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
function getFormatOption(options, key, dflt) {
|
|
116
|
-
if (options && options.hasOwnProperty(key)) {
|
|
117
|
-
const value = options[key];
|
|
118
|
-
if (value !== null) {
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return dflt;
|
|
123
|
-
}
|
|
124
|
-
function computeIndentLevel(content, offset, options) {
|
|
125
|
-
let i = offset;
|
|
126
|
-
let nChars = 0;
|
|
127
|
-
const tabSize = options.tabSize || 4;
|
|
128
|
-
while (i < content.length) {
|
|
129
|
-
const ch = content.charAt(i);
|
|
130
|
-
if (ch === ' ') {
|
|
131
|
-
nChars++;
|
|
132
|
-
}
|
|
133
|
-
else if (ch === '\t') {
|
|
134
|
-
nChars += tabSize;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
i++;
|
|
140
|
-
}
|
|
141
|
-
return Math.floor(nChars / tabSize);
|
|
142
|
-
}
|
|
143
|
-
function isEOL(text, offset) {
|
|
144
|
-
return '\r\n'.indexOf(text.charAt(offset)) !== -1;
|
|
145
|
-
}
|
|
146
|
-
function isWhitespace(text, offset) {
|
|
147
|
-
return ' \t'.indexOf(text.charAt(offset)) !== -1;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
@@ -1,174 +0,0 @@
|
|
|
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
|
-
let selectorContexts = [];
|
|
44
|
-
for (let i = 0; i < nodepath.length; i++) {
|
|
45
|
-
const node = nodepath[i];
|
|
46
|
-
if (node instanceof nodes.Scope) {
|
|
47
|
-
const scopeLimits = node.getChild(0);
|
|
48
|
-
if (scopeLimits instanceof nodes.ScopeLimits) {
|
|
49
|
-
const scopeName = `${scopeLimits.getName()}`;
|
|
50
|
-
selectorContexts.push(`@scope${scopeName ? ` ${scopeName}` : ''}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (node instanceof nodes.Media) {
|
|
54
|
-
const mediaList = node.getChild(0);
|
|
55
|
-
if (mediaList instanceof nodes.Medialist) {
|
|
56
|
-
const name = '@media ' + mediaList.getText();
|
|
57
|
-
selectorContexts.push(name);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (node instanceof nodes.Selector) {
|
|
61
|
-
hover = {
|
|
62
|
-
contents: this.selectorPrinting.selectorToMarkedString(node, selectorContexts),
|
|
63
|
-
range: getRange(node),
|
|
64
|
-
};
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
if (node instanceof nodes.SimpleSelector) {
|
|
68
|
-
/**
|
|
69
|
-
* Some sass specific at rules such as `@at-root` are parsed as `SimpleSelector`
|
|
70
|
-
*/
|
|
71
|
-
if (!(0, strings_1.startsWith)(node.getText(), '@')) {
|
|
72
|
-
hover = {
|
|
73
|
-
contents: this.selectorPrinting.simpleSelectorToMarkedString(node),
|
|
74
|
-
range: getRange(node),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
if (node instanceof nodes.Declaration) {
|
|
80
|
-
const propertyName = node.getFullPropertyName();
|
|
81
|
-
const entry = this.cssDataManager.getProperty(propertyName);
|
|
82
|
-
if (entry) {
|
|
83
|
-
const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
|
|
84
|
-
if (contents) {
|
|
85
|
-
hover = {
|
|
86
|
-
contents,
|
|
87
|
-
range: getRange(node),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
hover = null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (node instanceof nodes.UnknownAtRule) {
|
|
97
|
-
const atRuleName = node.getText();
|
|
98
|
-
const entry = this.cssDataManager.getAtDirective(atRuleName);
|
|
99
|
-
if (entry) {
|
|
100
|
-
const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
|
|
101
|
-
if (contents) {
|
|
102
|
-
hover = {
|
|
103
|
-
contents,
|
|
104
|
-
range: getRange(node),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
hover = null;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (node instanceof nodes.Node && node.type === nodes.NodeType.PseudoSelector) {
|
|
114
|
-
const selectorName = node.getText();
|
|
115
|
-
const entry = selectorName.slice(0, 2) === '::' ? this.cssDataManager.getPseudoElement(selectorName) : this.cssDataManager.getPseudoClass(selectorName);
|
|
116
|
-
if (entry) {
|
|
117
|
-
const contents = languageFacts.getEntryDescription(entry, this.doesSupportMarkdown(), settings);
|
|
118
|
-
if (contents) {
|
|
119
|
-
hover = {
|
|
120
|
-
contents,
|
|
121
|
-
range: getRange(node),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
hover = null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (hover) {
|
|
132
|
-
hover.contents = this.convertContents(hover.contents);
|
|
133
|
-
}
|
|
134
|
-
return hover;
|
|
135
|
-
}
|
|
136
|
-
convertContents(contents) {
|
|
137
|
-
if (!this.doesSupportMarkdown()) {
|
|
138
|
-
if (typeof contents === 'string') {
|
|
139
|
-
return contents;
|
|
140
|
-
}
|
|
141
|
-
// MarkupContent
|
|
142
|
-
else if ('kind' in contents) {
|
|
143
|
-
return {
|
|
144
|
-
kind: 'plaintext',
|
|
145
|
-
value: contents.value,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
// MarkedString[]
|
|
149
|
-
else if (Array.isArray(contents)) {
|
|
150
|
-
return contents.map((c) => {
|
|
151
|
-
return typeof c === 'string' ? c : c.value;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
// MarkedString
|
|
155
|
-
else {
|
|
156
|
-
return contents.value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return contents;
|
|
160
|
-
}
|
|
161
|
-
doesSupportMarkdown() {
|
|
162
|
-
if (!(0, objects_1.isDefined)(this.supportsMarkdown)) {
|
|
163
|
-
if (!(0, objects_1.isDefined)(this.clientCapabilities)) {
|
|
164
|
-
this.supportsMarkdown = true;
|
|
165
|
-
return this.supportsMarkdown;
|
|
166
|
-
}
|
|
167
|
-
const hover = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.hover;
|
|
168
|
-
this.supportsMarkdown = hover && hover.contentFormat && Array.isArray(hover.contentFormat) && hover.contentFormat.indexOf(cssLanguageTypes_1.MarkupKind.Markdown) !== -1;
|
|
169
|
-
}
|
|
170
|
-
return this.supportsMarkdown;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.CSSHover = CSSHover;
|
|
174
|
-
});
|