@master/css-language-server 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.
- package/README.md +102 -0
- package/dist/core.d.ts +53 -0
- package/dist/core.mjs +486 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +2 -0
- package/dist/settings.d.ts +8 -0
- package/dist/settings.mjs +9 -0
- package/dist/utils/create-document.d.ts +5 -0
- package/dist/utils/create-document.mjs +28 -0
- package/package.json +1 -1
- package/dist/server.bundle.js +0 -1
- package/dist/server.d.ts +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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 Server 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-server">
|
|
24
|
+
<picture>
|
|
25
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-language-server?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-server?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-server?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-server">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/jsdelivr/npm/hm/@master/css-language-server?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-server?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-server?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/ci-release.yml">
|
|
52
|
+
<picture>
|
|
53
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-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/ci-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/ci-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
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install @master/css-language-server
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import CSSLanguageServer from '@master/css-language-server'
|
|
72
|
+
|
|
73
|
+
const languageServer = new CSSLanguageServer(connection, customSettings)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`CSSLanguageServer` wraps `@master/css-language-service` with LSP workspace lifecycle, completion, hover, document color, color presentation, and semantic token handlers.
|
|
77
|
+
|
|
78
|
+
## Semantic tokens
|
|
79
|
+
|
|
80
|
+
The language server supports full-document and active-position semantic tokens.
|
|
81
|
+
|
|
82
|
+
| `embeddedSyntaxHighlighting` | Behavior |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `always` | Advertises the standard LSP `semanticTokensProvider` and handles `textDocument/semanticTokens/full`. |
|
|
85
|
+
| `active` | Uses the VS Code extension request for active class-context highlighting. |
|
|
86
|
+
| `off` | Disables embedded utility highlighting. |
|
|
87
|
+
|
|
88
|
+
CSS directive syntax is highlighted by the shared TextMate grammar. Server semantic tokens cover Master CSS class-list spans and directive class-list spans such as `@compose` and `@safelist`.
|
|
89
|
+
|
|
90
|
+
## Settings
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { settings } from '@master/css-language-server'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| Setting | Type | Default | Description |
|
|
97
|
+
| --- | --- | --- | --- |
|
|
98
|
+
| `workspaces` | `FastGlobPattern[] \| 'auto'` | `'auto'` | Workspace roots where independent language services are created. The root workspace is always included. |
|
|
99
|
+
| `verbose` | `boolean` | `false` | Print server logs. |
|
|
100
|
+
| `embeddedSyntaxHighlighting` | `'active' \| 'always' \| 'off'` | `'active'` | Inherited language-service semantic token mode. |
|
|
101
|
+
|
|
102
|
+
With `workspaces: 'auto'`, the server creates workspaces from CSS files containing `@master;` or `@import '@master/css'`, and from `package.json` files that declare Master CSS package dependencies.
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TextDocuments, InitializeParams, InitializeResult, WorkspaceFolder, Connection, ClientCapabilities, TextDocumentChangeEvent, DidChangeConfigurationParams, HoverParams, CompletionParams, DocumentColorParams, ColorPresentationParams, RemoteConsole, SemanticTokensParams, TextDocumentPositionParams } from 'vscode-languageserver/node';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import CSSLanguageService, { Settings as CSSLanguageServiceSettings } from '@master/css-language-service';
|
|
4
|
+
import { Settings } from './settings';
|
|
5
|
+
export declare interface Workspace {
|
|
6
|
+
uri: string;
|
|
7
|
+
openedTextDocuments: TextDocument[];
|
|
8
|
+
languageService?: CSSLanguageService;
|
|
9
|
+
languageServiceSettings: CSSLanguageServiceSettings;
|
|
10
|
+
planEntries?: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const ACTIVE_SEMANTIC_TOKENS_REQUEST = "masterCSS/renderActiveSemanticTokens";
|
|
13
|
+
export declare const DOCUMENT_SEMANTIC_TOKENS_REQUEST = "masterCSS/renderDocumentSemanticTokens";
|
|
14
|
+
export default class CSSLanguageServer {
|
|
15
|
+
connection: Connection;
|
|
16
|
+
customSettings?: Settings | undefined;
|
|
17
|
+
workspaceFolders: WorkspaceFolder[];
|
|
18
|
+
workspaces: Map<string, Workspace>;
|
|
19
|
+
globalWorkspace: Workspace;
|
|
20
|
+
documents: TextDocuments<TextDocument>;
|
|
21
|
+
initializing?: Promise<void>;
|
|
22
|
+
clientCapabilities: ClientCapabilities;
|
|
23
|
+
settings?: Settings;
|
|
24
|
+
console: RemoteConsole;
|
|
25
|
+
private disposables;
|
|
26
|
+
constructor(connection?: Connection, customSettings?: Settings | undefined);
|
|
27
|
+
start(): void;
|
|
28
|
+
init(): Promise<void>;
|
|
29
|
+
onInitialize(params: InitializeParams): InitializeResult;
|
|
30
|
+
onHover(params: HoverParams): Promise<import("vscode-languageserver-protocol").Hover | undefined>;
|
|
31
|
+
onCompletion(params: CompletionParams): Promise<import("vscode-languageserver-protocol").CompletionItem[] | undefined>;
|
|
32
|
+
onDocumentColor(params: DocumentColorParams): Promise<import("vscode-languageserver-protocol").ColorInformation[]>;
|
|
33
|
+
onColorPresentation(params: ColorPresentationParams): Promise<import("vscode-languageserver-protocol").ColorPresentation[]>;
|
|
34
|
+
onSemanticTokens(params: SemanticTokensParams): Promise<import("vscode-languageserver-protocol").SemanticTokens>;
|
|
35
|
+
onDocumentSemanticTokens(params: SemanticTokensParams): Promise<import("vscode-languageserver-protocol").SemanticTokens>;
|
|
36
|
+
onActiveSemanticTokens(params: TextDocumentPositionParams): Promise<import("vscode-languageserver-protocol").SemanticTokens>;
|
|
37
|
+
onDidOpen(params: TextDocumentChangeEvent<TextDocument>): Promise<void>;
|
|
38
|
+
onDidChangeContent(params: TextDocumentChangeEvent<TextDocument>): Promise<void>;
|
|
39
|
+
onDidClose(params: TextDocumentChangeEvent<TextDocument>): Promise<void>;
|
|
40
|
+
onDidSave(params: TextDocumentChangeEvent<TextDocument>): Promise<void>;
|
|
41
|
+
onDidChangeConfiguration({ settings: changedSettings }: DidChangeConfigurationParams): Promise<void>;
|
|
42
|
+
private initWorkspaceFolder;
|
|
43
|
+
initWorkspaceLanguageService(workspace: Workspace): Promise<void>;
|
|
44
|
+
private loadWorkspacePlan;
|
|
45
|
+
destroyLanguageService(workspace: Workspace): void;
|
|
46
|
+
findClosestWorkspace(textDocumentURI: string): Workspace;
|
|
47
|
+
private publishCSSDirectiveDiagnostics;
|
|
48
|
+
private createCSSDirectiveDiagnostic;
|
|
49
|
+
private createCSSDirectiveRelatedInformation;
|
|
50
|
+
private createCSSDirectiveRange;
|
|
51
|
+
private refreshSemanticTokens;
|
|
52
|
+
stop(): void;
|
|
53
|
+
}
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { TextDocumentSyncKind, TextDocuments, createConnection, DiagnosticSeverity } from 'vscode-languageserver/node';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import CSSLanguageService from '@master/css-language-service';
|
|
5
|
+
import { compileCSSManifest } from '@master/css-compiler';
|
|
6
|
+
import { findMasterCSSWorkspaceDirectories, findCSSManifestEntryFiles } from '@master/css-project/entries';
|
|
7
|
+
import { loadProjectManifest } from '@master/css-project/manifest';
|
|
8
|
+
import extend from '@techor/extend';
|
|
9
|
+
import settings from './settings.mjs';
|
|
10
|
+
import { INVOKED_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, AT_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER } from '@master/css-language-service/common';
|
|
11
|
+
import { SEMANTIC_TOKENS_LEGEND } from '@master/css-language';
|
|
12
|
+
import glob from 'fast-glob';
|
|
13
|
+
import { URI } from 'vscode-uri';
|
|
14
|
+
import { CSSDirectiveError } from '@master/css-schema/css-directives';
|
|
15
|
+
|
|
16
|
+
const ACTIVE_SEMANTIC_TOKENS_REQUEST = 'masterCSS/renderActiveSemanticTokens';
|
|
17
|
+
const DOCUMENT_SEMANTIC_TOKENS_REQUEST = 'masterCSS/renderDocumentSemanticTokens';
|
|
18
|
+
const SERVER_CAPABILITIES = {
|
|
19
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
20
|
+
completionProvider: {
|
|
21
|
+
resolveProvider: false,
|
|
22
|
+
workDoneProgress: false,
|
|
23
|
+
triggerCharacters: [
|
|
24
|
+
...new Set([
|
|
25
|
+
...INVOKED_TRIGGER_CHARACTERS,
|
|
26
|
+
...VALUE_TRIGGER_CHARACTERS,
|
|
27
|
+
...SELECTOR_TRIGGER_CHARACTERS,
|
|
28
|
+
...QUERY_TRIGGER_CHARACTERS,
|
|
29
|
+
DECLARATION_SEPARATOR_TRIGGER_CHARACTER,
|
|
30
|
+
AT_TRIGGER_CHARACTER,
|
|
31
|
+
GROUP_TRIGGER_CHARACTER
|
|
32
|
+
])
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
colorProvider: true,
|
|
36
|
+
hoverProvider: true,
|
|
37
|
+
semanticTokensProvider: {
|
|
38
|
+
legend: SEMANTIC_TOKENS_LEGEND,
|
|
39
|
+
full: true
|
|
40
|
+
},
|
|
41
|
+
workspace: {
|
|
42
|
+
workspaceFolders: {
|
|
43
|
+
supported: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const CSS_DIAGNOSTIC_LANGUAGE_IDS = new Set([
|
|
48
|
+
'css',
|
|
49
|
+
'scss',
|
|
50
|
+
'less'
|
|
51
|
+
]);
|
|
52
|
+
const SFC_DIAGNOSTIC_LANGUAGE_IDS = new Set([
|
|
53
|
+
'vue',
|
|
54
|
+
'svelte',
|
|
55
|
+
'astro'
|
|
56
|
+
]);
|
|
57
|
+
const STYLE_BLOCK_RE = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
58
|
+
function isCSSDiagnosticDocument(textDocument) {
|
|
59
|
+
return CSS_DIAGNOSTIC_LANGUAGE_IDS.has(textDocument.languageId) || SFC_DIAGNOSTIC_LANGUAGE_IDS.has(textDocument.languageId);
|
|
60
|
+
}
|
|
61
|
+
function getSFCStyleLanguage(attributes) {
|
|
62
|
+
const match = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+))/i.exec(attributes);
|
|
63
|
+
return (match?.[1] || match?.[2] || match?.[3] || 'css').toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
function getCSSDiagnosticSources(textDocument) {
|
|
66
|
+
const text = textDocument.getText();
|
|
67
|
+
if (CSS_DIAGNOSTIC_LANGUAGE_IDS.has(textDocument.languageId)) {
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
source: text,
|
|
71
|
+
offset: 0
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
if (!SFC_DIAGNOSTIC_LANGUAGE_IDS.has(textDocument.languageId)) return [];
|
|
76
|
+
const sources = [];
|
|
77
|
+
STYLE_BLOCK_RE.lastIndex = 0;
|
|
78
|
+
for (const match of text.matchAll(STYLE_BLOCK_RE)){
|
|
79
|
+
const styleLanguage = getSFCStyleLanguage(match[1]);
|
|
80
|
+
if (!CSS_DIAGNOSTIC_LANGUAGE_IDS.has(styleLanguage)) continue;
|
|
81
|
+
const source = match[2];
|
|
82
|
+
const offset = (match.index || 0) + match[0].indexOf(source);
|
|
83
|
+
sources.push({
|
|
84
|
+
source,
|
|
85
|
+
offset
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return sources;
|
|
89
|
+
}
|
|
90
|
+
function isCSSDirectiveError(error) {
|
|
91
|
+
return error instanceof CSSDirectiveError || !!error && typeof error === 'object' && error.name === 'CSSDirectiveError' && typeof error.code === 'string';
|
|
92
|
+
}
|
|
93
|
+
function getInitializationSettings(initializationOptions) {
|
|
94
|
+
if (!initializationOptions || typeof initializationOptions !== 'object') return;
|
|
95
|
+
const options = initializationOptions;
|
|
96
|
+
return options.masterCSS ?? options;
|
|
97
|
+
}
|
|
98
|
+
function isWindowsFilePath(fsPath) {
|
|
99
|
+
return /^[a-z]:[\\/]/i.test(fsPath) || fsPath.startsWith('\\\\') || fsPath.startsWith('//');
|
|
100
|
+
}
|
|
101
|
+
function getFilePathTools(...fsPaths) {
|
|
102
|
+
return fsPaths.some(isWindowsFilePath) ? path.win32 : path;
|
|
103
|
+
}
|
|
104
|
+
function toComparableFilePath(uri) {
|
|
105
|
+
const parsedURI = URI.parse(uri);
|
|
106
|
+
if (parsedURI.scheme !== 'file') return;
|
|
107
|
+
const fsPath = parsedURI.fsPath;
|
|
108
|
+
if (!fsPath) return;
|
|
109
|
+
const filePathTools = getFilePathTools(fsPath);
|
|
110
|
+
const resolvedPath = filePathTools.resolve(fsPath);
|
|
111
|
+
return isWindowsFilePath(resolvedPath) ? resolvedPath.toLowerCase() : resolvedPath;
|
|
112
|
+
}
|
|
113
|
+
function containsFilePath(parentPath, childPath) {
|
|
114
|
+
const filePathTools = getFilePathTools(parentPath, childPath);
|
|
115
|
+
const relativePath = filePathTools.relative(parentPath, childPath);
|
|
116
|
+
return relativePath === '' || !!relativePath && relativePath !== '..' && !relativePath.startsWith(`..${filePathTools.sep}`) && !filePathTools.isAbsolute(relativePath);
|
|
117
|
+
}
|
|
118
|
+
class CSSLanguageServer {
|
|
119
|
+
connection;
|
|
120
|
+
customSettings;
|
|
121
|
+
workspaceFolders = [];
|
|
122
|
+
workspaces = new Map();
|
|
123
|
+
globalWorkspace = {
|
|
124
|
+
uri: '',
|
|
125
|
+
openedTextDocuments: [],
|
|
126
|
+
languageServiceSettings: this.settings
|
|
127
|
+
};
|
|
128
|
+
documents;
|
|
129
|
+
initializing;
|
|
130
|
+
clientCapabilities = {};
|
|
131
|
+
settings;
|
|
132
|
+
console;
|
|
133
|
+
disposables = [];
|
|
134
|
+
constructor(connection = process.argv.includes('--stdio') ? createConnection(process.stdin, process.stdout) : createConnection(), customSettings){
|
|
135
|
+
this.connection = connection;
|
|
136
|
+
this.customSettings = customSettings;
|
|
137
|
+
this.documents = new TextDocuments(TextDocument);
|
|
138
|
+
this.settings = extend(settings, this.customSettings);
|
|
139
|
+
this.globalWorkspace.languageServiceSettings = this.settings;
|
|
140
|
+
this.console = new Proxy(this.connection.console, {
|
|
141
|
+
get: (target, prop)=>{
|
|
142
|
+
if (!this.settings?.verbose) return ()=>{};
|
|
143
|
+
return this.connection.console[prop];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
start() {
|
|
148
|
+
this.disposables.push(this.documents.onDidSave(this.onDidSave.bind(this)), this.documents.onDidOpen(this.onDidOpen.bind(this)), this.documents.onDidChangeContent(this.onDidChangeContent.bind(this)), this.documents.onDidClose(this.onDidClose.bind(this)), this.documents.listen(this.connection), this.connection.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this)), this.connection.onHover(this.onHover.bind(this)), this.connection.onCompletion(this.onCompletion.bind(this)), this.connection.onDocumentColor(this.onDocumentColor.bind(this)), this.connection.onColorPresentation(this.onColorPresentation.bind(this)), this.connection.languages.semanticTokens.on(this.onSemanticTokens.bind(this)), this.connection.onRequest(DOCUMENT_SEMANTIC_TOKENS_REQUEST, this.onDocumentSemanticTokens.bind(this)), this.connection.onRequest(ACTIVE_SEMANTIC_TOKENS_REQUEST, this.onActiveSemanticTokens.bind(this)), this.connection.onInitialize(this.onInitialize.bind(this)), this.connection.onInitialized(()=>this.init()));
|
|
149
|
+
this.connection.listen();
|
|
150
|
+
}
|
|
151
|
+
init() {
|
|
152
|
+
if (this.initializing) return this.initializing;
|
|
153
|
+
return this.initializing = new Promise(async (resolve)=>{
|
|
154
|
+
await Promise.all(this.workspaceFolders.map((folder)=>this.initWorkspaceFolder(folder.uri)));
|
|
155
|
+
resolve();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
onInitialize(params) {
|
|
159
|
+
this.clientCapabilities = params.capabilities;
|
|
160
|
+
const initializationSettings = getInitializationSettings(params.initializationOptions);
|
|
161
|
+
if (initializationSettings) {
|
|
162
|
+
this.customSettings = extend(this.customSettings, initializationSettings);
|
|
163
|
+
this.settings = extend(settings, this.customSettings);
|
|
164
|
+
this.globalWorkspace.languageServiceSettings = this.settings;
|
|
165
|
+
}
|
|
166
|
+
if (params.workspaceFolders?.length) {
|
|
167
|
+
this.workspaceFolders = params.workspaceFolders;
|
|
168
|
+
}
|
|
169
|
+
const capabilities = {
|
|
170
|
+
...SERVER_CAPABILITIES
|
|
171
|
+
};
|
|
172
|
+
if (this.settings?.embeddedSyntaxHighlighting !== 'always') {
|
|
173
|
+
delete capabilities.semanticTokensProvider;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
capabilities
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async onHover(params) {
|
|
180
|
+
await this.init();
|
|
181
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
182
|
+
if (workspace?.languageService) {
|
|
183
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
184
|
+
if (document) return workspace.languageService.inspectSyntax(document, params.position);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async onCompletion(params) {
|
|
188
|
+
await this.init();
|
|
189
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
190
|
+
if (workspace?.languageService) {
|
|
191
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
192
|
+
if (document) return workspace.languageService.suggestSyntax(document, params.position, params.context);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async onDocumentColor(params) {
|
|
196
|
+
await this.init();
|
|
197
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
198
|
+
if (workspace?.languageService) {
|
|
199
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
200
|
+
if (document) return await workspace.languageService.renderSyntaxColors(document) ?? [];
|
|
201
|
+
}
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
async onColorPresentation(params) {
|
|
205
|
+
await this.init();
|
|
206
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
207
|
+
if (workspace?.languageService) {
|
|
208
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
209
|
+
if (document) return workspace.languageService.editSyntaxColors(document, params.color, params.range) ?? [];
|
|
210
|
+
}
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
async onSemanticTokens(params) {
|
|
214
|
+
await this.init();
|
|
215
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
216
|
+
if (workspace?.languageService) {
|
|
217
|
+
const document = this.documents.get(params.textDocument.uri) ?? workspace.openedTextDocuments.find((document)=>document.uri === params.textDocument.uri);
|
|
218
|
+
if (document) return workspace.languageService.renderSemanticTokens(document) ?? {
|
|
219
|
+
data: []
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
data: []
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async onDocumentSemanticTokens(params) {
|
|
227
|
+
return this.onSemanticTokens(params);
|
|
228
|
+
}
|
|
229
|
+
async onActiveSemanticTokens(params) {
|
|
230
|
+
await this.init();
|
|
231
|
+
const workspace = this.findClosestWorkspace(params.textDocument.uri);
|
|
232
|
+
if (workspace?.languageService) {
|
|
233
|
+
const document = this.documents.get(params.textDocument.uri) ?? workspace.openedTextDocuments.find((document)=>document.uri === params.textDocument.uri);
|
|
234
|
+
if (document) return workspace.languageService.renderSemanticTokensAtPosition(document, params.position) ?? {
|
|
235
|
+
data: []
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
data: []
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async onDidOpen(params) {
|
|
243
|
+
await this.init();
|
|
244
|
+
const workspace = this.findClosestWorkspace(params.document.uri);
|
|
245
|
+
if (!workspace) return;
|
|
246
|
+
if (workspace.openedTextDocuments.includes(params.document)) {
|
|
247
|
+
this.publishCSSDirectiveDiagnostics(params.document, workspace);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (!workspace.openedTextDocuments.length) {
|
|
251
|
+
await this.initWorkspaceLanguageService(workspace);
|
|
252
|
+
}
|
|
253
|
+
workspace.openedTextDocuments.push(params.document);
|
|
254
|
+
this.publishCSSDirectiveDiagnostics(params.document, workspace);
|
|
255
|
+
}
|
|
256
|
+
async onDidChangeContent(params) {
|
|
257
|
+
await this.init();
|
|
258
|
+
const workspace = this.findClosestWorkspace(params.document.uri);
|
|
259
|
+
if (!workspace) return;
|
|
260
|
+
this.publishCSSDirectiveDiagnostics(params.document, workspace);
|
|
261
|
+
}
|
|
262
|
+
async onDidClose(params) {
|
|
263
|
+
await this.init();
|
|
264
|
+
const workspace = this.findClosestWorkspace(params.document.uri);
|
|
265
|
+
if (!workspace) return;
|
|
266
|
+
workspace.openedTextDocuments.splice(workspace.openedTextDocuments.indexOf(params.document), 1);
|
|
267
|
+
this.connection.sendDiagnostics({
|
|
268
|
+
uri: params.document.uri,
|
|
269
|
+
diagnostics: []
|
|
270
|
+
});
|
|
271
|
+
if (!workspace.openedTextDocuments.length) {
|
|
272
|
+
this.destroyLanguageService(workspace);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async onDidSave(params) {
|
|
276
|
+
await this.init();
|
|
277
|
+
const workspace = this.findClosestWorkspace(params.document.uri);
|
|
278
|
+
if (!workspace) return;
|
|
279
|
+
this.publishCSSDirectiveDiagnostics(params.document, workspace);
|
|
280
|
+
const name = path.basename(URI.parse(params.document.uri).fsPath);
|
|
281
|
+
if (name.endsWith('.css')) {
|
|
282
|
+
this.refreshSemanticTokens();
|
|
283
|
+
this.connection.sendRequest('masterCSS/restart', {
|
|
284
|
+
title: 'Updating Master CSS configuration'
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async onDidChangeConfiguration({ settings: changedSettings }) {
|
|
289
|
+
await this.init();
|
|
290
|
+
if (changedSettings?.masterCSS) {
|
|
291
|
+
this.connection.sendNotification('masterCSS/globalSettingsChanged', changedSettings.masterCSS);
|
|
292
|
+
this.customSettings = changedSettings.masterCSS;
|
|
293
|
+
this.settings = extend(settings, this.customSettings);
|
|
294
|
+
this.globalWorkspace.languageServiceSettings = this.settings;
|
|
295
|
+
this.refreshSemanticTokens();
|
|
296
|
+
this.connection.sendRequest('masterCSS/restart', {
|
|
297
|
+
title: 'Updating Master CSS settings'
|
|
298
|
+
});
|
|
299
|
+
for (const workspace of [
|
|
300
|
+
this.globalWorkspace,
|
|
301
|
+
...this.workspaces.values()
|
|
302
|
+
]){
|
|
303
|
+
for (const document of workspace.openedTextDocuments){
|
|
304
|
+
this.publishCSSDirectiveDiagnostics(document, workspace);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async initWorkspaceFolder(workspaceFolderURI) {
|
|
310
|
+
const workspaceFolderCWD = URI.parse(workspaceFolderURI).fsPath;
|
|
311
|
+
let customWorkspaceFolderSettings;
|
|
312
|
+
if (this.clientCapabilities.workspace?.configuration) {
|
|
313
|
+
customWorkspaceFolderSettings = await this.connection.workspace.getConfiguration({
|
|
314
|
+
scopeUri: workspaceFolderURI,
|
|
315
|
+
section: 'masterCSS'
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
const { workspaces, ...languageServiceSettings } = extend(settings, this.customSettings, customWorkspaceFolderSettings);
|
|
319
|
+
const resolvedWorkspaceDirectories = new Set([
|
|
320
|
+
workspaceFolderCWD
|
|
321
|
+
]);
|
|
322
|
+
if (workspaceFolderCWD) {
|
|
323
|
+
this.console.info(`Registered workspace folder ${workspaceFolderURI}`);
|
|
324
|
+
} else {
|
|
325
|
+
this.console.info(`Registered global workspace folder`);
|
|
326
|
+
}
|
|
327
|
+
if (workspaces === 'auto') {
|
|
328
|
+
for (const workspaceDir of (await findMasterCSSWorkspaceDirectories(workspaceFolderCWD))){
|
|
329
|
+
resolvedWorkspaceDirectories.add(workspaceDir);
|
|
330
|
+
}
|
|
331
|
+
} else if (workspaces?.length) {
|
|
332
|
+
(await glob(workspaces, {
|
|
333
|
+
cwd: workspaceFolderCWD,
|
|
334
|
+
absolute: true,
|
|
335
|
+
onlyDirectories: true,
|
|
336
|
+
ignore: [
|
|
337
|
+
'**/node_modules/**'
|
|
338
|
+
]
|
|
339
|
+
})).forEach((workspaceDir)=>resolvedWorkspaceDirectories.add(path.resolve(workspaceDir)));
|
|
340
|
+
}
|
|
341
|
+
for (const workspaceDir of resolvedWorkspaceDirectories){
|
|
342
|
+
const workspaceURI = URI.file(workspaceDir).toString();
|
|
343
|
+
this.console.info(`Added workspace ${workspaceURI}`);
|
|
344
|
+
this.workspaces.set(workspaceURI, {
|
|
345
|
+
uri: workspaceURI,
|
|
346
|
+
openedTextDocuments: [],
|
|
347
|
+
languageServiceSettings,
|
|
348
|
+
planEntries: await findCSSManifestEntryFiles(workspaceDir)
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
async initWorkspaceLanguageService(workspace) {
|
|
353
|
+
let workspacePlan;
|
|
354
|
+
if (workspace !== this.globalWorkspace) {
|
|
355
|
+
try {
|
|
356
|
+
workspacePlan = await this.loadWorkspacePlan(workspace);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
this.console.info(`Failed to load manifest from ${workspace.uri}`);
|
|
359
|
+
this.console.error(e instanceof Error ? e.stack : e.toString());
|
|
360
|
+
}
|
|
361
|
+
if (workspacePlan) {
|
|
362
|
+
this.console.info(`Initialized workspace ${workspace.planEntries?.length ? '(with manifest entry)' : '(with manifest)'} ${workspace.uri}`);
|
|
363
|
+
} else {
|
|
364
|
+
this.console.info(`Initialized workspace ${workspace.uri}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
workspace.languageService = new CSSLanguageService({
|
|
368
|
+
...workspace.languageServiceSettings,
|
|
369
|
+
manifest: workspacePlan
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
async loadWorkspacePlan(workspace) {
|
|
373
|
+
const cwd = workspace.uri ? URI.parse(workspace.uri).fsPath : process.cwd();
|
|
374
|
+
const result = await loadProjectManifest(cwd);
|
|
375
|
+
return result.entries.length ? result.manifest : workspace.languageServiceSettings.manifest;
|
|
376
|
+
}
|
|
377
|
+
destroyLanguageService(workspace) {
|
|
378
|
+
this.console.info(`Destroyed workspace ${workspace.uri}`);
|
|
379
|
+
delete workspace.languageService;
|
|
380
|
+
}
|
|
381
|
+
findClosestWorkspace(textDocumentURI) {
|
|
382
|
+
const documentPath = toComparableFilePath(textDocumentURI);
|
|
383
|
+
if (!documentPath) {
|
|
384
|
+
this.console.info(`This is an external document ${textDocumentURI} with the global workspace`);
|
|
385
|
+
return this.globalWorkspace;
|
|
386
|
+
}
|
|
387
|
+
let foundWorkspace;
|
|
388
|
+
let foundWorkspacePath = '';
|
|
389
|
+
for (const [uri, workspace] of this.workspaces){
|
|
390
|
+
if (!uri) continue;
|
|
391
|
+
const workspacePath = toComparableFilePath(uri);
|
|
392
|
+
if (!workspacePath) continue;
|
|
393
|
+
if (containsFilePath(workspacePath, documentPath) && workspacePath.length > foundWorkspacePath.length) {
|
|
394
|
+
foundWorkspace = workspace;
|
|
395
|
+
foundWorkspacePath = workspacePath;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (foundWorkspace) return foundWorkspace;
|
|
399
|
+
this.console.info(`This is an external document ${textDocumentURI} with the global workspace`);
|
|
400
|
+
return this.globalWorkspace;
|
|
401
|
+
}
|
|
402
|
+
publishCSSDirectiveDiagnostics(textDocument, workspace) {
|
|
403
|
+
if (!isCSSDiagnosticDocument(textDocument)) return;
|
|
404
|
+
const diagnostics = [];
|
|
405
|
+
const documentFile = path.resolve(URI.parse(textDocument.uri).fsPath);
|
|
406
|
+
for (const { source, offset } of getCSSDiagnosticSources(textDocument)){
|
|
407
|
+
try {
|
|
408
|
+
compileCSSManifest(source, {
|
|
409
|
+
from: documentFile
|
|
410
|
+
});
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (!isCSSDirectiveError(error)) continue;
|
|
413
|
+
const diagnostic = this.createCSSDirectiveDiagnostic(error, textDocument, documentFile, offset);
|
|
414
|
+
if (diagnostic) diagnostics.push(diagnostic);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
this.connection.sendDiagnostics({
|
|
418
|
+
uri: textDocument.uri,
|
|
419
|
+
diagnostics
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
createCSSDirectiveDiagnostic(error, textDocument, documentFile, sourceOffset) {
|
|
423
|
+
if (error.source?.file && path.resolve(error.source.file) !== documentFile) return;
|
|
424
|
+
return {
|
|
425
|
+
range: this.createCSSDirectiveRange(error.source, textDocument, documentFile, sourceOffset),
|
|
426
|
+
severity: DiagnosticSeverity.Error,
|
|
427
|
+
code: error.code,
|
|
428
|
+
source: 'Master CSS',
|
|
429
|
+
message: error.message,
|
|
430
|
+
relatedInformation: this.createCSSDirectiveRelatedInformation(error.related, textDocument, documentFile, sourceOffset)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
createCSSDirectiveRelatedInformation(related, textDocument, documentFile, sourceOffset) {
|
|
434
|
+
if (!related?.length) return;
|
|
435
|
+
return related.map(({ message, source })=>({
|
|
436
|
+
message,
|
|
437
|
+
location: {
|
|
438
|
+
uri: source?.file ? URI.file(source.file).toString() : textDocument.uri,
|
|
439
|
+
range: this.createCSSDirectiveRange(source, textDocument, documentFile, sourceOffset)
|
|
440
|
+
}
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
createCSSDirectiveRange(source, textDocument, documentFile, sourceOffset) {
|
|
444
|
+
if (source?.file && path.resolve(source.file) !== documentFile) {
|
|
445
|
+
return source.loc ? {
|
|
446
|
+
start: {
|
|
447
|
+
line: Math.max(0, source.loc.start.line - 1),
|
|
448
|
+
character: Math.max(0, source.loc.start.column - 1)
|
|
449
|
+
},
|
|
450
|
+
end: {
|
|
451
|
+
line: Math.max(0, source.loc.end.line - 1),
|
|
452
|
+
character: Math.max(0, source.loc.end.column - 1)
|
|
453
|
+
}
|
|
454
|
+
} : {
|
|
455
|
+
start: {
|
|
456
|
+
line: 0,
|
|
457
|
+
character: 0
|
|
458
|
+
},
|
|
459
|
+
end: {
|
|
460
|
+
line: 0,
|
|
461
|
+
character: 0
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const start = Math.max(0, (source?.range.start || 0) + sourceOffset);
|
|
466
|
+
const end = Math.max(start, (source?.range.end || 0) + sourceOffset);
|
|
467
|
+
return {
|
|
468
|
+
start: textDocument.positionAt(start),
|
|
469
|
+
end: textDocument.positionAt(end)
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
refreshSemanticTokens() {
|
|
473
|
+
if (this.settings?.embeddedSyntaxHighlighting !== 'always') return;
|
|
474
|
+
if (!this.clientCapabilities.workspace?.semanticTokens?.refreshSupport) return;
|
|
475
|
+
this.connection.languages.semanticTokens.refresh();
|
|
476
|
+
}
|
|
477
|
+
stop() {
|
|
478
|
+
this.connection.sendNotification('masterCSS/dispose');
|
|
479
|
+
this.disposables.forEach((disposable)=>disposable.dispose());
|
|
480
|
+
this.disposables.length = 0;
|
|
481
|
+
this.connection.dispose();
|
|
482
|
+
this.initializing = undefined;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export { ACTIVE_SEMANTIC_TOKENS_REQUEST, DOCUMENT_SEMANTIC_TOKENS_REQUEST, CSSLanguageServer as default };
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Settings as CSSLanguageServiceSettings } from '@master/css-language-service';
|
|
2
|
+
import type { Pattern } from 'fast-glob';
|
|
3
|
+
declare const settings: Settings;
|
|
4
|
+
export default settings;
|
|
5
|
+
export declare type Settings = CSSLanguageServiceSettings & {
|
|
6
|
+
workspaces?: Pattern[] | 'auto';
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { URI } from 'vscode-uri';
|
|
5
|
+
|
|
6
|
+
const extOfLang = {
|
|
7
|
+
typescript: 'ts',
|
|
8
|
+
typescriptreact: 'tsx',
|
|
9
|
+
javascript: 'js',
|
|
10
|
+
javascriptreact: 'jsx',
|
|
11
|
+
css: 'css',
|
|
12
|
+
scss: 'scss',
|
|
13
|
+
less: 'less',
|
|
14
|
+
html: 'html',
|
|
15
|
+
json: 'json',
|
|
16
|
+
vue: 'vue',
|
|
17
|
+
svelte: 'svelte',
|
|
18
|
+
astro: 'astro'
|
|
19
|
+
};
|
|
20
|
+
function createDocument(text, options) {
|
|
21
|
+
const lang = options?.lang || 'html';
|
|
22
|
+
const dir = options?.dir || './';
|
|
23
|
+
const filePath = path.join(dir, `${nanoid()}.${extOfLang[lang]}`);
|
|
24
|
+
const fileURI = URI.file(filePath).toString();
|
|
25
|
+
return TextDocument.create(fileURI, lang, 0, text);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { createDocument as default };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@master/css-language-server","scripts":{"build":"techor
|
|
1
|
+
{"name":"@master/css-language-server","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 Server","author":"Aoyue Design LLC.","license":"MIT","repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/language-server"},"dependencies":{"@master/css":"^2.0.0-rc.71","@master/css-compiler":"^2.0.0-rc.71","@master/css-language":"^2.0.0-rc.71","@master/css-language-service":"^2.0.0-rc.71","@master/css-project":"^2.0.0-rc.71","@techor/extend":"^3.2.5","fast-glob":"^3.3.3","js-beautify":"^1.15.4","nanoid":"^5.1.15","vscode-languageserver":"^10.0.0","vscode-languageserver-textdocument":"^1.0.12","vscode-uri":"^3.1.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"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.71"}
|
package/dist/server.bundle.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var W=Object.create;var S=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var E=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of H(e))!L.call(t,i)&&i!==n&&S(t,i,{get:()=>e[i],enumerable:!(s=U(e,i))||s.enumerable});return t};var h=(t,e,n)=>(n=t!=null?W(K(t)):{},E(e||!t||!t.__esModule?S(n,"default",{value:t,enumerable:!0}):n,t));var u=require("vscode-languageserver/node"),w=require("@master/css"),b=require("minimatch"),P=require("vscode-languageserver-textdocument"),k=h(require("path")),T=require("url"),o=require("@master/css-language-service"),v=h(require("explore-config")),a=(0,u.createConnection)(u.ProposedFeatures.all),f=new u.TextDocuments(P.TextDocument),C=!1,D=!1,O=!1,l,g,I;var M=o.settings,p=new Map;a.onDidChangeConfiguration(t=>{C?p.clear():M=t.settings.masterCSS||o.settings,f.all().forEach(y)});async function B(t){if(!C)return Promise.resolve(M);let e=p.get(t);return e||(e=a.workspace.getConfiguration({scopeUri:t,section:"masterCSS"}),p.set(t,e)),e}f.onDidClose(t=>{p.delete(t.document.uri)});f.onDidOpen(t=>{y(t.document)});f.onDidSave(async t=>{k.default.parse(t.document.uri).name==="master.css"&&await A(t.document.uri)});async function y(t){l=await B(t.uri),await A(t.uri)}async function A(t){let e=await a.workspace.getWorkspaceFolders(),n;if(e?.length===1?n=e[0]:n=e?.find(s=>t.includes(s.uri)),n?.uri){let s=(0,T.fileURLToPath)(n.uri.replace("%3A",":"));I=(0,v.default)(l.config||"master.css.*",{cwd:s}),g=new w.MasterCSS(I)}}a.onInitialize(t=>{let e=t.capabilities;C=!!(e.workspace&&e.workspace.configuration),D=!!(e.workspace&&e.workspace.workspaceFolders),O=!!(e.textDocument&&e.textDocument.publishDiagnostics&&e.textDocument.publishDiagnostics.relatedInformation);let n={capabilities:{textDocumentSync:u.TextDocumentSyncKind.Incremental,completionProvider:{resolveProvider:!0,workDoneProgress:!1,triggerCharacters:[":","@","'"]},colorProvider:{},hoverProvider:!0}};return D&&(n.capabilities.workspace={workspaceFolders:{supported:!0}}),n});a.onInitialized(()=>{C&&a.client.register(u.DidChangeConfigurationNotification.type,void 0)});a.onCompletion(t=>{if(l.suggestions==!0&&x(t.textDocument.uri)){let e=t.textDocument.uri,n=f.get(e),s=e.substring(e.lastIndexOf(".")+1),i=t.position;if(n){let c=n.getText(),d=n.offsetAt(i)??0,r=n.offsetAt({line:i.line-100,character:0})??0,F=n.offsetAt({line:i.line+100,character:0})??void 0,R=(0,o.positionCheck)(c.substring(r,F),d,r,l.classMatch).IsMatch,z=n.getText({start:{line:i.line,character:0},end:{line:i.line,character:i.character}}).trim(),m=(0,o.getLastInstance)(z,i,s);if(m.isInstance==!0&&R==!0)return(0,o.getCompletionItem)(m.lastKey,m.triggerKey,m.isStart,m.language,g);if(m.isInstance==!0&&(0,o.checkConfigColorsBlock)(n,t.position)==!0)return(0,o.getConfigColorsCompletionItem)(g)}}return[]});a.onCompletionResolve(t=>t);a.onDocumentColor(async t=>{if(l==null)return[];if(l.previewColors==!0&&x(t.textDocument.uri)){let e=t.textDocument.uri,n=f.get(e);if(n){let s=n.getText()??"";if(typeof n==null)return[];let i=await(0,o.getDocumentColors)(s,g),c=new Set;return i.filter(r=>c.has(r.index.start)?!1:(c.add(r.index.start),!0)).map(r=>({range:{start:n.positionAt(r.index.start),end:n.positionAt(r.index.end)},color:r.color}))}}return[]});a.onColorPresentation(t=>{if(l.previewColors==!0&&x(t.textDocument.uri)){let e=f.get(t.textDocument.uri);if(e){let n=e.getText(),s=["(?<=colors:\\s*{\\s*.*)([^}]*)}"],i=e.offsetAt(t.range.start)??0,c=e.offsetAt({line:t.range.start.line-100,character:0})??0,d=e.offsetAt({line:t.range.start.line+100,character:0})??void 0,r=(0,o.positionCheck)(n.substring(c,d),i,c,s);return(0,o.getColorPresentation)(t,r.IsMatch)}}return[]});a.onHover(t=>{if(l.inspect==!0&&x(t.textDocument.uri)){let e=f.get(t.textDocument.uri),n=t.position;if(e){let s=e.getText(),i=e.offsetAt(n)??0,c=e.offsetAt({line:n.line-100,character:0})??0,d=e.offsetAt({line:n.line+100,character:0})??void 0,r=(0,o.positionCheck)(s.substring(c,d),i,c,l.classMatch);if(r.IsMatch)return(0,o.doHover)(r.instance.instanceString,N(r.instance.index,e),I)}}return null});function x(t){for(let e of l.files.exclude)if((0,b.minimatch)(t,e))return!1;return!0}function N(t,e){return{start:e.positionAt(t.start),end:e.positionAt(t.end)}}f.listen(a);a.listen();
|
package/dist/server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|