@master/css-language-service 2.0.0-rc.6 → 2.0.0-rc.61
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 +63 -0
- package/dist/common.cjs +57 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.mjs +48 -0
- package/dist/core.cjs +246 -0
- package/dist/core.d.ts +29 -0
- package/dist/core.mjs +244 -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 +19 -9
- 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 +29 -0
- package/dist/utils/get-color-completion-items.d.ts +3 -0
- package/dist/utils/get-color-completion-items.mjs +27 -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 +106 -0
- package/dist/utils/get-main-completion-items.d.ts +3 -0
- package/dist/utils/get-main-completion-items.mjs +104 -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 +184 -0
- package/dist/utils/get-value-completion-items.d.ts +3 -0
- package/dist/utils/get-value-completion-items.mjs +182 -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
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<br>
|
|
2
|
+
<div align="center">
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://css.master.co">
|
|
6
|
+
<picture>
|
|
7
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/33840671/201701649-3bb7d698-abec-4d5f-ac30-ccc4d7bafcd4.svg">
|
|
8
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg">
|
|
9
|
+
<img alt="Master CSS" src="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg" width="100%">
|
|
10
|
+
</picture>
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
<p align="center">Language Service for Master CSS</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
|
|
17
|
+
<picture>
|
|
18
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff">
|
|
19
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000">
|
|
20
|
+
<img alt="NPM Version" src="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github">
|
|
21
|
+
</picture>
|
|
22
|
+
</a>
|
|
23
|
+
<a aria-label="NPM Package" href="https://www.npmjs.com/package/@master/css-language-service">
|
|
24
|
+
<picture>
|
|
25
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-language-service?color=212022&label=%20&logo=npm&style=for-the-badge">
|
|
26
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/@master/css-language-service?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
27
|
+
<img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/@master/css-language-service?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
28
|
+
</picture>
|
|
29
|
+
</a>
|
|
30
|
+
<a aria-label="JSDelivr" href="https://www.jsdelivr.com/package/npm/@master/css-language-service">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/jsdelivr/npm/hm/@master/css-language-service?color=212022&label=%20&logo=jsdelivr&style=for-the-badge">
|
|
33
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/jsdelivr/npm/hm/@master/css-language-service?color=f6f7f8&label=%20&logo=jsdelivr&style=for-the-badge">
|
|
34
|
+
<img alt="JSDelivr hits (npm scoped)" src="https://img.shields.io/jsdelivr/npm/hm/@master/css-language-service?color=f6f7f8&label=%20&logo=jsdelivr&style=for-the-badge">
|
|
35
|
+
</picture>
|
|
36
|
+
</a>
|
|
37
|
+
<a aria-label="Discord Community" href="https://discord.gg/sZNKpAAAw6">
|
|
38
|
+
<picture>
|
|
39
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/discord/917780624314613760?color=212022&label=%20&logo=discord&style=for-the-badge">
|
|
40
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
41
|
+
<img alt="Discord online" src="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
42
|
+
</picture>
|
|
43
|
+
</a>
|
|
44
|
+
<a aria-label="Follow @mastercorg" href="https://twitter.com/mastercorg">
|
|
45
|
+
<picture>
|
|
46
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge">
|
|
47
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
48
|
+
<img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
49
|
+
</picture>
|
|
50
|
+
</a>
|
|
51
|
+
<a aria-label="Github Actions" href="https://github.com/master-co/css/actions/workflows/release.yml">
|
|
52
|
+
<picture>
|
|
53
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
|
|
54
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
55
|
+
<img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
56
|
+
</picture>
|
|
57
|
+
</a>
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
Check out the official [documentation](https://rc.css.master.co/reference/language-service).
|
package/dist/common.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
4
|
+
var css = require('@master/css');
|
|
5
|
+
|
|
6
|
+
const INVOKED_TRIGGER_CHARACTERS = [
|
|
7
|
+
'"',
|
|
8
|
+
' ',
|
|
9
|
+
'\''
|
|
10
|
+
];
|
|
11
|
+
const VALUE_TRIGGER_CHARACTERS = [
|
|
12
|
+
css.SEPARATOR_SIGN,
|
|
13
|
+
css.DELIMITER_SIGN
|
|
14
|
+
];
|
|
15
|
+
const SELECTOR_TRIGGER_CHARACTERS = css.SELECTOR_SIGNS;
|
|
16
|
+
const AT_TRIGGER_CHARACTER = css.AT_SIGN;
|
|
17
|
+
const QUERY_TRIGGER_CHARACTERS = [
|
|
18
|
+
...css.QUERY_COMPARISON_OPERATORS,
|
|
19
|
+
...css.QUERY_LOGICAL_OPERATORS
|
|
20
|
+
];
|
|
21
|
+
const GROUP_TRIGGER_CHARACTER = '{';
|
|
22
|
+
const DECLARATION_SEPARATOR_TRIGGER_CHARACTER = ';';
|
|
23
|
+
const SERVER_CAPABILITIES = {
|
|
24
|
+
textDocumentSync: vscodeLanguageserverProtocol.TextDocumentSyncKind.Incremental,
|
|
25
|
+
// Tell the client that this server supports code completion.
|
|
26
|
+
completionProvider: {
|
|
27
|
+
resolveProvider: false,
|
|
28
|
+
workDoneProgress: false,
|
|
29
|
+
triggerCharacters: [
|
|
30
|
+
...new Set([
|
|
31
|
+
...INVOKED_TRIGGER_CHARACTERS,
|
|
32
|
+
...VALUE_TRIGGER_CHARACTERS,
|
|
33
|
+
...SELECTOR_TRIGGER_CHARACTERS,
|
|
34
|
+
...QUERY_TRIGGER_CHARACTERS,
|
|
35
|
+
DECLARATION_SEPARATOR_TRIGGER_CHARACTER,
|
|
36
|
+
AT_TRIGGER_CHARACTER,
|
|
37
|
+
GROUP_TRIGGER_CHARACTER
|
|
38
|
+
])
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
colorProvider: true,
|
|
42
|
+
hoverProvider: true,
|
|
43
|
+
workspace: {
|
|
44
|
+
workspaceFolders: {
|
|
45
|
+
supported: true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
exports.AT_TRIGGER_CHARACTER = AT_TRIGGER_CHARACTER;
|
|
51
|
+
exports.DECLARATION_SEPARATOR_TRIGGER_CHARACTER = DECLARATION_SEPARATOR_TRIGGER_CHARACTER;
|
|
52
|
+
exports.GROUP_TRIGGER_CHARACTER = GROUP_TRIGGER_CHARACTER;
|
|
53
|
+
exports.INVOKED_TRIGGER_CHARACTERS = INVOKED_TRIGGER_CHARACTERS;
|
|
54
|
+
exports.QUERY_TRIGGER_CHARACTERS = QUERY_TRIGGER_CHARACTERS;
|
|
55
|
+
exports.SELECTOR_TRIGGER_CHARACTERS = SELECTOR_TRIGGER_CHARACTERS;
|
|
56
|
+
exports.SERVER_CAPABILITIES = SERVER_CAPABILITIES;
|
|
57
|
+
exports.VALUE_TRIGGER_CHARACTERS = VALUE_TRIGGER_CHARACTERS;
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ServerCapabilities } from 'vscode-languageserver-protocol';
|
|
2
|
+
export declare const INVOKED_TRIGGER_CHARACTERS: string[];
|
|
3
|
+
export declare const VALUE_TRIGGER_CHARACTERS: string[];
|
|
4
|
+
export declare const SELECTOR_TRIGGER_CHARACTERS: string[];
|
|
5
|
+
export declare const AT_TRIGGER_CHARACTER = "@";
|
|
6
|
+
export declare const QUERY_TRIGGER_CHARACTERS: string[];
|
|
7
|
+
export declare const GROUP_TRIGGER_CHARACTER = "{";
|
|
8
|
+
export declare const DECLARATION_SEPARATOR_TRIGGER_CHARACTER = ";";
|
|
9
|
+
export declare const SERVER_CAPABILITIES: ServerCapabilities;
|
package/dist/common.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TextDocumentSyncKind } from 'vscode-languageserver-protocol';
|
|
2
|
+
import { QUERY_COMPARISON_OPERATORS, QUERY_LOGICAL_OPERATORS, SEPARATOR_SIGN, DELIMITER_SIGN, SELECTOR_SIGNS, AT_SIGN } from '@master/css';
|
|
3
|
+
|
|
4
|
+
const INVOKED_TRIGGER_CHARACTERS = [
|
|
5
|
+
'"',
|
|
6
|
+
' ',
|
|
7
|
+
'\''
|
|
8
|
+
];
|
|
9
|
+
const VALUE_TRIGGER_CHARACTERS = [
|
|
10
|
+
SEPARATOR_SIGN,
|
|
11
|
+
DELIMITER_SIGN
|
|
12
|
+
];
|
|
13
|
+
const SELECTOR_TRIGGER_CHARACTERS = SELECTOR_SIGNS;
|
|
14
|
+
const AT_TRIGGER_CHARACTER = AT_SIGN;
|
|
15
|
+
const QUERY_TRIGGER_CHARACTERS = [
|
|
16
|
+
...QUERY_COMPARISON_OPERATORS,
|
|
17
|
+
...QUERY_LOGICAL_OPERATORS
|
|
18
|
+
];
|
|
19
|
+
const GROUP_TRIGGER_CHARACTER = '{';
|
|
20
|
+
const DECLARATION_SEPARATOR_TRIGGER_CHARACTER = ';';
|
|
21
|
+
const SERVER_CAPABILITIES = {
|
|
22
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
23
|
+
// Tell the client that this server supports code completion.
|
|
24
|
+
completionProvider: {
|
|
25
|
+
resolveProvider: false,
|
|
26
|
+
workDoneProgress: false,
|
|
27
|
+
triggerCharacters: [
|
|
28
|
+
...new Set([
|
|
29
|
+
...INVOKED_TRIGGER_CHARACTERS,
|
|
30
|
+
...VALUE_TRIGGER_CHARACTERS,
|
|
31
|
+
...SELECTOR_TRIGGER_CHARACTERS,
|
|
32
|
+
...QUERY_TRIGGER_CHARACTERS,
|
|
33
|
+
DECLARATION_SEPARATOR_TRIGGER_CHARACTER,
|
|
34
|
+
AT_TRIGGER_CHARACTER,
|
|
35
|
+
GROUP_TRIGGER_CHARACTER
|
|
36
|
+
])
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
colorProvider: true,
|
|
40
|
+
hoverProvider: true,
|
|
41
|
+
workspace: {
|
|
42
|
+
workspaceFolders: {
|
|
43
|
+
supported: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { AT_TRIGGER_CHARACTER, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, SERVER_CAPABILITIES, VALUE_TRIGGER_CHARACTERS };
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var css = require('@master/css');
|
|
4
|
+
var extend = require('@techor/extend');
|
|
5
|
+
var EventEmitter = require('node:events');
|
|
6
|
+
var settings = require('./settings.cjs');
|
|
7
|
+
var minimatch = require('minimatch');
|
|
8
|
+
var inspectSyntax = require('./features/inspect-syntax.cjs');
|
|
9
|
+
var renderSyntaxColors = require('./features/render-syntax-colors.cjs');
|
|
10
|
+
var editSyntaxColors = require('./features/edit-syntax-colors.cjs');
|
|
11
|
+
var suggestSyntax = require('./features/suggest-syntax.cjs');
|
|
12
|
+
var findMatchingBrackets = require('./utils/find-matching-brackets.cjs');
|
|
13
|
+
var escapeRegexp = require('lodash.escaperegexp');
|
|
14
|
+
|
|
15
|
+
class CSSLanguageService extends EventEmitter {
|
|
16
|
+
customSettings;
|
|
17
|
+
css;
|
|
18
|
+
settings;
|
|
19
|
+
constructor(customSettings){
|
|
20
|
+
super(), this.customSettings = customSettings;
|
|
21
|
+
this.settings = extend(settings, customSettings);
|
|
22
|
+
this.css = new css.MasterCSS(this.settings.config);
|
|
23
|
+
}
|
|
24
|
+
inspectSyntax(...params) {
|
|
25
|
+
if (this.settings.inspectSyntax && this.isDocumentAccepted(params[0])) return inspectSyntax?.call(this, ...params);
|
|
26
|
+
}
|
|
27
|
+
renderSyntaxColors(...params) {
|
|
28
|
+
if (this.settings.renderSyntaxColors && this.isDocumentAccepted(params[0])) return renderSyntaxColors?.call(this, ...params);
|
|
29
|
+
}
|
|
30
|
+
editSyntaxColors(...params) {
|
|
31
|
+
if (this.settings.editSyntaxColors && this.isDocumentAccepted(params[0])) return editSyntaxColors?.call(this, ...params);
|
|
32
|
+
}
|
|
33
|
+
suggestSyntax(...params) {
|
|
34
|
+
if (this.settings.suggestSyntax && this.isDocumentAccepted(params[0])) return suggestSyntax?.call(this, ...params);
|
|
35
|
+
}
|
|
36
|
+
getClassPosition(textDocument, position) {
|
|
37
|
+
const positionIndex = textDocument.offsetAt(position);
|
|
38
|
+
const startIndex = textDocument.offsetAt({
|
|
39
|
+
line: position.line - 100,
|
|
40
|
+
character: 0
|
|
41
|
+
}) ?? 0;
|
|
42
|
+
const endIndex = textDocument.offsetAt({
|
|
43
|
+
line: position.line + 100,
|
|
44
|
+
character: 0
|
|
45
|
+
}) ?? undefined;
|
|
46
|
+
const text = textDocument.getText().substring(startIndex, endIndex);
|
|
47
|
+
const { classAttributeBindings, classAttributes, classDeclarations, classFunctions } = this.settings;
|
|
48
|
+
const normalizeClassNamePosition = (className, attrStart, escapeCharacter)=>{
|
|
49
|
+
/**
|
|
50
|
+
* Matching classes, including empty string after white space
|
|
51
|
+
* @example <div class="class-a class-b "></div>
|
|
52
|
+
* @url https://regex101.com/r/LnBLAV/1
|
|
53
|
+
*/ for (const eachClassMatch of className.matchAll(/(?:[^\s]+)?/g)){
|
|
54
|
+
if (eachClassMatch.index === undefined) continue;
|
|
55
|
+
const raw = eachClassMatch[0];
|
|
56
|
+
const classStartIndex = attrStart + eachClassMatch.index;
|
|
57
|
+
const classEndIndex = classStartIndex + raw.length;
|
|
58
|
+
if (classStartIndex <= positionIndex - startIndex && positionIndex - startIndex <= classEndIndex) {
|
|
59
|
+
return {
|
|
60
|
+
range: {
|
|
61
|
+
start: classStartIndex,
|
|
62
|
+
end: startIndex + classEndIndex
|
|
63
|
+
},
|
|
64
|
+
raw,
|
|
65
|
+
token: raw.replace(new RegExp('\\' + escapeCharacter, 'g'), escapeCharacter)
|
|
66
|
+
};
|
|
67
|
+
} else if (attrStart === classEndIndex) {
|
|
68
|
+
return {
|
|
69
|
+
range: {
|
|
70
|
+
start: attrStart,
|
|
71
|
+
end: attrStart
|
|
72
|
+
},
|
|
73
|
+
raw: '',
|
|
74
|
+
token: ''
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const resolve = (classMatchers, handle)=>{
|
|
80
|
+
for (const eachClassMatcher of classMatchers){
|
|
81
|
+
let [eachPattern, start, end] = eachClassMatcher;
|
|
82
|
+
end = end ?? start;
|
|
83
|
+
for (const eachClassPostioinMatch of text.matchAll(new RegExp(`(?:\\s|\\.)${eachPattern}${escapeRegexp(start)}`, 'g'))){
|
|
84
|
+
if (eachClassPostioinMatch.index === undefined) continue;
|
|
85
|
+
const eachClassAttributeString = eachClassPostioinMatch[0];
|
|
86
|
+
const eachAttrStart = eachClassPostioinMatch.index + eachClassAttributeString.length;
|
|
87
|
+
const eachClassPositionEnd = findMatchingBrackets(text, eachAttrStart, start, end);
|
|
88
|
+
if (!eachClassPositionEnd) continue;
|
|
89
|
+
if ((eachAttrStart <= positionIndex - startIndex && eachClassPositionEnd >= positionIndex - startIndex) === true) {
|
|
90
|
+
const classPosition = handle(eachAttrStart, eachClassPositionEnd, eachClassMatcher);
|
|
91
|
+
if (classPosition) return classPosition;
|
|
92
|
+
} else if (eachClassPostioinMatch.index > positionIndex - startIndex) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const stringExpressions = [];
|
|
99
|
+
const assignmentExpressions = [];
|
|
100
|
+
classAttributes?.forEach((eachClassAttribute)=>{
|
|
101
|
+
stringExpressions.push([
|
|
102
|
+
eachClassAttribute + '=',
|
|
103
|
+
'"',
|
|
104
|
+
'"'
|
|
105
|
+
], [
|
|
106
|
+
eachClassAttribute + '=',
|
|
107
|
+
'\'',
|
|
108
|
+
'\''
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
classDeclarations?.forEach((eachClassDeclaration)=>{
|
|
112
|
+
stringExpressions.push([
|
|
113
|
+
eachClassDeclaration + '(?:\\s+)?(?::|=)(?:\\s+)?',
|
|
114
|
+
'"',
|
|
115
|
+
'"'
|
|
116
|
+
], [
|
|
117
|
+
eachClassDeclaration + '(?:\\s+)?(?::|=)(?:\\s+)?',
|
|
118
|
+
'`',
|
|
119
|
+
'`'
|
|
120
|
+
], [
|
|
121
|
+
eachClassDeclaration + '(?:\\s+)?(?::|=)(?:\\s+)?',
|
|
122
|
+
'\'',
|
|
123
|
+
'\''
|
|
124
|
+
]);
|
|
125
|
+
assignmentExpressions.push([
|
|
126
|
+
eachClassDeclaration + '(?:\\s+)?(?::|=)(?:\\s+)?',
|
|
127
|
+
'{',
|
|
128
|
+
'}'
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
classFunctions?.forEach((eachClassFunction)=>{
|
|
132
|
+
/**
|
|
133
|
+
* @example clsx`class-a class-b`
|
|
134
|
+
*/ stringExpressions.push([
|
|
135
|
+
eachClassFunction,
|
|
136
|
+
'`',
|
|
137
|
+
'`'
|
|
138
|
+
]);
|
|
139
|
+
/**
|
|
140
|
+
* @example clsx('class-a class-b')
|
|
141
|
+
*/ assignmentExpressions.push([
|
|
142
|
+
eachClassFunction,
|
|
143
|
+
'(',
|
|
144
|
+
')'
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
/**
|
|
148
|
+
* @example <div class=""></div>
|
|
149
|
+
* */ if (stringExpressions?.length) {
|
|
150
|
+
const classPosition = resolve(stringExpressions, (eachAttrStart, eachClassPositionEnd, [eachPattern, pair])=>{
|
|
151
|
+
const eachClassName = text.substring(eachAttrStart, eachClassPositionEnd);
|
|
152
|
+
/**
|
|
153
|
+
* @example <div class=""></div>
|
|
154
|
+
*/ if (eachClassName === undefined) {
|
|
155
|
+
return {
|
|
156
|
+
range: {
|
|
157
|
+
start: eachAttrStart,
|
|
158
|
+
end: eachAttrStart
|
|
159
|
+
},
|
|
160
|
+
token: '',
|
|
161
|
+
raw: ''
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const classNameStart = eachAttrStart;
|
|
165
|
+
const classPosition = normalizeClassNamePosition(eachClassName, classNameStart, pair);
|
|
166
|
+
if (classPosition) return classPosition;
|
|
167
|
+
});
|
|
168
|
+
if (classPosition) return classPosition;
|
|
169
|
+
}
|
|
170
|
+
if (classAttributeBindings) {
|
|
171
|
+
for(const eachClassAttribute in classAttributeBindings){
|
|
172
|
+
const eachClassAttributeBinding = classAttributeBindings[eachClassAttribute];
|
|
173
|
+
if (eachClassAttributeBinding === false) continue;
|
|
174
|
+
assignmentExpressions.push([
|
|
175
|
+
eachClassAttribute + '=',
|
|
176
|
+
eachClassAttributeBinding[0],
|
|
177
|
+
eachClassAttributeBinding[1]
|
|
178
|
+
]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* attribute binding
|
|
183
|
+
* @example <div className={''}></div>
|
|
184
|
+
* @example <div :class="isActive ? 'block' : 'hidden'"></div>
|
|
185
|
+
* */ if (assignmentExpressions?.length) {
|
|
186
|
+
const classPosition = resolve(assignmentExpressions, (eachAttrStart, eachClassPositionEnd, eachClassMatcher)=>{
|
|
187
|
+
const eachClassPositionExpression = text.substring(eachAttrStart, eachClassPositionEnd);
|
|
188
|
+
/**
|
|
189
|
+
* @example <div className={""}></div>
|
|
190
|
+
*/ if ([
|
|
191
|
+
'""',
|
|
192
|
+
'\'\'',
|
|
193
|
+
'``'
|
|
194
|
+
].includes(eachClassPositionExpression)) {
|
|
195
|
+
return {
|
|
196
|
+
range: {
|
|
197
|
+
start: eachAttrStart + 1,
|
|
198
|
+
end: eachAttrStart + 1
|
|
199
|
+
},
|
|
200
|
+
raw: '',
|
|
201
|
+
token: ''
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// 1. "
|
|
205
|
+
for (const classExpressionMatch of eachClassPositionExpression.matchAll(/(?<!\\)"([\s\S]*?)(?<!\\)"/g)){
|
|
206
|
+
if (classExpressionMatch.index === undefined) continue;
|
|
207
|
+
const eachClassName = classExpressionMatch[1];
|
|
208
|
+
const classNameStart = eachAttrStart + classExpressionMatch.index + 1 // " length
|
|
209
|
+
;
|
|
210
|
+
const classPosition = normalizeClassNamePosition(eachClassName, classNameStart, '"');
|
|
211
|
+
if (classPosition) return classPosition;
|
|
212
|
+
}
|
|
213
|
+
// 2. '
|
|
214
|
+
for (const classExpressionMatch of eachClassPositionExpression.matchAll(/(?<!\\)'([\s\S]*?)(?<!\\)'/g)){
|
|
215
|
+
if (classExpressionMatch.index === undefined) continue;
|
|
216
|
+
const eachClassName = classExpressionMatch[1];
|
|
217
|
+
const classNameStart = eachAttrStart + classExpressionMatch.index + 1 // ' length
|
|
218
|
+
;
|
|
219
|
+
const classPosition = normalizeClassNamePosition(eachClassName, classNameStart, '\'');
|
|
220
|
+
if (classPosition) return classPosition;
|
|
221
|
+
}
|
|
222
|
+
// 3. `
|
|
223
|
+
for (const classExpressionMatch of eachClassPositionExpression.matchAll(/(?<!\\)`([\s\S]*?)(?<!\\)`/g)){
|
|
224
|
+
if (classExpressionMatch.index === undefined) continue;
|
|
225
|
+
const eachClassName = classExpressionMatch[1];
|
|
226
|
+
const classNameStart = eachAttrStart + classExpressionMatch.index + 1 // ` length
|
|
227
|
+
;
|
|
228
|
+
const classPosition = normalizeClassNamePosition(eachClassName, classNameStart, '`');
|
|
229
|
+
if (classPosition) return classPosition;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (classPosition) return classPosition;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
isDocumentAccepted(doc) {
|
|
236
|
+
if (!this.settings.exclude) return true;
|
|
237
|
+
for (const exclude of this.settings.exclude){
|
|
238
|
+
if (minimatch.minimatch(doc.uri, exclude)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
module.exports = CSSLanguageService;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MasterCSS } from '@master/css';
|
|
2
|
+
import EventEmitter from 'node:events';
|
|
3
|
+
import type { Position } from 'vscode-languageserver-protocol';
|
|
4
|
+
import { type Settings } from './settings';
|
|
5
|
+
import inspectSyntax from './features/inspect-syntax';
|
|
6
|
+
import renderSyntaxColors from './features/render-syntax-colors';
|
|
7
|
+
import editSyntaxColors from './features/edit-syntax-colors';
|
|
8
|
+
import suggestSyntax from './features/suggest-syntax';
|
|
9
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
10
|
+
export interface ClassPosition {
|
|
11
|
+
range: {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
};
|
|
15
|
+
raw: string;
|
|
16
|
+
token: string;
|
|
17
|
+
}
|
|
18
|
+
export default class CSSLanguageService extends EventEmitter {
|
|
19
|
+
customSettings?: Settings | undefined;
|
|
20
|
+
css: MasterCSS;
|
|
21
|
+
settings: Settings;
|
|
22
|
+
constructor(customSettings?: Settings | undefined);
|
|
23
|
+
inspectSyntax(...params: Parameters<typeof inspectSyntax>): import("vscode-languageserver-protocol").Hover | undefined;
|
|
24
|
+
renderSyntaxColors(...params: Parameters<typeof renderSyntaxColors>): Promise<import("vscode-languageserver-protocol").ColorInformation[] | undefined> | undefined;
|
|
25
|
+
editSyntaxColors(...params: Parameters<typeof editSyntaxColors>): import("vscode-languageserver-protocol").ColorPresentation[] | undefined;
|
|
26
|
+
suggestSyntax(...params: Parameters<typeof suggestSyntax>): import("vscode-languageserver-protocol").CompletionItem[] | undefined;
|
|
27
|
+
getClassPosition(textDocument: TextDocument, position: Position): ClassPosition | undefined;
|
|
28
|
+
isDocumentAccepted(doc: TextDocument): boolean;
|
|
29
|
+
}
|