@master/css-language-service 2.0.0-rc.69 → 2.0.0-rc.70
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/README.md +57 -6
- package/dist/common.d.ts +1 -9
- package/dist/common.mjs +1 -48
- package/dist/core.d.ts +11 -10
- package/dist/core.mjs +70 -200
- package/dist/features/inspect-syntax.mjs +18 -32
- package/dist/features/render-semantic-tokens.d.ts +5 -0
- package/dist/features/render-semantic-tokens.mjs +10 -0
- package/dist/features/render-syntax-colors.mjs +23 -8
- package/dist/features/suggest-syntax.d.ts +2 -1
- package/dist/features/suggest-syntax.mjs +2 -2
- package/dist/index.mjs +1 -1
- package/dist/settings.d.ts +4 -7
- package/dist/settings.mjs +12 -41
- package/dist/utils/beautify-css.mjs +1 -1
- package/dist/utils/completion-index.d.ts +38 -0
- package/dist/utils/completion-index.mjs +268 -0
- package/dist/utils/convert-color-token.d.ts +1 -1
- package/dist/utils/convert-color-token.mjs +1 -1
- package/dist/utils/create-css-markdown-documentation.d.ts +5 -0
- package/dist/utils/create-css-markdown-documentation.mjs +15 -0
- package/dist/utils/get-class-completion-items.d.ts +4 -0
- package/dist/utils/get-class-completion-items.mjs +20 -0
- package/dist/utils/get-color-completion-items.d.ts +1 -1
- package/dist/utils/get-color-completion-items.mjs +6 -9
- package/dist/utils/get-pseudo-class-completion-items.d.ts +3 -2
- package/dist/utils/get-pseudo-class-completion-items.mjs +45 -42
- package/dist/utils/get-pseudo-element-completion-items.d.ts +3 -2
- package/dist/utils/get-pseudo-element-completion-items.mjs +17 -28
- package/dist/utils/get-query-completion-items.d.ts +3 -2
- package/dist/utils/get-query-completion-items.mjs +19 -32
- package/dist/utils/get-utility-info.d.ts +2 -5
- package/dist/utils/get-utility-info.mjs +4 -16
- package/dist/utils/get-value-completion-items.d.ts +3 -2
- package/dist/utils/get-value-completion-items.mjs +145 -123
- package/dist/utils/query-syntax-completions.d.ts +3 -2
- package/dist/utils/query-syntax-completions.mjs +25 -44
- package/package.json +1 -1
- package/dist/common.cjs +0 -57
- package/dist/core.cjs +0 -246
- package/dist/features/edit-syntax-colors.cjs +0 -19
- package/dist/features/inspect-syntax.cjs +0 -70
- package/dist/features/render-syntax-colors.cjs +0 -89
- package/dist/features/suggest-syntax.cjs +0 -20
- package/dist/index.cjs +0 -29
- package/dist/settings.cjs +0 -84
- package/dist/utils/beautify-css.cjs +0 -13
- package/dist/utils/convert-color-token.cjs +0 -60
- package/dist/utils/create-doc.cjs +0 -26
- package/dist/utils/css-data-provider.cjs +0 -9
- package/dist/utils/css-data-provider.d.ts +0 -3
- package/dist/utils/css-data-provider.mjs +0 -7
- package/dist/utils/find-matching-brackets.cjs +0 -29
- package/dist/utils/find-matching-brackets.d.ts +0 -1
- package/dist/utils/find-matching-brackets.mjs +0 -27
- package/dist/utils/get-color-completion-items.cjs +0 -29
- package/dist/utils/get-css-data-documentation.cjs +0 -88
- package/dist/utils/get-css-data-documentation.d.ts +0 -5
- package/dist/utils/get-css-data-documentation.mjs +0 -86
- package/dist/utils/get-main-completion-items.cjs +0 -106
- package/dist/utils/get-main-completion-items.d.ts +0 -3
- package/dist/utils/get-main-completion-items.mjs +0 -104
- package/dist/utils/get-position.cjs +0 -12
- package/dist/utils/get-pseudo-class-completion-items.cjs +0 -67
- package/dist/utils/get-pseudo-element-completion-items.cjs +0 -56
- package/dist/utils/get-query-completion-items.cjs +0 -92
- package/dist/utils/get-range.cjs +0 -23
- package/dist/utils/get-utility-info.cjs +0 -33
- package/dist/utils/get-value-completion-items.cjs +0 -183
- package/dist/utils/query-syntax-completions.cjs +0 -115
- package/dist/utils/regex.cjs +0 -5
- package/dist/utils/sort-completion-items.cjs +0 -13
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
2
|
-
import { createCSS, SyntaxRuleType, generateCSS, isCoreRule } from '@master/css';
|
|
3
|
-
import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
|
|
4
|
-
import sortCompletionItems from './sort-completion-items.mjs';
|
|
5
|
-
import getUtilityInfo from './get-utility-info.mjs';
|
|
6
|
-
import cssDataProvider from './css-data-provider.mjs';
|
|
7
|
-
|
|
8
|
-
function getMainCompletionItems(css = createCSS()) {
|
|
9
|
-
const completionItems = [];
|
|
10
|
-
const addedKeys = new Set();
|
|
11
|
-
for (const eachDefinedRule of css.definedRules){
|
|
12
|
-
if (eachDefinedRule.definition.type === SyntaxRuleType.Utility) {
|
|
13
|
-
const { data, detail, docs } = getUtilityInfo(eachDefinedRule, css);
|
|
14
|
-
const utilityName = eachDefinedRule.id.slice(1);
|
|
15
|
-
completionItems.push({
|
|
16
|
-
label: utilityName,
|
|
17
|
-
kind: CompletionItemKind.Value,
|
|
18
|
-
documentation: getCSSDataDocumentation(data, {
|
|
19
|
-
generatedCSS: generateCSS([
|
|
20
|
-
utilityName
|
|
21
|
-
], css),
|
|
22
|
-
docs
|
|
23
|
-
}),
|
|
24
|
-
detail
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
const nativeProperties = cssDataProvider.provideProperties();
|
|
28
|
-
const nativeCSSPropertyData = nativeProperties.find(({ name })=>name === eachDefinedRule.id);
|
|
29
|
-
const eachCompletionItem = {
|
|
30
|
-
kind: CompletionItemKind.Property,
|
|
31
|
-
documentation: getCSSDataDocumentation(nativeCSSPropertyData, {
|
|
32
|
-
docs: '/reference/' + isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
|
|
33
|
-
}),
|
|
34
|
-
detail: nativeCSSPropertyData?.syntax
|
|
35
|
-
};
|
|
36
|
-
eachDefinedRule.keys.forEach((key)=>{
|
|
37
|
-
addedKeys.delete(key);
|
|
38
|
-
completionItems.push({
|
|
39
|
-
...eachCompletionItem,
|
|
40
|
-
label: key + ':',
|
|
41
|
-
sortText: key,
|
|
42
|
-
command: {
|
|
43
|
-
title: 'triggerSuggest',
|
|
44
|
-
command: 'editor.action.triggerSuggest'
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
/**
|
|
49
|
-
* @example @ animation and ~ transition
|
|
50
|
-
*/ if (eachDefinedRule.definition?.sign && eachDefinedRule.definition.includeAnimations) {
|
|
51
|
-
css.animations.forEach((animation, animationName)=>{
|
|
52
|
-
completionItems.push({
|
|
53
|
-
...eachCompletionItem,
|
|
54
|
-
label: eachDefinedRule.definition.sign + animationName + '|1s',
|
|
55
|
-
kind: CompletionItemKind.Value
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (eachDefinedRule.definition?.aliasGroups?.length) {
|
|
60
|
-
for (const aliasGroup of eachDefinedRule.definition.aliasGroups){
|
|
61
|
-
if (addedKeys.has(aliasGroup)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
addedKeys.add(aliasGroup);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
addedKeys.forEach((aliasGroup)=>{
|
|
70
|
-
/**
|
|
71
|
-
* Ambiguous keys are added to the completion list
|
|
72
|
-
* @example text: t:
|
|
73
|
-
*/ completionItems.push({
|
|
74
|
-
kind: CompletionItemKind.Property,
|
|
75
|
-
detail: 'ambiguous key',
|
|
76
|
-
label: aliasGroup + ':',
|
|
77
|
-
sortText: aliasGroup,
|
|
78
|
-
command: {
|
|
79
|
-
title: 'triggerSuggest',
|
|
80
|
-
command: 'editor.action.triggerSuggest'
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
if (css.config.components) {
|
|
85
|
-
for(const componentClass in css.config.components){
|
|
86
|
-
const componentTokens = css.components.get(componentClass);
|
|
87
|
-
if (!componentTokens) continue;
|
|
88
|
-
completionItems.push({
|
|
89
|
-
label: componentClass,
|
|
90
|
-
kind: CompletionItemKind.Value,
|
|
91
|
-
documentation: getCSSDataDocumentation({}, {
|
|
92
|
-
generatedCSS: generateCSS([
|
|
93
|
-
componentClass
|
|
94
|
-
], css),
|
|
95
|
-
docs: '/guide/components'
|
|
96
|
-
}),
|
|
97
|
-
detail: componentTokens.join(' ') + ' (style)'
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return sortCompletionItems(completionItems);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export { getMainCompletionItems as default };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var vscodeLanguageserverTextdocument = require('vscode-languageserver-textdocument');
|
|
4
|
-
|
|
5
|
-
function getPosition(searchString, text) {
|
|
6
|
-
const document = vscodeLanguageserverTextdocument.TextDocument.create('mockuri://test', 'plaintext', 1, text);
|
|
7
|
-
const offset = text.indexOf(searchString);
|
|
8
|
-
const position = document.positionAt(offset);
|
|
9
|
-
return position;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = getPosition;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var css = require('@master/css');
|
|
4
|
-
var cssDataProvider = require('./css-data-provider.cjs');
|
|
5
|
-
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
6
|
-
var sortCompletionItems = require('./sort-completion-items.cjs');
|
|
7
|
-
var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
|
|
8
|
-
|
|
9
|
-
const kind = vscodeLanguageserverProtocol.CompletionItemKind.Function;
|
|
10
|
-
function getPseudoClassCompletionItems(css$1 = css.createCSS(), syntax) {
|
|
11
|
-
const pseudoClassDataList = cssDataProvider.providePseudoClasses().filter((data)=>{
|
|
12
|
-
// exclude @page pseudo-classes
|
|
13
|
-
if ([
|
|
14
|
-
':first',
|
|
15
|
-
':left',
|
|
16
|
-
':right',
|
|
17
|
-
':blank'
|
|
18
|
-
].includes(data.name)) return false;
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
const completionItems = pseudoClassDataList.map((data)=>{
|
|
22
|
-
// fix https://github.com/microsoft/vscode-custom-data/issues/78
|
|
23
|
-
const name = /:(?:dir|has|is|nth-col|where)/.test(data.name) ? data.name + '()' : data.name;
|
|
24
|
-
let sortText = name.startsWith(':-') ? 'yyyy' + name.slice(2) : 'yy' + name.replace(/^:/, '');
|
|
25
|
-
if (sortText.endsWith('()')) sortText = 'y' + sortText;
|
|
26
|
-
return {
|
|
27
|
-
label: name,
|
|
28
|
-
sortText,
|
|
29
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
|
|
30
|
-
generatedCSS: css.generateCSS([
|
|
31
|
-
syntax + name.slice(1)
|
|
32
|
-
], css$1),
|
|
33
|
-
docs: '/guide/selectors'
|
|
34
|
-
}),
|
|
35
|
-
kind,
|
|
36
|
-
data
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
const selectors = {
|
|
40
|
-
...css$1.config.selectors,
|
|
41
|
-
':of': ':of'
|
|
42
|
-
};
|
|
43
|
-
for(const name in selectors){
|
|
44
|
-
if (name.startsWith('::')) continue;
|
|
45
|
-
const value = selectors[name];
|
|
46
|
-
const data = pseudoClassDataList.find((data)=>value.startsWith(data.name));
|
|
47
|
-
let sortText = name.startsWith(':-') ? 'yyyy' + name.slice(2) : 'yy' + name.replace(/^:/, '');
|
|
48
|
-
if (sortText.endsWith('()')) sortText = 'y' + sortText;
|
|
49
|
-
const completionItem = {
|
|
50
|
-
label: name,
|
|
51
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
|
|
52
|
-
generatedCSS: css.generateCSS([
|
|
53
|
-
syntax + name.slice(1)
|
|
54
|
-
], css$1),
|
|
55
|
-
docs: '/guide/selectors'
|
|
56
|
-
}),
|
|
57
|
-
sortText,
|
|
58
|
-
kind,
|
|
59
|
-
detail: String(value),
|
|
60
|
-
data
|
|
61
|
-
};
|
|
62
|
-
completionItems.push(completionItem);
|
|
63
|
-
}
|
|
64
|
-
return sortCompletionItems(completionItems);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = getPseudoClassCompletionItems;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var css = require('@master/css');
|
|
4
|
-
var cssDataProvider = require('./css-data-provider.cjs');
|
|
5
|
-
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
6
|
-
var sortCompletionItems = require('./sort-completion-items.cjs');
|
|
7
|
-
var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
|
|
8
|
-
|
|
9
|
-
const kind = vscodeLanguageserverProtocol.CompletionItemKind.Function;
|
|
10
|
-
function getPseudoElementCompletionItems(css$1 = css.createCSS(), syntax) {
|
|
11
|
-
const pseudoElementDataList = cssDataProvider.providePseudoElements();
|
|
12
|
-
const completionItems = pseudoElementDataList.map((data)=>{
|
|
13
|
-
// fix https://github.com/microsoft/vscode-custom-data/issues/78
|
|
14
|
-
const name = /::(?:part|slotted)/.test(data.name) ? data.name + '()' : data.name;
|
|
15
|
-
let sortText = name.startsWith('::-') ? 'zzzz' + name.slice(3) : 'zz' + name.replace(/^::/, '');
|
|
16
|
-
if (sortText.endsWith('()')) sortText = 'z' + sortText;
|
|
17
|
-
return {
|
|
18
|
-
label: name,
|
|
19
|
-
sortText,
|
|
20
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
|
|
21
|
-
generatedCSS: css.generateCSS([
|
|
22
|
-
syntax + name.slice(2)
|
|
23
|
-
], css$1),
|
|
24
|
-
docs: '/guide/selectors'
|
|
25
|
-
}),
|
|
26
|
-
kind,
|
|
27
|
-
data
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
for(const selectorName in css$1.config.selectors){
|
|
31
|
-
if (!selectorName.startsWith('::')) continue;
|
|
32
|
-
const selectorValue = css$1.config.selectors[selectorName];
|
|
33
|
-
const name = selectorName.endsWith('(') ? selectorName + ')' : selectorName;
|
|
34
|
-
const value = typeof selectorValue === 'string' ? selectorValue.endsWith('(') ? selectorValue + ')' : selectorValue : selectorValue;
|
|
35
|
-
const data = pseudoElementDataList.find((data)=>typeof value === 'string' ? value.startsWith(data.name) : false);
|
|
36
|
-
let sortText = name.startsWith('::-') ? 'zzzz' + name.slice(3) : 'zz' + name.replace(/^::/, '');
|
|
37
|
-
if (sortText.endsWith('()')) sortText = 'z' + sortText;
|
|
38
|
-
const completionItem = {
|
|
39
|
-
label: name,
|
|
40
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
|
|
41
|
-
generatedCSS: css.generateCSS([
|
|
42
|
-
syntax + name.slice(2)
|
|
43
|
-
], css$1),
|
|
44
|
-
docs: '/guide/selectors'
|
|
45
|
-
}),
|
|
46
|
-
sortText,
|
|
47
|
-
kind,
|
|
48
|
-
detail: String(value),
|
|
49
|
-
data
|
|
50
|
-
};
|
|
51
|
-
completionItems.push(completionItem);
|
|
52
|
-
}
|
|
53
|
-
return sortCompletionItems(completionItems);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = getPseudoElementCompletionItems;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var css = require('@master/css');
|
|
4
|
-
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
5
|
-
var sortCompletionItems = require('./sort-completion-items.cjs');
|
|
6
|
-
var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
|
|
7
|
-
var cssDataProvider = require('./css-data-provider.cjs');
|
|
8
|
-
|
|
9
|
-
function getQueryCompletionItems(css$1 = css.createCSS(), triggerCharacter = css.AT_SIGN, syntax) {
|
|
10
|
-
const atDataList = cssDataProvider.provideAtDirectives();
|
|
11
|
-
const completionItems = [];
|
|
12
|
-
if (!css.QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
13
|
-
[
|
|
14
|
-
'media',
|
|
15
|
-
'container',
|
|
16
|
-
'supports'
|
|
17
|
-
].forEach((name)=>{
|
|
18
|
-
completionItems.push({
|
|
19
|
-
label: triggerCharacter + name + '()',
|
|
20
|
-
filterText: name + '()',
|
|
21
|
-
insertText: name + '()',
|
|
22
|
-
sortText: name + '()',
|
|
23
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(atDataList.find(({ name })=>name === '@' + name), {
|
|
24
|
-
generatedCSS: css.generateCSS([
|
|
25
|
-
syntax + name + '()'
|
|
26
|
-
], css$1),
|
|
27
|
-
docs: '/guide/at'
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const handleNumberNodes = (atRule, token)=>{
|
|
33
|
-
const numberNode = css.getSingleAtNumberRuleNode(atRule.nodes);
|
|
34
|
-
if (numberNode) {
|
|
35
|
-
const prevComparisonCharacter = syntax.charAt(syntax.length - 2);
|
|
36
|
-
const comparisonCharacter = prevComparisonCharacter === '>' || prevComparisonCharacter === '<' ? prevComparisonCharacter + triggerCharacter : triggerCharacter;
|
|
37
|
-
const text = css.generateAt(css.parseAt(comparisonCharacter + token, css$1));
|
|
38
|
-
completionItems.push({
|
|
39
|
-
label: comparisonCharacter + token,
|
|
40
|
-
sortText: vscodeLanguageserverProtocol.CompletionItemKind.Keyword + comparisonCharacter + String(Math.round(numberNode.value)).padStart(12, '0'),
|
|
41
|
-
filterText: token,
|
|
42
|
-
insertText: token,
|
|
43
|
-
detail: text,
|
|
44
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Keyword,
|
|
45
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
46
|
-
generatedCSS: css.generateCSS([
|
|
47
|
-
syntax + token
|
|
48
|
-
], css$1),
|
|
49
|
-
docs: '/guide/at'
|
|
50
|
-
})
|
|
51
|
-
});
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
css$1.atRules.forEach((atRule, token)=>{
|
|
56
|
-
const completionItem = {
|
|
57
|
-
filterText: token,
|
|
58
|
-
insertText: token,
|
|
59
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
60
|
-
generatedCSS: css.generateCSS([
|
|
61
|
-
syntax + token
|
|
62
|
-
], css$1),
|
|
63
|
-
docs: '/guide/at'
|
|
64
|
-
})
|
|
65
|
-
};
|
|
66
|
-
if ([
|
|
67
|
-
css.AT_SIGN,
|
|
68
|
-
...css.QUERY_LOGICAL_OPERATORS
|
|
69
|
-
].includes(triggerCharacter)) {
|
|
70
|
-
if (handleNumberNodes(atRule, token)) return;
|
|
71
|
-
const text = css.generateAt(css.parseAt(triggerCharacter + token, css$1));
|
|
72
|
-
completionItems.push({
|
|
73
|
-
...completionItem,
|
|
74
|
-
label: triggerCharacter + token,
|
|
75
|
-
detail: text,
|
|
76
|
-
sortText: vscodeLanguageserverProtocol.CompletionItemKind.Keyword + token,
|
|
77
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Keyword,
|
|
78
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
79
|
-
generatedCSS: css.generateCSS([
|
|
80
|
-
syntax + token
|
|
81
|
-
], css$1),
|
|
82
|
-
docs: '/guide/at'
|
|
83
|
-
})
|
|
84
|
-
});
|
|
85
|
-
} else if (css.QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
86
|
-
handleNumberNodes(atRule, token);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return sortCompletionItems(completionItems);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = getQueryCompletionItems;
|
package/dist/utils/get-range.cjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function getRange(searchString, doc) {
|
|
4
|
-
const text = doc.getText();
|
|
5
|
-
const regex = new RegExp(`(\\b(?:className|class)\\s*=\\s*(['"\`]))(.*?)\\2`, 'gs');
|
|
6
|
-
let match;
|
|
7
|
-
while((match = regex.exec(text)) !== null){
|
|
8
|
-
match[0];
|
|
9
|
-
const attrStartIndex = match.index + match[1].length;
|
|
10
|
-
const className = match[3];
|
|
11
|
-
const relativeIndex = className.indexOf(searchString);
|
|
12
|
-
if (relativeIndex !== -1) {
|
|
13
|
-
const absoluteIndex = attrStartIndex + relativeIndex;
|
|
14
|
-
return {
|
|
15
|
-
start: doc.positionAt(absoluteIndex),
|
|
16
|
-
end: doc.positionAt(absoluteIndex + searchString.length)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw new Error(`Cannot find "${searchString}" in any class attribute.`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = getRange;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var css = require('@master/css');
|
|
4
|
-
var cssDataProvider = require('./css-data-provider.cjs');
|
|
5
|
-
|
|
6
|
-
function getUtilityInfo(syntax, css$1 = css.createCSS()) {
|
|
7
|
-
const nativeProperties = cssDataProvider.provideProperties();
|
|
8
|
-
const declarations = syntax.definition.declarations;
|
|
9
|
-
const propsLength = Object.keys(declarations || {}).length;
|
|
10
|
-
const propName = Object.keys(declarations || {})[0];
|
|
11
|
-
const propValue = declarations?.[propName];
|
|
12
|
-
let data;
|
|
13
|
-
let detail;
|
|
14
|
-
/**
|
|
15
|
-
* Remaps to native CSS properties when only one property is declared
|
|
16
|
-
* */ if (propsLength === 1) {
|
|
17
|
-
const nativeCSSPropertyData = nativeProperties.find(({ name })=>name === propName);
|
|
18
|
-
data = nativeCSSPropertyData?.values?.find(({ name })=>name === propValue || name.replace(/^-(ms|moz)-/, '') === propValue);
|
|
19
|
-
if (data) {
|
|
20
|
-
detail = `${propName}: ${propValue}`;
|
|
21
|
-
} else {
|
|
22
|
-
data = nativeCSSPropertyData;
|
|
23
|
-
detail = nativeCSSPropertyData?.syntax;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
docs: '/reference/' + (data ? propName : 'utilities'),
|
|
28
|
-
data,
|
|
29
|
-
detail
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = getUtilityInfo;
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
4
|
-
var cssDataProvider = require('./css-data-provider.cjs');
|
|
5
|
-
var css = require('@master/css');
|
|
6
|
-
var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
|
|
7
|
-
var sortCompletionItems = require('./sort-completion-items.cjs');
|
|
8
|
-
|
|
9
|
-
const SCOPED_VARIABLE_PRIORITY = 'aaaa';
|
|
10
|
-
const AMBIGUOUS_PRIORITY = 'bbbb';
|
|
11
|
-
const NATIVE_PRIORITY = 'ccccc';
|
|
12
|
-
const GLOBAL_VARIABLE_PRIORITY = 'zzzz';
|
|
13
|
-
function getValueCompletionItems(css$1 = css.createCSS(), ruleKey) {
|
|
14
|
-
const nativeProperties = cssDataProvider.provideProperties();
|
|
15
|
-
const completionItems = [];
|
|
16
|
-
const nativeKey = css$1.definedRules.find(({ keys })=>keys.includes(ruleKey))?.id;
|
|
17
|
-
const nativePropertyData = nativeProperties.find(({ name })=>name === nativeKey);
|
|
18
|
-
const generateVariableCompletionItem = (variable, { scoped } = {
|
|
19
|
-
scoped: false
|
|
20
|
-
})=>{
|
|
21
|
-
const eachNativePropertyData = nativeProperties.find((x)=>x.name === variable.group) || nativePropertyData;
|
|
22
|
-
const appliedValue = scoped ? variable.key : variable.name;
|
|
23
|
-
const documentation = getCssDataDocumentation.getCSSDataDocumentation(eachNativePropertyData, {
|
|
24
|
-
generatedCSS: css.generateCSS([
|
|
25
|
-
ruleKey + ':' + appliedValue
|
|
26
|
-
], css$1),
|
|
27
|
-
docs: '/reference/' + (eachNativePropertyData?.name || 'variables')
|
|
28
|
-
});
|
|
29
|
-
const completionItem = {
|
|
30
|
-
label: variable.name,
|
|
31
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Value
|
|
32
|
-
};
|
|
33
|
-
const conflicted = completionItems.find(({ label })=>label === variable.name);
|
|
34
|
-
if (conflicted) {
|
|
35
|
-
completionItem.label = '$(' + completionItem.label + ')';
|
|
36
|
-
completionItem.documentation = getCssDataDocumentation.getCSSDataDocumentation(eachNativePropertyData, {
|
|
37
|
-
generatedCSS: css.generateCSS([
|
|
38
|
-
ruleKey + ':' + completionItem.label
|
|
39
|
-
], css$1),
|
|
40
|
-
docs: '/reference/' + (eachNativePropertyData?.name || 'variables')
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
completionItem.documentation = getCssDataDocumentation.getCSSDataDocumentation(eachNativePropertyData, {
|
|
44
|
-
generatedCSS: css.generateCSS([
|
|
45
|
-
ruleKey + ':' + appliedValue
|
|
46
|
-
], css$1),
|
|
47
|
-
docs: '/reference/' + (eachNativePropertyData?.name || 'variables')
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (variable.type === 'color') {
|
|
51
|
-
if (Object.keys(variable.modes || {}).length) {
|
|
52
|
-
completionItem.kind = vscodeLanguageserverProtocol.CompletionItemKind.Color;
|
|
53
|
-
completionItem.detail = variable.name;
|
|
54
|
-
} else {
|
|
55
|
-
// todo: packages/core should support getTextByVariable(variable)
|
|
56
|
-
const configKey = 'variables.' + (variable.group ? variable.group + '.' + variable.key : variable.name);
|
|
57
|
-
const valueToken = variable.space && variable.value ? `${variable.space}(${variable.value.split(' ').join(',')})` : variable.value;
|
|
58
|
-
// detail is shown in the detail pane
|
|
59
|
-
// todo: variable.token should be recorded as original config variable
|
|
60
|
-
completionItem.detail = String(configKey);
|
|
61
|
-
completionItem.documentation = {
|
|
62
|
-
kind: 'markdown',
|
|
63
|
-
value: valueToken + '\n\n' + documentation?.value
|
|
64
|
-
};
|
|
65
|
-
completionItem.kind = vscodeLanguageserverProtocol.CompletionItemKind.Color;
|
|
66
|
-
completionItem.sortText = 'color-' + variable.name.replace(/(.+?)-(\d+)/, (match, prefix, num)=>prefix + num.padStart(10, '0'));
|
|
67
|
-
}
|
|
68
|
-
} else if (variable.type === 'number') {
|
|
69
|
-
if (variable.name.startsWith('-') && eachNativePropertyData?.syntax?.includes('absolute')) return;
|
|
70
|
-
completionItem.detail = String(variable.name);
|
|
71
|
-
completionItem.sortText = (variable.group || '') + (variable.value >= 0 ? String(variable.value).padStart(10, '0') : '-' + String(Math.abs(variable.value)).padStart(10, '0'));
|
|
72
|
-
} else {
|
|
73
|
-
completionItem.detail = String(variable.value || variable.name);
|
|
74
|
-
}
|
|
75
|
-
return completionItem;
|
|
76
|
-
};
|
|
77
|
-
for (const eachDefinedRule of css$1.definedRules){
|
|
78
|
-
/**
|
|
79
|
-
* Scoped variables
|
|
80
|
-
* @example box: + content -> box-sizing:content
|
|
81
|
-
*/ if (eachDefinedRule.definition.key === ruleKey || eachDefinedRule.definition.subkey === ruleKey || eachDefinedRule.definition.aliasGroups?.includes(ruleKey)) {
|
|
82
|
-
eachDefinedRule.variables?.forEach((variable, variableName)=>{
|
|
83
|
-
if (completionItems.find(({ label })=>label === variableName)) return;
|
|
84
|
-
const completionItem = generateVariableCompletionItem(variable, {
|
|
85
|
-
scoped: true
|
|
86
|
-
});
|
|
87
|
-
if (completionItem) {
|
|
88
|
-
completionItem.label = variableName;
|
|
89
|
-
completionItem.sortText = SCOPED_VARIABLE_PRIORITY + variableName;
|
|
90
|
-
completionItem.detail = '(scope) ' + completionItem.detail;
|
|
91
|
-
completionItems.push(completionItem);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* @example animation:fade
|
|
97
|
-
*/ if (eachDefinedRule.keys.includes(ruleKey) && eachDefinedRule.definition.includeAnimations) {
|
|
98
|
-
css$1.animations.forEach((_, animationName)=>{
|
|
99
|
-
const isNative = eachDefinedRule.definition.type && [
|
|
100
|
-
css.SyntaxRuleType.Native,
|
|
101
|
-
css.SyntaxRuleType.NativeShorthand
|
|
102
|
-
].includes(eachDefinedRule.definition.type);
|
|
103
|
-
completionItems.push({
|
|
104
|
-
label: animationName,
|
|
105
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
|
|
106
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
107
|
-
generatedCSS: css.generateCSS([
|
|
108
|
-
ruleKey + ':' + animationName
|
|
109
|
-
], css$1),
|
|
110
|
-
docs: '/reference/' + css.isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
|
|
111
|
-
}),
|
|
112
|
-
detail: isNative ? eachDefinedRule.id + ': ' + animationName : animationName
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Ambiguous values
|
|
118
|
-
* @example text: -> center, left, right, justify
|
|
119
|
-
* @example t: -> center, left, right, justify
|
|
120
|
-
*/ if (eachDefinedRule.definition.aliasGroups?.includes(ruleKey) && eachDefinedRule.definition.values?.length) {
|
|
121
|
-
const nativePropertyData = nativeProperties.find((x)=>x.name === eachDefinedRule.id);
|
|
122
|
-
for (const value of eachDefinedRule.definition.values){
|
|
123
|
-
if (typeof value !== 'string') continue;
|
|
124
|
-
const nativeValueData = nativePropertyData?.values?.find((x)=>x.name === value);
|
|
125
|
-
const isNative = eachDefinedRule.definition.type && [
|
|
126
|
-
css.SyntaxRuleType.Native,
|
|
127
|
-
css.SyntaxRuleType.NativeShorthand
|
|
128
|
-
].includes(eachDefinedRule.definition.type);
|
|
129
|
-
completionItems.push({
|
|
130
|
-
label: value,
|
|
131
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
|
|
132
|
-
sortText: AMBIGUOUS_PRIORITY + value,
|
|
133
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation({
|
|
134
|
-
...nativeValueData || {},
|
|
135
|
-
// use nativePropertyData.reference because nativeValueData does not have references
|
|
136
|
-
references: nativePropertyData?.references
|
|
137
|
-
}, {
|
|
138
|
-
generatedCSS: css.generateCSS([
|
|
139
|
-
ruleKey + ':' + value
|
|
140
|
-
], css$1),
|
|
141
|
-
docs: '/reference/' + css.isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
|
|
142
|
-
}),
|
|
143
|
-
detail: isNative ? eachDefinedRule.id + ': ' + value : value
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Native values
|
|
150
|
-
*/ if (nativeKey) {
|
|
151
|
-
nativePropertyData?.values?.forEach((value)=>{
|
|
152
|
-
if (completionItems.find((x)=>x.label === value.name) || nativePropertyData.name === 'font' && typeof +value.name === 'number' || value.name.includes(' ')) return;
|
|
153
|
-
completionItems.push({
|
|
154
|
-
label: value.name,
|
|
155
|
-
kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
|
|
156
|
-
sortText: NATIVE_PRIORITY + (value.name.startsWith('-') ? 'zz' + value.name.slice(1) : value.name),
|
|
157
|
-
documentation: getCssDataDocumentation.getCSSDataDocumentation({
|
|
158
|
-
...value,
|
|
159
|
-
// use nativePropertyData.reference because nativeValueData does not have references
|
|
160
|
-
references: nativePropertyData?.references
|
|
161
|
-
}, {
|
|
162
|
-
generatedCSS: css.generateCSS([
|
|
163
|
-
ruleKey + ':' + value.name
|
|
164
|
-
], css$1),
|
|
165
|
-
docs: '/reference/' + nativeKey
|
|
166
|
-
}),
|
|
167
|
-
detail: nativeKey + ': ' + value.name
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
// global variables
|
|
172
|
-
css$1.variables.forEach((variable)=>{
|
|
173
|
-
const completionItem = generateVariableCompletionItem(variable);
|
|
174
|
-
if (completionItem) {
|
|
175
|
-
completionItem.sortText = GLOBAL_VARIABLE_PRIORITY + (completionItem.sortText || completionItem.label);
|
|
176
|
-
completionItem.detail = '(global) ' + completionItem.detail;
|
|
177
|
-
completionItems.push(completionItem);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
return sortCompletionItems(completionItems);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
module.exports = getValueCompletionItems;
|