@master/css-language-service 2.0.0-rc.3 → 2.0.0-rc.30
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/dist/common.cjs +57 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.mjs +48 -0
- package/dist/core.cjs +248 -0
- package/dist/core.d.ts +30 -0
- package/dist/core.mjs +246 -0
- package/dist/features/edit-syntax-colors.cjs +19 -0
- package/dist/features/edit-syntax-colors.d.ts +4 -0
- package/dist/features/edit-syntax-colors.mjs +17 -0
- package/dist/features/inspect-syntax.cjs +70 -0
- package/dist/features/inspect-syntax.d.ts +4 -0
- package/dist/features/inspect-syntax.mjs +68 -0
- package/dist/features/render-syntax-colors.cjs +88 -0
- package/dist/features/render-syntax-colors.d.ts +4 -0
- package/dist/features/render-syntax-colors.mjs +86 -0
- package/dist/features/suggest-syntax.cjs +20 -0
- package/dist/features/suggest-syntax.d.ts +4 -0
- package/dist/features/suggest-syntax.mjs +18 -0
- package/dist/index.cjs +29 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.mjs +7 -0
- package/dist/settings.cjs +84 -0
- package/dist/settings.d.ts +18 -8
- package/dist/settings.mjs +82 -0
- package/dist/utils/beautify-css.cjs +13 -0
- package/dist/utils/beautify-css.d.ts +1 -0
- package/dist/utils/beautify-css.mjs +11 -0
- package/dist/utils/convert-color-space.cjs +40 -0
- package/dist/utils/convert-color-space.d.ts +2 -0
- package/dist/utils/convert-color-space.mjs +38 -0
- package/dist/utils/convert-color-token.cjs +28 -0
- package/dist/utils/convert-color-token.d.ts +3 -0
- package/dist/utils/convert-color-token.mjs +26 -0
- package/dist/utils/create-doc.cjs +26 -0
- package/dist/utils/create-doc.d.ts +16 -0
- package/dist/utils/create-doc.mjs +21 -0
- package/dist/utils/css-data-provider.cjs +9 -0
- package/dist/utils/css-data-provider.d.ts +3 -0
- package/dist/utils/css-data-provider.mjs +7 -0
- package/dist/utils/find-matching-brackets.cjs +29 -0
- package/dist/utils/find-matching-brackets.d.ts +1 -0
- package/dist/utils/find-matching-brackets.mjs +27 -0
- package/dist/utils/get-color-completion-items.cjs +30 -0
- package/dist/utils/get-color-completion-items.d.ts +3 -0
- package/dist/utils/get-color-completion-items.mjs +28 -0
- package/dist/utils/get-css-data-documentation.cjs +90 -0
- package/dist/utils/get-css-data-documentation.d.ts +5 -0
- package/dist/utils/get-css-data-documentation.mjs +88 -0
- package/dist/utils/get-main-completion-items.cjs +105 -0
- package/dist/utils/get-main-completion-items.d.ts +3 -0
- package/dist/utils/get-main-completion-items.mjs +103 -0
- package/dist/utils/get-position.cjs +12 -0
- package/dist/utils/get-position.d.ts +1 -0
- package/dist/utils/get-position.mjs +10 -0
- package/dist/utils/get-pseudo-class-completion-items.cjs +65 -0
- package/dist/utils/get-pseudo-class-completion-items.d.ts +3 -0
- package/dist/utils/get-pseudo-class-completion-items.mjs +63 -0
- package/dist/utils/get-pseudo-element-completion-items.cjs +56 -0
- package/dist/utils/get-pseudo-element-completion-items.d.ts +3 -0
- package/dist/utils/get-pseudo-element-completion-items.mjs +54 -0
- package/dist/utils/get-query-completion-items.cjs +102 -0
- package/dist/utils/get-query-completion-items.d.ts +3 -0
- package/dist/utils/get-query-completion-items.mjs +100 -0
- package/dist/utils/get-range.cjs +21 -0
- package/dist/utils/get-range.d.ts +2 -0
- package/dist/utils/get-range.mjs +19 -0
- package/dist/utils/get-utility-info.cjs +32 -0
- package/dist/utils/get-utility-info.d.ts +7 -0
- package/dist/utils/get-utility-info.mjs +30 -0
- package/dist/utils/get-value-completion-items.cjs +185 -0
- package/dist/utils/get-value-completion-items.d.ts +3 -0
- package/dist/utils/get-value-completion-items.mjs +183 -0
- package/dist/utils/query-syntax-completions.cjs +115 -0
- package/dist/utils/query-syntax-completions.d.ts +3 -0
- package/dist/utils/query-syntax-completions.mjs +113 -0
- package/dist/utils/regex.cjs +5 -0
- package/dist/utils/regex.mjs +3 -0
- package/dist/utils/sort-completion-items.cjs +11 -0
- package/dist/utils/sort-completion-items.d.ts +2 -0
- package/dist/utils/sort-completion-items.mjs +9 -0
- package/package.json +1 -1
- package/dist/constant.d.ts +0 -33
- package/dist/index.bundle.js +0 -33
- package/dist/position-check.d.ts +0 -20
- package/dist/providers/color.d.ts +0 -5
- package/dist/providers/completion.d.ts +0 -14
- package/dist/providers/hover.d.ts +0 -2
- package/dist/settings.bundle.js +0 -1
- package/dist/utils/get-css-entry-markdown-description.d.ts +0 -1
- package/dist/utils/hex-to-rgb.d.ts +0 -2
- package/dist/utils/oklab-to-rgb.d.ts +0 -1
- package/dist/utils/oklch-to-oklab.d.ts +0 -1
- package/dist/utils/to-two-digit-hex.d.ts +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
2
|
+
import { Layer, generateCSS, isCoreRule, MasterCSS } 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 = new MasterCSS()) {
|
|
9
|
+
const completionItems = [];
|
|
10
|
+
const addedKeys = new Set();
|
|
11
|
+
for (const EachRule of css.Rules){
|
|
12
|
+
if (EachRule.definition.layer === Layer.Utility) {
|
|
13
|
+
const { data, detail, docs } = getUtilityInfo(EachRule, css);
|
|
14
|
+
const utilityName = EachRule.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 === EachRule.id);
|
|
29
|
+
const eachCompletionItem = {
|
|
30
|
+
kind: CompletionItemKind.Property,
|
|
31
|
+
documentation: getCSSDataDocumentation(nativeCSSPropertyData, {
|
|
32
|
+
docs: isCoreRule(EachRule.id) && EachRule.id
|
|
33
|
+
}),
|
|
34
|
+
detail: nativeCSSPropertyData?.syntax
|
|
35
|
+
};
|
|
36
|
+
EachRule.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 (EachRule.definition?.sign && EachRule.definition.includeAnimations) {
|
|
51
|
+
for(const animationName in css.animations){
|
|
52
|
+
completionItems.push({
|
|
53
|
+
...eachCompletionItem,
|
|
54
|
+
label: EachRule.definition.sign + animationName + '|1s',
|
|
55
|
+
kind: CompletionItemKind.Value
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (EachRule.definition?.ambiguousKeys?.length) {
|
|
60
|
+
for (const ambiguousKey of EachRule.definition.ambiguousKeys){
|
|
61
|
+
if (addedKeys.has(ambiguousKey)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
addedKeys.add(ambiguousKey);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
addedKeys.forEach((ambiguousKey)=>{
|
|
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: ambiguousKey + ':',
|
|
77
|
+
sortText: ambiguousKey,
|
|
78
|
+
command: {
|
|
79
|
+
title: 'triggerSuggest',
|
|
80
|
+
command: 'editor.action.triggerSuggest'
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
if (css.config.styles) {
|
|
85
|
+
for(const styleName in css.config.styles){
|
|
86
|
+
const styleClasses = css.styles[styleName];
|
|
87
|
+
completionItems.push({
|
|
88
|
+
label: styleName,
|
|
89
|
+
kind: CompletionItemKind.Value,
|
|
90
|
+
documentation: getCSSDataDocumentation({}, {
|
|
91
|
+
generatedCSS: generateCSS([
|
|
92
|
+
styleName
|
|
93
|
+
], css),
|
|
94
|
+
docs: 'styles'
|
|
95
|
+
}),
|
|
96
|
+
detail: styleClasses.join(' ') + ' (style)'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return sortCompletionItems(completionItems);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { getMainCompletionItems as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getPosition(searchString: string, text: string): import("vscode-languageserver-textdocument").Position;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
|
|
3
|
+
function getPosition(searchString, text) {
|
|
4
|
+
const document = TextDocument.create('mockuri://test', 'plaintext', 1, text);
|
|
5
|
+
const offset = text.indexOf(searchString);
|
|
6
|
+
const position = document.positionAt(offset);
|
|
7
|
+
return position;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { getPosition as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
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 = new css.MasterCSS(), 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: 'selectors'
|
|
34
|
+
}),
|
|
35
|
+
kind,
|
|
36
|
+
data
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
for(const selectorName in css$1.config.selectors){
|
|
40
|
+
if (selectorName.startsWith('::')) continue;
|
|
41
|
+
const selectorValue = css$1.config.selectors[selectorName];
|
|
42
|
+
const name = selectorName.endsWith('(') ? selectorName + ')' : selectorName;
|
|
43
|
+
const value = typeof selectorValue === 'string' ? selectorValue.endsWith('(') ? selectorValue + ')' : selectorValue : selectorValue;
|
|
44
|
+
const data = pseudoClassDataList.find((data)=>typeof value === 'string' ? value.startsWith(data.name) : false);
|
|
45
|
+
let sortText = name.startsWith(':-') ? 'yyyy' + name.slice(2) : 'yy' + name.replace(/^:/, '');
|
|
46
|
+
if (sortText.endsWith('()')) sortText = 'y' + sortText;
|
|
47
|
+
const completionItem = {
|
|
48
|
+
label: name,
|
|
49
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
|
|
50
|
+
generatedCSS: css.generateCSS([
|
|
51
|
+
syntax + name.slice(1)
|
|
52
|
+
], css$1),
|
|
53
|
+
docs: 'selectors'
|
|
54
|
+
}),
|
|
55
|
+
sortText,
|
|
56
|
+
kind,
|
|
57
|
+
detail: String(value),
|
|
58
|
+
data
|
|
59
|
+
};
|
|
60
|
+
completionItems.push(completionItem);
|
|
61
|
+
}
|
|
62
|
+
return sortCompletionItems(completionItems);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = getPseudoClassCompletionItems;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { generateCSS, MasterCSS } from '@master/css';
|
|
2
|
+
import cssDataProvider from './css-data-provider.mjs';
|
|
3
|
+
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
4
|
+
import sortCompletionItems from './sort-completion-items.mjs';
|
|
5
|
+
import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
|
|
6
|
+
|
|
7
|
+
const kind = CompletionItemKind.Function;
|
|
8
|
+
function getPseudoClassCompletionItems(css = new MasterCSS(), syntax) {
|
|
9
|
+
const pseudoClassDataList = cssDataProvider.providePseudoClasses().filter((data)=>{
|
|
10
|
+
// exclude @page pseudo-classes
|
|
11
|
+
if ([
|
|
12
|
+
':first',
|
|
13
|
+
':left',
|
|
14
|
+
':right',
|
|
15
|
+
':blank'
|
|
16
|
+
].includes(data.name)) return false;
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
const completionItems = pseudoClassDataList.map((data)=>{
|
|
20
|
+
// fix https://github.com/microsoft/vscode-custom-data/issues/78
|
|
21
|
+
const name = /:(?:dir|has|is|nth-col|where)/.test(data.name) ? data.name + '()' : data.name;
|
|
22
|
+
let sortText = name.startsWith(':-') ? 'yyyy' + name.slice(2) : 'yy' + name.replace(/^:/, '');
|
|
23
|
+
if (sortText.endsWith('()')) sortText = 'y' + sortText;
|
|
24
|
+
return {
|
|
25
|
+
label: name,
|
|
26
|
+
sortText,
|
|
27
|
+
documentation: getCSSDataDocumentation(data, {
|
|
28
|
+
generatedCSS: generateCSS([
|
|
29
|
+
syntax + name.slice(1)
|
|
30
|
+
], css),
|
|
31
|
+
docs: 'selectors'
|
|
32
|
+
}),
|
|
33
|
+
kind,
|
|
34
|
+
data
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
for(const selectorName in css.config.selectors){
|
|
38
|
+
if (selectorName.startsWith('::')) continue;
|
|
39
|
+
const selectorValue = css.config.selectors[selectorName];
|
|
40
|
+
const name = selectorName.endsWith('(') ? selectorName + ')' : selectorName;
|
|
41
|
+
const value = typeof selectorValue === 'string' ? selectorValue.endsWith('(') ? selectorValue + ')' : selectorValue : selectorValue;
|
|
42
|
+
const data = pseudoClassDataList.find((data)=>typeof value === 'string' ? value.startsWith(data.name) : false);
|
|
43
|
+
let sortText = name.startsWith(':-') ? 'yyyy' + name.slice(2) : 'yy' + name.replace(/^:/, '');
|
|
44
|
+
if (sortText.endsWith('()')) sortText = 'y' + sortText;
|
|
45
|
+
const completionItem = {
|
|
46
|
+
label: name,
|
|
47
|
+
documentation: getCSSDataDocumentation(data, {
|
|
48
|
+
generatedCSS: generateCSS([
|
|
49
|
+
syntax + name.slice(1)
|
|
50
|
+
], css),
|
|
51
|
+
docs: 'selectors'
|
|
52
|
+
}),
|
|
53
|
+
sortText,
|
|
54
|
+
kind,
|
|
55
|
+
detail: String(value),
|
|
56
|
+
data
|
|
57
|
+
};
|
|
58
|
+
completionItems.push(completionItem);
|
|
59
|
+
}
|
|
60
|
+
return sortCompletionItems(completionItems);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { getPseudoClassCompletionItems as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
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 = new css.MasterCSS(), 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: '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: '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;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { generateCSS, MasterCSS } from '@master/css';
|
|
2
|
+
import cssDataProvider from './css-data-provider.mjs';
|
|
3
|
+
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
4
|
+
import sortCompletionItems from './sort-completion-items.mjs';
|
|
5
|
+
import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
|
|
6
|
+
|
|
7
|
+
const kind = CompletionItemKind.Function;
|
|
8
|
+
function getPseudoElementCompletionItems(css = new MasterCSS(), syntax) {
|
|
9
|
+
const pseudoElementDataList = cssDataProvider.providePseudoElements();
|
|
10
|
+
const completionItems = pseudoElementDataList.map((data)=>{
|
|
11
|
+
// fix https://github.com/microsoft/vscode-custom-data/issues/78
|
|
12
|
+
const name = /::(?:part|slotted)/.test(data.name) ? data.name + '()' : data.name;
|
|
13
|
+
let sortText = name.startsWith('::-') ? 'zzzz' + name.slice(3) : 'zz' + name.replace(/^::/, '');
|
|
14
|
+
if (sortText.endsWith('()')) sortText = 'z' + sortText;
|
|
15
|
+
return {
|
|
16
|
+
label: name,
|
|
17
|
+
sortText,
|
|
18
|
+
documentation: getCSSDataDocumentation(data, {
|
|
19
|
+
generatedCSS: generateCSS([
|
|
20
|
+
syntax + name.slice(2)
|
|
21
|
+
], css),
|
|
22
|
+
docs: 'selectors'
|
|
23
|
+
}),
|
|
24
|
+
kind,
|
|
25
|
+
data
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
for(const selectorName in css.config.selectors){
|
|
29
|
+
if (!selectorName.startsWith('::')) continue;
|
|
30
|
+
const selectorValue = css.config.selectors[selectorName];
|
|
31
|
+
const name = selectorName.endsWith('(') ? selectorName + ')' : selectorName;
|
|
32
|
+
const value = typeof selectorValue === 'string' ? selectorValue.endsWith('(') ? selectorValue + ')' : selectorValue : selectorValue;
|
|
33
|
+
const data = pseudoElementDataList.find((data)=>typeof value === 'string' ? value.startsWith(data.name) : false);
|
|
34
|
+
let sortText = name.startsWith('::-') ? 'zzzz' + name.slice(3) : 'zz' + name.replace(/^::/, '');
|
|
35
|
+
if (sortText.endsWith('()')) sortText = 'z' + sortText;
|
|
36
|
+
const completionItem = {
|
|
37
|
+
label: name,
|
|
38
|
+
documentation: getCSSDataDocumentation(data, {
|
|
39
|
+
generatedCSS: generateCSS([
|
|
40
|
+
syntax + name.slice(2)
|
|
41
|
+
], css),
|
|
42
|
+
docs: 'selectors'
|
|
43
|
+
}),
|
|
44
|
+
sortText,
|
|
45
|
+
kind,
|
|
46
|
+
detail: String(value),
|
|
47
|
+
data
|
|
48
|
+
};
|
|
49
|
+
completionItems.push(completionItem);
|
|
50
|
+
}
|
|
51
|
+
return sortCompletionItems(completionItems);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { getPseudoElementCompletionItems as default };
|
|
@@ -0,0 +1,102 @@
|
|
|
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 = new css.MasterCSS(), triggerCharacter = css.AT_SIGN, syntax) {
|
|
10
|
+
const atDataList = cssDataProvider.provideAtDirectives();
|
|
11
|
+
const completionItems = [];
|
|
12
|
+
if (!css.QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
13
|
+
completionItems.push({
|
|
14
|
+
label: triggerCharacter + 'media()',
|
|
15
|
+
filterText: 'media()',
|
|
16
|
+
insertText: 'media()',
|
|
17
|
+
sortText: 'media()',
|
|
18
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(atDataList.find(({ name })=>name === '@media'), {
|
|
19
|
+
generatedCSS: css.generateCSS([
|
|
20
|
+
syntax + 'media()'
|
|
21
|
+
], css$1),
|
|
22
|
+
docs: 'queries'
|
|
23
|
+
})
|
|
24
|
+
}, {
|
|
25
|
+
label: triggerCharacter + 'supports()',
|
|
26
|
+
filterText: 'supports()',
|
|
27
|
+
insertText: 'supports()',
|
|
28
|
+
sortText: 'supports()',
|
|
29
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(atDataList.find(({ name })=>name === '@supports'), {
|
|
30
|
+
generatedCSS: css.generateCSS([
|
|
31
|
+
syntax + 'supports()'
|
|
32
|
+
], css$1),
|
|
33
|
+
docs: 'queries'
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
Object.entries(css$1.queries).forEach(([name, value])=>{
|
|
38
|
+
const completionItem = {
|
|
39
|
+
filterText: name,
|
|
40
|
+
insertText: name,
|
|
41
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
42
|
+
generatedCSS: css.generateCSS([
|
|
43
|
+
syntax + name
|
|
44
|
+
], css$1),
|
|
45
|
+
docs: 'queries'
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
if ([
|
|
49
|
+
css.AT_SIGN,
|
|
50
|
+
...css.QUERY_LOGICAL_OPERATORS
|
|
51
|
+
].includes(triggerCharacter)) {
|
|
52
|
+
if (typeof value === 'number') {
|
|
53
|
+
completionItems.push({
|
|
54
|
+
...completionItem,
|
|
55
|
+
label: triggerCharacter + name,
|
|
56
|
+
sortText: String(value).padStart(8, '0'),
|
|
57
|
+
filterText: name,
|
|
58
|
+
insertText: name,
|
|
59
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
60
|
+
generatedCSS: css.generateCSS([
|
|
61
|
+
syntax + name
|
|
62
|
+
], css$1),
|
|
63
|
+
docs: 'queries'
|
|
64
|
+
}),
|
|
65
|
+
detail: `screen width ${'>='} ${value}px`,
|
|
66
|
+
kind: vscodeLanguageserverProtocol.CompletionItemKind.Keyword
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
completionItems.push({
|
|
70
|
+
...completionItem,
|
|
71
|
+
label: triggerCharacter + name,
|
|
72
|
+
detail: value,
|
|
73
|
+
sortText: name,
|
|
74
|
+
kind: vscodeLanguageserverProtocol.CompletionItemKind.Keyword
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else if (css.QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
78
|
+
if (typeof value === 'number') {
|
|
79
|
+
const prevComparisonCharacter = syntax.charAt(syntax.length - 2);
|
|
80
|
+
const comparisonCharacter = prevComparisonCharacter === '>' || prevComparisonCharacter === '<' ? prevComparisonCharacter + triggerCharacter : triggerCharacter;
|
|
81
|
+
completionItems.push({
|
|
82
|
+
...completionItem,
|
|
83
|
+
label: comparisonCharacter + name,
|
|
84
|
+
sortText: comparisonCharacter + String(value).padStart(8, '0'),
|
|
85
|
+
filterText: name,
|
|
86
|
+
insertText: name,
|
|
87
|
+
documentation: getCssDataDocumentation.getCSSDataDocumentation(undefined, {
|
|
88
|
+
generatedCSS: css.generateCSS([
|
|
89
|
+
syntax + name
|
|
90
|
+
], css$1),
|
|
91
|
+
docs: 'queries'
|
|
92
|
+
}),
|
|
93
|
+
detail: `screen width ${comparisonCharacter} ${value}px`,
|
|
94
|
+
kind: vscodeLanguageserverProtocol.CompletionItemKind.Keyword
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return sortCompletionItems(completionItems);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = getQueryCompletionItems;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { QUERY_COMPARISON_OPERATORS, generateCSS, AT_SIGN, QUERY_LOGICAL_OPERATORS, MasterCSS } from '@master/css';
|
|
2
|
+
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
3
|
+
import sortCompletionItems from './sort-completion-items.mjs';
|
|
4
|
+
import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
|
|
5
|
+
import cssDataProvider from './css-data-provider.mjs';
|
|
6
|
+
|
|
7
|
+
function getQueryCompletionItems(css = new MasterCSS(), triggerCharacter = AT_SIGN, syntax) {
|
|
8
|
+
const atDataList = cssDataProvider.provideAtDirectives();
|
|
9
|
+
const completionItems = [];
|
|
10
|
+
if (!QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
11
|
+
completionItems.push({
|
|
12
|
+
label: triggerCharacter + 'media()',
|
|
13
|
+
filterText: 'media()',
|
|
14
|
+
insertText: 'media()',
|
|
15
|
+
sortText: 'media()',
|
|
16
|
+
documentation: getCSSDataDocumentation(atDataList.find(({ name })=>name === '@media'), {
|
|
17
|
+
generatedCSS: generateCSS([
|
|
18
|
+
syntax + 'media()'
|
|
19
|
+
], css),
|
|
20
|
+
docs: 'queries'
|
|
21
|
+
})
|
|
22
|
+
}, {
|
|
23
|
+
label: triggerCharacter + 'supports()',
|
|
24
|
+
filterText: 'supports()',
|
|
25
|
+
insertText: 'supports()',
|
|
26
|
+
sortText: 'supports()',
|
|
27
|
+
documentation: getCSSDataDocumentation(atDataList.find(({ name })=>name === '@supports'), {
|
|
28
|
+
generatedCSS: generateCSS([
|
|
29
|
+
syntax + 'supports()'
|
|
30
|
+
], css),
|
|
31
|
+
docs: 'queries'
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
Object.entries(css.queries).forEach(([name, value])=>{
|
|
36
|
+
const completionItem = {
|
|
37
|
+
filterText: name,
|
|
38
|
+
insertText: name,
|
|
39
|
+
documentation: getCSSDataDocumentation(undefined, {
|
|
40
|
+
generatedCSS: generateCSS([
|
|
41
|
+
syntax + name
|
|
42
|
+
], css),
|
|
43
|
+
docs: 'queries'
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
if ([
|
|
47
|
+
AT_SIGN,
|
|
48
|
+
...QUERY_LOGICAL_OPERATORS
|
|
49
|
+
].includes(triggerCharacter)) {
|
|
50
|
+
if (typeof value === 'number') {
|
|
51
|
+
completionItems.push({
|
|
52
|
+
...completionItem,
|
|
53
|
+
label: triggerCharacter + name,
|
|
54
|
+
sortText: String(value).padStart(8, '0'),
|
|
55
|
+
filterText: name,
|
|
56
|
+
insertText: name,
|
|
57
|
+
documentation: getCSSDataDocumentation(undefined, {
|
|
58
|
+
generatedCSS: generateCSS([
|
|
59
|
+
syntax + name
|
|
60
|
+
], css),
|
|
61
|
+
docs: 'queries'
|
|
62
|
+
}),
|
|
63
|
+
detail: `screen width ${'>='} ${value}px`,
|
|
64
|
+
kind: CompletionItemKind.Keyword
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
completionItems.push({
|
|
68
|
+
...completionItem,
|
|
69
|
+
label: triggerCharacter + name,
|
|
70
|
+
detail: value,
|
|
71
|
+
sortText: name,
|
|
72
|
+
kind: CompletionItemKind.Keyword
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} else if (QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
|
|
76
|
+
if (typeof value === 'number') {
|
|
77
|
+
const prevComparisonCharacter = syntax.charAt(syntax.length - 2);
|
|
78
|
+
const comparisonCharacter = prevComparisonCharacter === '>' || prevComparisonCharacter === '<' ? prevComparisonCharacter + triggerCharacter : triggerCharacter;
|
|
79
|
+
completionItems.push({
|
|
80
|
+
...completionItem,
|
|
81
|
+
label: comparisonCharacter + name,
|
|
82
|
+
sortText: comparisonCharacter + String(value).padStart(8, '0'),
|
|
83
|
+
filterText: name,
|
|
84
|
+
insertText: name,
|
|
85
|
+
documentation: getCSSDataDocumentation(undefined, {
|
|
86
|
+
generatedCSS: generateCSS([
|
|
87
|
+
syntax + name
|
|
88
|
+
], css),
|
|
89
|
+
docs: 'queries'
|
|
90
|
+
}),
|
|
91
|
+
detail: `screen width ${comparisonCharacter} ${value}px`,
|
|
92
|
+
kind: CompletionItemKind.Keyword
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return sortCompletionItems(completionItems);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { getQueryCompletionItems as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// todo: unstable range calculation
|
|
4
|
+
function getRange(searchString, doc) {
|
|
5
|
+
const text = doc.getText();
|
|
6
|
+
const regex = new RegExp(`(\\b(?:className|class)\\s?=\\s?(['"\`]))(.*?)\\2`, 'g');
|
|
7
|
+
const classAttMatch = regex.exec(text);
|
|
8
|
+
if (classAttMatch) {
|
|
9
|
+
const attrIndex = classAttMatch.index + classAttMatch[1].length;
|
|
10
|
+
const className = classAttMatch[3];
|
|
11
|
+
const index = className.indexOf(searchString);
|
|
12
|
+
return {
|
|
13
|
+
start: doc.positionAt(attrIndex + index),
|
|
14
|
+
end: doc.positionAt(attrIndex + index + searchString.length)
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error(`Cannot find ${searchString} in ${text}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = getRange;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// todo: unstable range calculation
|
|
2
|
+
function getRange(searchString, doc) {
|
|
3
|
+
const text = doc.getText();
|
|
4
|
+
const regex = new RegExp(`(\\b(?:className|class)\\s?=\\s?(['"\`]))(.*?)\\2`, 'g');
|
|
5
|
+
const classAttMatch = regex.exec(text);
|
|
6
|
+
if (classAttMatch) {
|
|
7
|
+
const attrIndex = classAttMatch.index + classAttMatch[1].length;
|
|
8
|
+
const className = classAttMatch[3];
|
|
9
|
+
const index = className.indexOf(searchString);
|
|
10
|
+
return {
|
|
11
|
+
start: doc.positionAt(attrIndex + index),
|
|
12
|
+
end: doc.positionAt(attrIndex + index + searchString.length)
|
|
13
|
+
};
|
|
14
|
+
} else {
|
|
15
|
+
throw new Error(`Cannot find ${searchString} in ${text}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { getRange as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cssDataProvider = require('./css-data-provider.cjs');
|
|
4
|
+
|
|
5
|
+
function getUtilityInfo(EachRule, css = new MasterCSS()) {
|
|
6
|
+
const nativeProperties = cssDataProvider.provideProperties();
|
|
7
|
+
const declarations = EachRule.definition.declarations;
|
|
8
|
+
const propsLength = Object.keys(declarations || {}).length;
|
|
9
|
+
const propName = Object.keys(declarations || {})[0];
|
|
10
|
+
const propValue = declarations?.[propName];
|
|
11
|
+
let data;
|
|
12
|
+
let detail;
|
|
13
|
+
/**
|
|
14
|
+
* Remaps to native CSS properties when only one property is declared
|
|
15
|
+
* */ if (propsLength === 1) {
|
|
16
|
+
const nativeCSSPropertyData = nativeProperties.find(({ name })=>name === propName);
|
|
17
|
+
data = nativeCSSPropertyData?.values?.find(({ name })=>name === propValue || name.replace(/^-(ms|moz)-/, '') === propValue);
|
|
18
|
+
if (data) {
|
|
19
|
+
detail = `${propName}: ${propValue}`;
|
|
20
|
+
} else {
|
|
21
|
+
data = nativeCSSPropertyData;
|
|
22
|
+
detail = nativeCSSPropertyData?.syntax;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
docs: data ? propName : 'utilities',
|
|
27
|
+
data,
|
|
28
|
+
detail
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = getUtilityInfo;
|