@master/css-language-service 2.0.0-rc.7 → 2.0.0-rc.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +114 -0
  2. package/dist/common.d.ts +1 -0
  3. package/dist/common.mjs +1 -0
  4. package/dist/core.d.ts +30 -0
  5. package/dist/core.mjs +114 -0
  6. package/dist/features/edit-syntax-colors.d.ts +4 -0
  7. package/dist/features/edit-syntax-colors.mjs +17 -0
  8. package/dist/features/inspect-syntax.d.ts +4 -0
  9. package/dist/features/inspect-syntax.mjs +54 -0
  10. package/dist/features/render-semantic-tokens.d.ts +5 -0
  11. package/dist/features/render-semantic-tokens.mjs +10 -0
  12. package/dist/features/render-syntax-colors.d.ts +4 -0
  13. package/dist/features/render-syntax-colors.mjs +102 -0
  14. package/dist/features/suggest-syntax.d.ts +5 -0
  15. package/dist/features/suggest-syntax.mjs +18 -0
  16. package/dist/index.d.ts +7 -5
  17. package/dist/index.mjs +7 -0
  18. package/dist/settings.d.ts +16 -9
  19. package/dist/settings.mjs +53 -0
  20. package/dist/utils/beautify-css.d.ts +1 -0
  21. package/dist/utils/beautify-css.mjs +11 -0
  22. package/dist/utils/completion-index.d.ts +38 -0
  23. package/dist/utils/completion-index.mjs +268 -0
  24. package/dist/utils/convert-color-token.d.ts +4 -0
  25. package/dist/utils/convert-color-token.mjs +55 -0
  26. package/dist/utils/create-css-markdown-documentation.d.ts +5 -0
  27. package/dist/utils/create-css-markdown-documentation.mjs +15 -0
  28. package/dist/utils/create-doc.d.ts +16 -0
  29. package/dist/utils/create-doc.mjs +21 -0
  30. package/dist/utils/get-class-completion-items.d.ts +4 -0
  31. package/dist/utils/get-class-completion-items.mjs +20 -0
  32. package/dist/utils/get-color-completion-items.d.ts +3 -0
  33. package/dist/utils/get-color-completion-items.mjs +24 -0
  34. package/dist/utils/get-position.d.ts +1 -0
  35. package/dist/utils/get-position.mjs +10 -0
  36. package/dist/utils/get-pseudo-class-completion-items.d.ts +4 -0
  37. package/dist/utils/get-pseudo-class-completion-items.mjs +68 -0
  38. package/dist/utils/get-pseudo-element-completion-items.d.ts +4 -0
  39. package/dist/utils/get-pseudo-element-completion-items.mjs +43 -0
  40. package/dist/utils/get-query-completion-items.d.ts +4 -0
  41. package/dist/utils/get-query-completion-items.mjs +77 -0
  42. package/dist/utils/get-range.d.ts +2 -0
  43. package/dist/utils/get-range.mjs +21 -0
  44. package/dist/utils/get-utility-info.d.ts +4 -0
  45. package/dist/utils/get-utility-info.mjs +19 -0
  46. package/dist/utils/get-value-completion-items.d.ts +4 -0
  47. package/dist/utils/get-value-completion-items.mjs +203 -0
  48. package/dist/utils/query-syntax-completions.d.ts +4 -0
  49. package/dist/utils/query-syntax-completions.mjs +94 -0
  50. package/dist/utils/regex.mjs +3 -0
  51. package/dist/utils/sort-completion-items.d.ts +2 -0
  52. package/dist/utils/sort-completion-items.mjs +11 -0
  53. package/package.json +1 -1
  54. package/dist/constant.d.ts +0 -33
  55. package/dist/index.bundle.js +0 -33
  56. package/dist/position-check.d.ts +0 -20
  57. package/dist/providers/color.d.ts +0 -5
  58. package/dist/providers/completion.d.ts +0 -14
  59. package/dist/providers/hover.d.ts +0 -2
  60. package/dist/settings.bundle.js +0 -1
  61. package/dist/utils/get-css-entry-markdown-description.d.ts +0 -1
  62. package/dist/utils/hex-to-rgb.d.ts +0 -2
  63. package/dist/utils/oklab-to-rgb.d.ts +0 -1
  64. package/dist/utils/oklch-to-oklab.d.ts +0 -1
  65. package/dist/utils/to-two-digit-hex.d.ts +0 -1
@@ -0,0 +1,77 @@
1
+ import { AT_SIGN, QUERY_COMPARISON_OPERATORS, generateCSS, QUERY_LOGICAL_OPERATORS, generateAt, parseAt, createDefaultCSS, getSingleAtNumberRuleNode } from '@master/css-language';
2
+ import { CompletionItemKind } from 'vscode-languageserver-protocol';
3
+ import sortCompletionItems from './sort-completion-items.mjs';
4
+ import createCSSMarkdownDocumentation from './create-css-markdown-documentation.mjs';
5
+ import { createCompletionIndex } from './completion-index.mjs';
6
+
7
+ function getQueryCompletionItems(css = createDefaultCSS(), triggerCharacter = AT_SIGN, syntax, completionIndex = createCompletionIndex(css)) {
8
+ const completionItems = [];
9
+ if (!QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
10
+ [
11
+ 'media',
12
+ 'container',
13
+ 'supports'
14
+ ].forEach((name)=>{
15
+ completionItems.push({
16
+ label: triggerCharacter + name + '()',
17
+ filterText: name + '()',
18
+ insertText: name + '()',
19
+ sortText: name + '()',
20
+ documentation: createCSSMarkdownDocumentation(generateCSS([
21
+ syntax + name + '()'
22
+ ], css))
23
+ });
24
+ });
25
+ }
26
+ const handleNumberNodes = (atRule, token)=>{
27
+ const numberNode = getSingleAtNumberRuleNode(atRule.nodes);
28
+ if (numberNode) {
29
+ const prevComparisonCharacter = syntax.charAt(syntax.length - 2);
30
+ const comparisonCharacter = prevComparisonCharacter === '>' || prevComparisonCharacter === '<' ? prevComparisonCharacter + triggerCharacter : triggerCharacter;
31
+ const text = generateAt(parseAt(comparisonCharacter + token, css));
32
+ completionItems.push({
33
+ label: comparisonCharacter + token,
34
+ sortText: CompletionItemKind.Keyword + comparisonCharacter + String(Math.round(numberNode.value)).padStart(12, '0'),
35
+ filterText: token,
36
+ insertText: token,
37
+ detail: text,
38
+ kind: CompletionItemKind.Keyword,
39
+ documentation: createCSSMarkdownDocumentation(generateCSS([
40
+ syntax + token
41
+ ], css))
42
+ });
43
+ return true;
44
+ }
45
+ };
46
+ for (const [token, atRule] of completionIndex.atRules){
47
+ const completionItem = {
48
+ filterText: token,
49
+ insertText: token,
50
+ documentation: createCSSMarkdownDocumentation(generateCSS([
51
+ syntax + token
52
+ ], css))
53
+ };
54
+ if ([
55
+ AT_SIGN,
56
+ ...QUERY_LOGICAL_OPERATORS
57
+ ].includes(triggerCharacter)) {
58
+ if (handleNumberNodes(atRule, token)) continue;
59
+ const text = generateAt(parseAt(triggerCharacter + token, css));
60
+ completionItems.push({
61
+ ...completionItem,
62
+ label: triggerCharacter + token,
63
+ detail: text,
64
+ sortText: CompletionItemKind.Keyword + token,
65
+ kind: CompletionItemKind.Keyword,
66
+ documentation: createCSSMarkdownDocumentation(generateCSS([
67
+ syntax + token
68
+ ], css))
69
+ });
70
+ } else if (QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
71
+ handleNumberNodes(atRule, token);
72
+ }
73
+ }
74
+ return sortCompletionItems(completionItems);
75
+ }
76
+
77
+ export { getQueryCompletionItems as default };
@@ -0,0 +1,2 @@
1
+ import { TextDocument, Range } from 'vscode-languageserver-textdocument';
2
+ export default function getRange(searchString: string, doc: TextDocument): Range;
@@ -0,0 +1,21 @@
1
+ function getRange(searchString, doc) {
2
+ const text = doc.getText();
3
+ const regex = new RegExp(`(\\b(?:className|class)\\s*=\\s*(['"\`]))(.*?)\\2`, 'gs');
4
+ let match;
5
+ while((match = regex.exec(text)) !== null){
6
+ match[0];
7
+ const attrStartIndex = match.index + match[1].length;
8
+ const className = match[3];
9
+ const relativeIndex = className.indexOf(searchString);
10
+ if (relativeIndex !== -1) {
11
+ const absoluteIndex = attrStartIndex + relativeIndex;
12
+ return {
13
+ start: doc.positionAt(absoluteIndex),
14
+ end: doc.positionAt(absoluteIndex + searchString.length)
15
+ };
16
+ }
17
+ }
18
+ throw new Error(`Cannot find "${searchString}" in any class attribute.`);
19
+ }
20
+
21
+ export { getRange as default };
@@ -0,0 +1,4 @@
1
+ import { type CompiledUtility } from '@master/css-language';
2
+ export default function getUtilityInfo(utility: CompiledUtility): {
3
+ detail: string | undefined;
4
+ };
@@ -0,0 +1,19 @@
1
+ import { getStaticUtilityDeclarations } from '@master/css-language';
2
+
3
+ function getUtilityInfo(utility) {
4
+ const declarations = getStaticUtilityDeclarations(utility);
5
+ const propsLength = Object.keys(declarations || {}).length;
6
+ const propName = Object.keys(declarations || {})[0];
7
+ const propValue = declarations?.[propName];
8
+ let detail;
9
+ /**
10
+ * Remaps to native CSS properties when only one property is declared
11
+ * */ if (propsLength === 1) {
12
+ detail = `${propName}: ${propValue}`;
13
+ }
14
+ return {
15
+ detail
16
+ };
17
+ }
18
+
19
+ export { getUtilityInfo as default };
@@ -0,0 +1,4 @@
1
+ import { type CompletionItem } from 'vscode-languageserver-protocol';
2
+ import { MasterCSS } from '@master/css-language';
3
+ import { type CompletionIndex } from './completion-index';
4
+ export default function getValueCompletionItems(css: MasterCSS | undefined, ruleKey: string, valuePrefix?: string, completionIndex?: CompletionIndex): CompletionItem[];
@@ -0,0 +1,203 @@
1
+ import { CompletionItemKind } from 'vscode-languageserver-protocol';
2
+ import { getMdnPropertySyntax, getMdnPropertyValueNames, generateCSS, createDefaultCSS } from '@master/css-language';
3
+ import { builtinKeyAliases } from '@master/css-engine';
4
+ import createCSSMarkdownDocumentation from './create-css-markdown-documentation.mjs';
5
+ import sortCompletionItems from './sort-completion-items.mjs';
6
+ import { createCompletionIndex } from './completion-index.mjs';
7
+
8
+ const SCOPED_VARIABLE_PRIORITY = 'aaaa';
9
+ const NATIVE_PRIORITY = 'ccccc';
10
+ const GLOBAL_VARIABLE_PRIORITY = 'zzzz';
11
+ const ANIMATION_REFERENCE_PROPERTIES = new Set([
12
+ 'animation',
13
+ 'animation-name'
14
+ ]);
15
+ function getNumericSortValue(variable, rootSize) {
16
+ if (variable.numeric) {
17
+ switch(variable.numeric.unit){
18
+ case 'rem':
19
+ return variable.numeric.value * rootSize;
20
+ case undefined:
21
+ case '':
22
+ case 'px':
23
+ return variable.numeric.value;
24
+ }
25
+ }
26
+ return typeof variable.value === 'number' ? variable.value : 0;
27
+ }
28
+ function getVariableKeyByNamespace(variableName, namespace) {
29
+ const negative = variableName.startsWith('-');
30
+ const positiveName = negative ? variableName.slice(1) : variableName;
31
+ if (positiveName !== namespace && !positiveName.startsWith(namespace + '-')) return;
32
+ const key = positiveName === namespace ? '' : positiveName.slice(namespace.length + 1);
33
+ return negative ? '-' + key : key;
34
+ }
35
+ function getValueCompletionItems(css = createDefaultCSS(), ruleKey, valuePrefix = '', completionIndex = createCompletionIndex(css)) {
36
+ const completionItems = [];
37
+ const addedLabels = new Set();
38
+ const canonicalRuleKey = builtinKeyAliases[ruleKey] || ruleKey;
39
+ const nativeUtilityKey = completionIndex.nativeUtilityKeys.get(canonicalRuleKey);
40
+ const nativeKey = nativeUtilityKey || (getMdnPropertySyntax(canonicalRuleKey) ? canonicalRuleKey : undefined);
41
+ const nativePropertyValues = getMdnPropertyValueNames(nativeKey);
42
+ const pushCompletionItem = (completionItem)=>{
43
+ completionItems.push(completionItem);
44
+ addedLabels.add(completionItem.label);
45
+ };
46
+ const generateVariableCompletionItem = (variable, { appliedValue, label, negative, scoped } = {})=>{
47
+ const nativePropertySyntax = getMdnPropertySyntax(variable.namespace) || getMdnPropertySyntax(nativeKey);
48
+ if (variable.type === 'number' && variable.name.startsWith('-') && nativePropertySyntax?.includes('absolute')) return;
49
+ const valueToken = appliedValue ?? (scoped ? variable.key : variable.name);
50
+ const documentation = createCSSMarkdownDocumentation(generateCSS([
51
+ ruleKey + ':' + valueToken
52
+ ], css));
53
+ const completionItemLabel = label ?? variable.name;
54
+ const conflicted = addedLabels.has(completionItemLabel);
55
+ const completionItem = {
56
+ label: conflicted ? 'var(--' + completionItemLabel + ')' : completionItemLabel,
57
+ kind: CompletionItemKind.Value
58
+ };
59
+ if (conflicted) {
60
+ completionItem.documentation = createCSSMarkdownDocumentation(generateCSS([
61
+ ruleKey + ':' + completionItem.label
62
+ ], css));
63
+ } else {
64
+ completionItem.documentation = createCSSMarkdownDocumentation(generateCSS([
65
+ ruleKey + ':' + valueToken
66
+ ], css));
67
+ }
68
+ if (variable.namespace?.startsWith('color')) {
69
+ if (Object.keys(variable.modes || {}).length) {
70
+ completionItem.kind = CompletionItemKind.Color;
71
+ completionItem.detail = variable.name;
72
+ } else {
73
+ // todo: packages/core should support getTextByVariable(variable)
74
+ const configKey = 'variables.' + (variable.namespace ? variable.namespace + '.' + variable.key : variable.name);
75
+ const valueToken = variable.value ?? variable.name;
76
+ // detail is shown in the detail pane
77
+ // todo: variable.token should be recorded as original config variable
78
+ completionItem.detail = String(configKey);
79
+ completionItem.documentation = {
80
+ kind: 'markdown',
81
+ value: valueToken + '\n\n' + documentation?.value
82
+ };
83
+ completionItem.kind = CompletionItemKind.Color;
84
+ completionItem.sortText = 'color-' + variable.name.replace(/(.+?)-(\d+)/, (match, prefix, num)=>prefix + num.padStart(10, '0'));
85
+ }
86
+ } else if (variable.type === 'number') {
87
+ completionItem.detail = String(variable.name);
88
+ const value = getNumericSortValue(variable, css.settings.rootSize);
89
+ const sortValue = negative ? -Math.abs(value) : value;
90
+ completionItem.sortText = (variable.namespace || '') + (sortValue >= 0 ? String(sortValue).padStart(10, '0') : '-' + String(Math.abs(sortValue)).padStart(10, '0'));
91
+ } else {
92
+ completionItem.detail = String(variable.value || variable.name);
93
+ }
94
+ return completionItem;
95
+ };
96
+ const addScopedVariableCompletionItem = (variable, variableName)=>{
97
+ if (addedLabels.has(variableName)) return;
98
+ const completionItem = generateVariableCompletionItem(variable, {
99
+ scoped: true
100
+ });
101
+ if (completionItem) {
102
+ completionItem.label = variableName;
103
+ completionItem.sortText = SCOPED_VARIABLE_PRIORITY + (completionItem.sortText || variableName);
104
+ completionItem.detail = '(scope) ' + completionItem.detail;
105
+ pushCompletionItem(completionItem);
106
+ }
107
+ const negativeVariableName = '-' + variableName;
108
+ if (valuePrefix.startsWith('-') && variableName[0] !== '-' && variable.type === 'number' && !addedLabels.has(negativeVariableName)) {
109
+ const negativeCompletionItem = generateVariableCompletionItem(variable, {
110
+ appliedValue: negativeVariableName,
111
+ label: negativeVariableName,
112
+ negative: true,
113
+ scoped: true
114
+ });
115
+ if (negativeCompletionItem) {
116
+ negativeCompletionItem.sortText = SCOPED_VARIABLE_PRIORITY + (negativeCompletionItem.sortText || negativeVariableName);
117
+ negativeCompletionItem.detail = '(scope) ' + negativeCompletionItem.detail;
118
+ pushCompletionItem(negativeCompletionItem);
119
+ }
120
+ }
121
+ };
122
+ /**
123
+ * Scoped variables
124
+ * @example box: + content -> box-sizing:content
125
+ */ for (const { name, variable } of completionIndex.scopedVariablesByKey.get(canonicalRuleKey) || []){
126
+ addScopedVariableCompletionItem(variable, name);
127
+ }
128
+ for (const { value } of completionIndex.patternValuesByKey.get(canonicalRuleKey) || []){
129
+ if (addedLabels.has(value)) continue;
130
+ pushCompletionItem({
131
+ label: value,
132
+ kind: CompletionItemKind.Value,
133
+ documentation: createCSSMarkdownDocumentation(generateCSS([
134
+ ruleKey + ':' + value
135
+ ], css)),
136
+ detail: canonicalRuleKey + ': ' + value
137
+ });
138
+ }
139
+ /**
140
+ * @example animation:fade|fast animate:fade animation-name:fade
141
+ */ for (const animationUtility of completionIndex.animationUtilitiesByKey.get(canonicalRuleKey) || []){
142
+ css.animations.forEach((_, animationName)=>{
143
+ pushCompletionItem({
144
+ label: animationName,
145
+ kind: CompletionItemKind.Value,
146
+ documentation: createCSSMarkdownDocumentation(generateCSS([
147
+ ruleKey + ':' + animationName
148
+ ], css)),
149
+ detail: animationUtility.detailPrefix ? animationUtility.detailPrefix + ': ' + animationName : animationName
150
+ });
151
+ });
152
+ }
153
+ if (ANIMATION_REFERENCE_PROPERTIES.has(canonicalRuleKey)) {
154
+ css.animations.forEach((_, animationName)=>{
155
+ if (addedLabels.has(animationName)) return;
156
+ pushCompletionItem({
157
+ label: animationName,
158
+ kind: CompletionItemKind.Value,
159
+ documentation: createCSSMarkdownDocumentation(generateCSS([
160
+ ruleKey + ':' + animationName
161
+ ], css)),
162
+ detail: canonicalRuleKey + ': ' + animationName
163
+ });
164
+ });
165
+ }
166
+ const usedKeys = new Set();
167
+ for (const variableNamespace of completionIndex.nativeVariableNamespacesByProperty.get(canonicalRuleKey) || []){
168
+ for (const variable of completionIndex.variables){
169
+ const variableName = getVariableKeyByNamespace(variable.name, variableNamespace);
170
+ if (variableName === undefined || usedKeys.has(variableName)) continue;
171
+ usedKeys.add(variableName);
172
+ addScopedVariableCompletionItem(variable, variableName);
173
+ }
174
+ }
175
+ /**
176
+ * Native values
177
+ */ if (nativeKey) {
178
+ nativePropertyValues.forEach((value)=>{
179
+ if (addedLabels.has(value) || nativeKey === 'font' && typeof +value === 'number' || value.includes(' ')) return;
180
+ pushCompletionItem({
181
+ label: value,
182
+ kind: CompletionItemKind.Value,
183
+ sortText: NATIVE_PRIORITY + (value.startsWith('-') ? 'zz' + value.slice(1) : value),
184
+ documentation: createCSSMarkdownDocumentation(generateCSS([
185
+ ruleKey + ':' + value
186
+ ], css)),
187
+ detail: nativeKey + ': ' + value
188
+ });
189
+ });
190
+ }
191
+ // global variables
192
+ completionIndex.variables.forEach((variable)=>{
193
+ const completionItem = generateVariableCompletionItem(variable);
194
+ if (completionItem) {
195
+ completionItem.sortText = GLOBAL_VARIABLE_PRIORITY + (completionItem.sortText || completionItem.label);
196
+ completionItem.detail = '(global) ' + completionItem.detail;
197
+ pushCompletionItem(completionItem);
198
+ }
199
+ });
200
+ return sortCompletionItems(completionItems);
201
+ }
202
+
203
+ export { getValueCompletionItems as default };
@@ -0,0 +1,4 @@
1
+ import { type CompletionItem } from 'vscode-languageserver-protocol';
2
+ import { MasterCSS } from '@master/css-language';
3
+ import { type CompletionIndex } from './completion-index';
4
+ export default function querySyntaxCompletions(q?: string, css?: MasterCSS, completionIndex?: CompletionIndex): CompletionItem[] | undefined;
@@ -0,0 +1,94 @@
1
+ import { CompletionItemKind } from 'vscode-languageserver-protocol';
2
+ import getPseudoClassCompletionItems from './get-pseudo-class-completion-items.mjs';
3
+ import getPseudoElementCompletionItems from './get-pseudo-element-completion-items.mjs';
4
+ import { GROUP_TRIGGER_CHARACTER, AT_SIGN, SELECTOR_SIGNS, QUERY_COMPARISON_OPERATORS, QUERY_LOGICAL_OPERATORS, SELECTOR_TRIGGER_CHARACTERS, generateCSS, createDefaultCSS } from '@master/css-language';
5
+ import getClassCompletionItems from './get-class-completion-items.mjs';
6
+ import getValueCompletionItems from './get-value-completion-items.mjs';
7
+ import getQueryCompletionItems from './get-query-completion-items.mjs';
8
+ import createCSSMarkdownDocumentation from './create-css-markdown-documentation.mjs';
9
+ import { matchesIndexedName, createCompletionIndex } from './completion-index.mjs';
10
+
11
+ function querySyntaxCompletions(q = '', css = createDefaultCSS(), completionIndex = createCompletionIndex(css)) {
12
+ const fields = q.split(' ');
13
+ let field = fields[fields.length - 1];
14
+ const triggerCharacter = q.charAt(q.length - 1);
15
+ const invoked = triggerCharacter === ' ' || field.length === 0;
16
+ if (invoked || field === GROUP_TRIGGER_CHARACTER || triggerCharacter === ';') {
17
+ return getClassCompletionItems(css, completionIndex);
18
+ }
19
+ const isGroup = field.startsWith(GROUP_TRIGGER_CHARACTER);
20
+ if (isGroup) {
21
+ const declarationSeparatorMatches = Array.from(field.matchAll(/;(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g));
22
+ if (declarationSeparatorMatches.length) {
23
+ field = field.slice(declarationSeparatorMatches[declarationSeparatorMatches.length - 1].index + 1);
24
+ } else {
25
+ field = field.slice(1);
26
+ }
27
+ }
28
+ if (field.startsWith(AT_SIGN) || field.startsWith('~')) {
29
+ return [];
30
+ }
31
+ const keyMatch = field.match(/^[^'":\s]+:/);
32
+ const atMatches = Array.from(field.matchAll(/@(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g));
33
+ const valueSeparatorMatch = field.match(/\|(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g);
34
+ const atInvoked = atMatches.findIndex(({ index })=>index !== 0) !== -1;
35
+ const firstColonIndex = keyMatch ? keyMatch[0].length - 1 : -1;
36
+ const selectorInvokedRegex = new RegExp(`[${SELECTOR_SIGNS.join('')}](?=(?:[^'"]|'[^']*'|"[^"]*")*$)`);
37
+ const key = keyMatch ? keyMatch[0].slice(0, firstColonIndex) : undefined;
38
+ const isStyle = completionIndex.componentNames.some((eachStyleName)=>matchesIndexedName(field, eachStyleName));
39
+ const isUtility = completionIndex.utilityNames.some((eachUtilityName)=>matchesIndexedName(field, eachUtilityName));
40
+ // check by utilities and components
41
+ if (!isStyle && !isUtility) {
42
+ if (key === undefined && !valueSeparatorMatch) {
43
+ return getClassCompletionItems(css, completionIndex);
44
+ }
45
+ if (!atInvoked && !selectorInvokedRegex.test(field.slice(firstColonIndex + 1))) {
46
+ if (key && firstColonIndex !== -1) {
47
+ return getValueCompletionItems(css, key, field.slice(firstColonIndex + 1), completionIndex);
48
+ }
49
+ }
50
+ }
51
+ /**
52
+ * Not support conditional btn:hover and group
53
+ */ if (isStyle || isGroup) return;
54
+ if (atInvoked && [
55
+ AT_SIGN,
56
+ ...QUERY_COMPARISON_OPERATORS,
57
+ ...QUERY_LOGICAL_OPERATORS
58
+ ].includes(triggerCharacter)) {
59
+ return getQueryCompletionItems(css, triggerCharacter, field, completionIndex);
60
+ }
61
+ if (!atInvoked && SELECTOR_TRIGGER_CHARACTERS.includes(triggerCharacter)) {
62
+ const pseudoElementCompletionItems = getPseudoElementCompletionItems(css, field, completionIndex);
63
+ if (field.endsWith('::')) {
64
+ /**
65
+ * Consider trigger characters and fix insertText.
66
+ * @incorrect class="text-center::" -> class="text-center::::after"
67
+ * @correct class="text-center::" -> class="text-center::after"
68
+ */ pseudoElementCompletionItems.forEach((completionItem)=>completionItem.insertText = completionItem.label.slice(2));
69
+ return pseudoElementCompletionItems;
70
+ } else {
71
+ const completionItems = getPseudoClassCompletionItems(css, field, completionIndex);
72
+ completionItems.push(...pseudoElementCompletionItems);
73
+ /**
74
+ * Consider trigger characters and fix insertText.
75
+ * @incorrect class="text-center:" -> class="text-center::active"
76
+ * @correct class="text-center:" -> class="text-center:active"
77
+ */ if (triggerCharacter === ':') {
78
+ completionItems.forEach((completionItem)=>completionItem.insertText = completionItem.label.slice(1));
79
+ } else {
80
+ completionItems.push({
81
+ label: '.<class>',
82
+ insertText: '.',
83
+ documentation: createCSSMarkdownDocumentation(generateCSS([
84
+ field + '.class'
85
+ ], css)),
86
+ kind: CompletionItemKind.Class
87
+ });
88
+ }
89
+ return completionItems;
90
+ }
91
+ }
92
+ }
93
+
94
+ export { querySyntaxCompletions as default };
@@ -0,0 +1,3 @@
1
+ const instancePattern = /[^\s:]+:\w*\(?((?<!\\)["'`])((?:\\\1|(?:(?!\1))\S)*)((?<!\\)\1)\)?|[^\s"'`]+/g;
2
+
3
+ export { instancePattern };
@@ -0,0 +1,2 @@
1
+ import type { CompletionItem } from 'vscode-languageserver-protocol';
2
+ export default function sortCompletionItems(items: CompletionItem[]): CompletionItem[];
@@ -0,0 +1,11 @@
1
+ /* localeCompare equals to the real vscode completion items sorting */ function sortCompletionItems(items) {
2
+ return items.sort((a, b)=>{
3
+ const sortTextA = a.sortText || a.label;
4
+ const sortTextB = b.sortText || b.label;
5
+ return sortTextA.localeCompare(sortTextB, undefined, {
6
+ numeric: true
7
+ });
8
+ });
9
+ }
10
+
11
+ export { sortCompletionItems as default };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@master/css-language-service","scripts":{"build":"techor pack --platform node --declare","dev":"pnpm run build --watch","type-check":"tsc --noEmit","lint":"eslint src"},"description":"Master CSS Language Service","author":"Aoyue Design LLC.","license":"MIT","dependencies":{"@babel/parser":"^7.22.7","@master/css":"^2.0.0-rc.7","color-convert":"^2.0.1","js-beautify":"^1.14.7"},"devDependencies":{"@types/color-convert":"^2.0.0","vscode-css-languageservice":"^6.2.5","vscode-languageserver-types":"^3.17.3"},"main":"./dist/index.bundle.js","types":"./dist/index.d.ts","exports":{".":"./dist/index.bundle.js","./settings":"./dist/settings.bundle.js"},"typesVersions":{"*":{"./":["./dist/index.d.ts"],"./settings":["./dist/settings.d.ts"]}},"files":["dist"],"publishConfig":{"access":"public"},"version":"2.0.0-rc.7"}
1
+ {"name":"@master/css-language-service","type":"module","scripts":{"build":"techor build \"src/**/*.ts\" --formats esm","dev":"pnpm build --watch","type-check":"tsc --noEmit","lint":"eslint","test":"vitest"},"description":"Master CSS Language Service","author":"Aoyue Design LLC.","license":"MIT","repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/language-service"},"dependencies":{"@master/css":"^2.0.0-rc.71","@master/css-engine":"^2.0.0-rc.71","@master/css-language":"^2.0.0-rc.71","@techor/extend":"^3.2.5","colorjs.io":"^0.6.1","js-beautify":"^1.15.4","minimatch":"^10.2.5","vscode-languageserver-protocol":"^3.18.0","vscode-languageserver-textdocument":"^1.0.12"},"devDependencies":{"@types/vscode":"^1.125.0","vscode-languageserver":"^10.0.0","@master/css-schema":"^2.0.0-rc.71"},"sideEffects":false,"main":"./dist/index.mjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./common":{"types":"./dist/common.d.ts","import":"./dist/common.mjs","default":"./dist/common.mjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.71"}
@@ -1,33 +0,0 @@
1
- import type { CompletionItem } from 'vscode-languageserver-types';
2
- interface MasterCssKey {
3
- key: string[];
4
- colored: boolean;
5
- values: Array<string | CompletionItem>;
6
- }
7
- export declare const masterCssSelectors: (string | {
8
- label: string;
9
- kind: number;
10
- })[];
11
- export declare const masterCssElements: (string | {
12
- label: string;
13
- kind: number;
14
- })[];
15
- export declare const masterCssMedia: (string | {
16
- label: string;
17
- kind: number;
18
- })[];
19
- export declare const masterCssOtherKeys: string[];
20
- export declare const masterCssCommonValues: (string | {
21
- label: string;
22
- kind: number;
23
- })[];
24
- export declare const commonUnit: any;
25
- export declare const masterCssKeyValues: MasterCssKey[];
26
- export declare const masterCssType: {
27
- type: string;
28
- values: (string | {
29
- label: string;
30
- kind: number;
31
- })[];
32
- }[];
33
- export {};