@master/css-language-server 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/serve.cjs +263 -0
- package/dist/serve.d.ts +1 -0
- package/dist/serve.mjs +261 -0
- package/package.json +1 -1
- package/dist/server.bundle.js +0 -1
- package/dist/server.d.ts +0 -1
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as serve } from './serve';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as serve } from './serve.mjs';
|
package/dist/serve.cjs
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node = require('vscode-languageserver/node');
|
|
4
|
+
var css = require('@master/css');
|
|
5
|
+
var minimatch = require('minimatch');
|
|
6
|
+
var vscodeLanguageserverTextdocument = require('vscode-languageserver-textdocument');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var url = require('url');
|
|
9
|
+
var cssLanguageService = require('@master/css-language-service');
|
|
10
|
+
var exploreConfig = require('explore-config');
|
|
11
|
+
|
|
12
|
+
function serve() {
|
|
13
|
+
const connection = node.createConnection(node.ProposedFeatures.all);
|
|
14
|
+
const documents = new node.TextDocuments(vscodeLanguageserverTextdocument.TextDocument);
|
|
15
|
+
let hasConfigurationCapability = false;
|
|
16
|
+
let hasWorkspaceFolderCapability = false;
|
|
17
|
+
let settings;
|
|
18
|
+
let css$1;
|
|
19
|
+
let customConfig;
|
|
20
|
+
let globalSettings = cssLanguageService.settings;
|
|
21
|
+
// Cache the settings of all open documents
|
|
22
|
+
const documentSettings = new Map();
|
|
23
|
+
connection.onDidChangeConfiguration((change)=>{
|
|
24
|
+
if (hasConfigurationCapability) {
|
|
25
|
+
// Reset all cached document settings
|
|
26
|
+
documentSettings.clear();
|
|
27
|
+
} else {
|
|
28
|
+
globalSettings = change.settings.masterCSS || cssLanguageService.settings;
|
|
29
|
+
}
|
|
30
|
+
// Revalidate all open text documents
|
|
31
|
+
documents.all().forEach(validateTextDocument);
|
|
32
|
+
});
|
|
33
|
+
async function getDocumentSettings(resource) {
|
|
34
|
+
if (!hasConfigurationCapability) {
|
|
35
|
+
return Promise.resolve(globalSettings);
|
|
36
|
+
}
|
|
37
|
+
let result = documentSettings.get(resource);
|
|
38
|
+
if (!result) {
|
|
39
|
+
result = connection.workspace.getConfiguration({
|
|
40
|
+
scopeUri: resource,
|
|
41
|
+
section: 'masterCSS'
|
|
42
|
+
});
|
|
43
|
+
documentSettings.set(resource, result);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
// Only keep settings for open documents
|
|
48
|
+
documents.onDidClose((e)=>{
|
|
49
|
+
documentSettings.delete(e.document.uri);
|
|
50
|
+
});
|
|
51
|
+
// The content of a text document has changed. This event is emitted
|
|
52
|
+
// when the text document first opened or when its content has changed.
|
|
53
|
+
documents.onDidOpen((change)=>{
|
|
54
|
+
validateTextDocument(change.document);
|
|
55
|
+
});
|
|
56
|
+
documents.onDidSave(async (change)=>{
|
|
57
|
+
if (path.parse(change.document.uri).name === 'master.css') {
|
|
58
|
+
await loadMasterCssConfig(change.document.uri);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
async function validateTextDocument(textDocument) {
|
|
62
|
+
// In this simple example we get the settings for every validate run.
|
|
63
|
+
settings = await getDocumentSettings(textDocument.uri);
|
|
64
|
+
await loadMasterCssConfig(textDocument.uri);
|
|
65
|
+
}
|
|
66
|
+
async function loadMasterCssConfig(resource) {
|
|
67
|
+
const workspaceFolders = await connection.workspace.getWorkspaceFolders();
|
|
68
|
+
let root;
|
|
69
|
+
if (workspaceFolders?.length === 1) {
|
|
70
|
+
root = workspaceFolders[0];
|
|
71
|
+
} else {
|
|
72
|
+
root = workspaceFolders?.find((x)=>resource.includes(x.uri));
|
|
73
|
+
}
|
|
74
|
+
if (root?.uri) {
|
|
75
|
+
const configCWD = url.fileURLToPath(root.uri.replace('%3A', ':'));
|
|
76
|
+
customConfig = exploreConfig(settings.config || 'master.css', {
|
|
77
|
+
cwd: configCWD,
|
|
78
|
+
found: (basename)=>console.log`Loaded **${basename}**`
|
|
79
|
+
});
|
|
80
|
+
css$1 = new css.MasterCSS(customConfig);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
connection.onInitialize((params)=>{
|
|
84
|
+
const capabilities = params.capabilities;
|
|
85
|
+
// Does the client support the `workspace/configuration` request?
|
|
86
|
+
// If not, we fall back using global settings.
|
|
87
|
+
hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
88
|
+
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
89
|
+
!!(capabilities.textDocument && capabilities.textDocument.publishDiagnostics && capabilities.textDocument.publishDiagnostics.relatedInformation);
|
|
90
|
+
const result = {
|
|
91
|
+
capabilities: {
|
|
92
|
+
textDocumentSync: node.TextDocumentSyncKind.Incremental,
|
|
93
|
+
// Tell the client that this server supports code completion.
|
|
94
|
+
completionProvider: {
|
|
95
|
+
resolveProvider: true,
|
|
96
|
+
workDoneProgress: false,
|
|
97
|
+
triggerCharacters: [
|
|
98
|
+
':',
|
|
99
|
+
'@',
|
|
100
|
+
'\''
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
colorProvider: {},
|
|
104
|
+
hoverProvider: true
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
if (hasWorkspaceFolderCapability) {
|
|
108
|
+
result.capabilities.workspace = {
|
|
109
|
+
workspaceFolders: {
|
|
110
|
+
supported: true
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
});
|
|
116
|
+
connection.onInitialized(()=>{
|
|
117
|
+
if (hasConfigurationCapability) {
|
|
118
|
+
// Register for all configuration changes.
|
|
119
|
+
connection.client.register(node.DidChangeConfigurationNotification.type, undefined);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
connection.onCompletion((textDocumentPosition)=>{
|
|
123
|
+
if (settings.suggestions == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
124
|
+
const documentUri = textDocumentPosition.textDocument.uri;
|
|
125
|
+
const document = documents.get(documentUri);
|
|
126
|
+
const language = documentUri.substring(documentUri.lastIndexOf('.') + 1);
|
|
127
|
+
const position = textDocumentPosition.position;
|
|
128
|
+
if (document) {
|
|
129
|
+
const text = document.getText();
|
|
130
|
+
const positionIndex = document.offsetAt(position) ?? 0;
|
|
131
|
+
const startIndex = document.offsetAt({
|
|
132
|
+
line: position.line - 100,
|
|
133
|
+
character: 0
|
|
134
|
+
}) ?? 0;
|
|
135
|
+
const endIndex = document.offsetAt({
|
|
136
|
+
line: position.line + 100,
|
|
137
|
+
character: 0
|
|
138
|
+
}) ?? undefined;
|
|
139
|
+
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings.classMatch);
|
|
140
|
+
const lineText = document.getText({
|
|
141
|
+
start: {
|
|
142
|
+
line: position.line,
|
|
143
|
+
character: 0
|
|
144
|
+
},
|
|
145
|
+
end: {
|
|
146
|
+
line: position.line,
|
|
147
|
+
character: position.character
|
|
148
|
+
}
|
|
149
|
+
}).trim();
|
|
150
|
+
const lastInstance = cssLanguageService.getLastInstance(lineText, position, language);
|
|
151
|
+
if (lastInstance.isInstance == true && checkResult) {
|
|
152
|
+
return cssLanguageService.getCompletionItem(lastInstance.lastKey, lastInstance.triggerKey, lastInstance.isStart, lastInstance.language, css$1);
|
|
153
|
+
} else if (lastInstance.isInstance == true && cssLanguageService.checkConfigColorsBlock(document, textDocumentPosition.position) == true) {
|
|
154
|
+
return cssLanguageService.getConfigColorsCompletionItem(css$1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return [];
|
|
159
|
+
});
|
|
160
|
+
connection.onCompletionResolve((item)=>{
|
|
161
|
+
return item;
|
|
162
|
+
});
|
|
163
|
+
connection.onDocumentColor(async (documentColor)=>{
|
|
164
|
+
if (settings == null) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
if (settings.previewColors == true && CheckFilesExclude(documentColor.textDocument.uri)) {
|
|
168
|
+
const documentUri = documentColor.textDocument.uri;
|
|
169
|
+
const document = documents.get(documentUri);
|
|
170
|
+
if (document) {
|
|
171
|
+
const text = document.getText() ?? '';
|
|
172
|
+
if (typeof document == 'undefined') {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
const colorIndexs = await cssLanguageService.getDocumentColors(text, css$1);
|
|
176
|
+
const colorIndexSet = new Set();
|
|
177
|
+
const colorInformations = colorIndexs.filter((item)=>{
|
|
178
|
+
if (colorIndexSet.has(item.index.start)) {
|
|
179
|
+
return false;
|
|
180
|
+
} else {
|
|
181
|
+
colorIndexSet.add(item.index.start);
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}).map((x)=>({
|
|
185
|
+
range: {
|
|
186
|
+
start: document.positionAt(x.index.start),
|
|
187
|
+
end: document.positionAt(x.index.end)
|
|
188
|
+
},
|
|
189
|
+
color: x.color
|
|
190
|
+
}));
|
|
191
|
+
return colorInformations;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return [];
|
|
195
|
+
});
|
|
196
|
+
connection.onColorPresentation((params)=>{
|
|
197
|
+
if (settings.previewColors == true && CheckFilesExclude(params.textDocument.uri)) {
|
|
198
|
+
const document = documents.get(params.textDocument.uri);
|
|
199
|
+
if (document) {
|
|
200
|
+
const text = document.getText();
|
|
201
|
+
const colorRender = [
|
|
202
|
+
'(?<=colors:\\s*{\\s*.*)([^}]*)}'
|
|
203
|
+
];
|
|
204
|
+
const positionIndex = document.offsetAt(params.range.start) ?? 0;
|
|
205
|
+
const startIndex = document.offsetAt({
|
|
206
|
+
line: params.range.start.line - 100,
|
|
207
|
+
character: 0
|
|
208
|
+
}) ?? 0;
|
|
209
|
+
const endIndex = document.offsetAt({
|
|
210
|
+
line: params.range.start.line + 100,
|
|
211
|
+
character: 0
|
|
212
|
+
}) ?? undefined;
|
|
213
|
+
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, colorRender);
|
|
214
|
+
return cssLanguageService.getColorPresentation(params, checkResult !== null);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return [];
|
|
218
|
+
});
|
|
219
|
+
connection.onHover((textDocumentPosition)=>{
|
|
220
|
+
if (settings.inspect == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
221
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
222
|
+
const position = textDocumentPosition.position;
|
|
223
|
+
if (document) {
|
|
224
|
+
const text = document.getText();
|
|
225
|
+
const positionIndex = document.offsetAt(position) ?? 0;
|
|
226
|
+
const startIndex = document.offsetAt({
|
|
227
|
+
line: position.line - 100,
|
|
228
|
+
character: 0
|
|
229
|
+
}) ?? 0;
|
|
230
|
+
const endIndex = document.offsetAt({
|
|
231
|
+
line: position.line + 100,
|
|
232
|
+
character: 0
|
|
233
|
+
}) ?? undefined;
|
|
234
|
+
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings.classMatch);
|
|
235
|
+
if (checkResult) {
|
|
236
|
+
return cssLanguageService.doHover(checkResult.instanceContent, indexToRange(checkResult.index, document), customConfig);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
});
|
|
242
|
+
function CheckFilesExclude(path) {
|
|
243
|
+
for (const exclude of settings.files.exclude){
|
|
244
|
+
if (minimatch.minimatch(path, exclude)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
function indexToRange(index, document) {
|
|
251
|
+
return {
|
|
252
|
+
start: document.positionAt(index.start),
|
|
253
|
+
end: document.positionAt(index.end)
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// Make the text document manager listen on the connection
|
|
257
|
+
// for open, change and close text document events
|
|
258
|
+
documents.listen(connection);
|
|
259
|
+
// Listen on the connection
|
|
260
|
+
connection.listen();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = serve;
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function serve(): void;
|
package/dist/serve.mjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { createConnection, ProposedFeatures, TextDocuments, TextDocumentSyncKind, DidChangeConfigurationNotification } from 'vscode-languageserver/node';
|
|
2
|
+
import { MasterCSS } from '@master/css';
|
|
3
|
+
import { minimatch } from 'minimatch';
|
|
4
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { settings, positionCheck, getLastInstance, getCompletionItem, checkConfigColorsBlock, getConfigColorsCompletionItem, getDocumentColors, getColorPresentation, doHover } from '@master/css-language-service';
|
|
8
|
+
import exploreConfig from 'explore-config';
|
|
9
|
+
|
|
10
|
+
function serve() {
|
|
11
|
+
const connection = createConnection(ProposedFeatures.all);
|
|
12
|
+
const documents = new TextDocuments(TextDocument);
|
|
13
|
+
let hasConfigurationCapability = false;
|
|
14
|
+
let hasWorkspaceFolderCapability = false;
|
|
15
|
+
let settings$1;
|
|
16
|
+
let css;
|
|
17
|
+
let customConfig;
|
|
18
|
+
let globalSettings = settings;
|
|
19
|
+
// Cache the settings of all open documents
|
|
20
|
+
const documentSettings = new Map();
|
|
21
|
+
connection.onDidChangeConfiguration((change)=>{
|
|
22
|
+
if (hasConfigurationCapability) {
|
|
23
|
+
// Reset all cached document settings
|
|
24
|
+
documentSettings.clear();
|
|
25
|
+
} else {
|
|
26
|
+
globalSettings = change.settings.masterCSS || settings;
|
|
27
|
+
}
|
|
28
|
+
// Revalidate all open text documents
|
|
29
|
+
documents.all().forEach(validateTextDocument);
|
|
30
|
+
});
|
|
31
|
+
async function getDocumentSettings(resource) {
|
|
32
|
+
if (!hasConfigurationCapability) {
|
|
33
|
+
return Promise.resolve(globalSettings);
|
|
34
|
+
}
|
|
35
|
+
let result = documentSettings.get(resource);
|
|
36
|
+
if (!result) {
|
|
37
|
+
result = connection.workspace.getConfiguration({
|
|
38
|
+
scopeUri: resource,
|
|
39
|
+
section: 'masterCSS'
|
|
40
|
+
});
|
|
41
|
+
documentSettings.set(resource, result);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
// Only keep settings for open documents
|
|
46
|
+
documents.onDidClose((e)=>{
|
|
47
|
+
documentSettings.delete(e.document.uri);
|
|
48
|
+
});
|
|
49
|
+
// The content of a text document has changed. This event is emitted
|
|
50
|
+
// when the text document first opened or when its content has changed.
|
|
51
|
+
documents.onDidOpen((change)=>{
|
|
52
|
+
validateTextDocument(change.document);
|
|
53
|
+
});
|
|
54
|
+
documents.onDidSave(async (change)=>{
|
|
55
|
+
if (path.parse(change.document.uri).name === 'master.css') {
|
|
56
|
+
await loadMasterCssConfig(change.document.uri);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
async function validateTextDocument(textDocument) {
|
|
60
|
+
// In this simple example we get the settings for every validate run.
|
|
61
|
+
settings$1 = await getDocumentSettings(textDocument.uri);
|
|
62
|
+
await loadMasterCssConfig(textDocument.uri);
|
|
63
|
+
}
|
|
64
|
+
async function loadMasterCssConfig(resource) {
|
|
65
|
+
const workspaceFolders = await connection.workspace.getWorkspaceFolders();
|
|
66
|
+
let root;
|
|
67
|
+
if (workspaceFolders?.length === 1) {
|
|
68
|
+
root = workspaceFolders[0];
|
|
69
|
+
} else {
|
|
70
|
+
root = workspaceFolders?.find((x)=>resource.includes(x.uri));
|
|
71
|
+
}
|
|
72
|
+
if (root?.uri) {
|
|
73
|
+
const configCWD = fileURLToPath(root.uri.replace('%3A', ':'));
|
|
74
|
+
customConfig = exploreConfig(settings$1.config || 'master.css', {
|
|
75
|
+
cwd: configCWD,
|
|
76
|
+
found: (basename)=>console.log`Loaded **${basename}**`
|
|
77
|
+
});
|
|
78
|
+
css = new MasterCSS(customConfig);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
connection.onInitialize((params)=>{
|
|
82
|
+
const capabilities = params.capabilities;
|
|
83
|
+
// Does the client support the `workspace/configuration` request?
|
|
84
|
+
// If not, we fall back using global settings.
|
|
85
|
+
hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
86
|
+
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
87
|
+
!!(capabilities.textDocument && capabilities.textDocument.publishDiagnostics && capabilities.textDocument.publishDiagnostics.relatedInformation);
|
|
88
|
+
const result = {
|
|
89
|
+
capabilities: {
|
|
90
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
91
|
+
// Tell the client that this server supports code completion.
|
|
92
|
+
completionProvider: {
|
|
93
|
+
resolveProvider: true,
|
|
94
|
+
workDoneProgress: false,
|
|
95
|
+
triggerCharacters: [
|
|
96
|
+
':',
|
|
97
|
+
'@',
|
|
98
|
+
'\''
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
colorProvider: {},
|
|
102
|
+
hoverProvider: true
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if (hasWorkspaceFolderCapability) {
|
|
106
|
+
result.capabilities.workspace = {
|
|
107
|
+
workspaceFolders: {
|
|
108
|
+
supported: true
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
});
|
|
114
|
+
connection.onInitialized(()=>{
|
|
115
|
+
if (hasConfigurationCapability) {
|
|
116
|
+
// Register for all configuration changes.
|
|
117
|
+
connection.client.register(DidChangeConfigurationNotification.type, undefined);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
connection.onCompletion((textDocumentPosition)=>{
|
|
121
|
+
if (settings$1.suggestions == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
122
|
+
const documentUri = textDocumentPosition.textDocument.uri;
|
|
123
|
+
const document = documents.get(documentUri);
|
|
124
|
+
const language = documentUri.substring(documentUri.lastIndexOf('.') + 1);
|
|
125
|
+
const position = textDocumentPosition.position;
|
|
126
|
+
if (document) {
|
|
127
|
+
const text = document.getText();
|
|
128
|
+
const positionIndex = document.offsetAt(position) ?? 0;
|
|
129
|
+
const startIndex = document.offsetAt({
|
|
130
|
+
line: position.line - 100,
|
|
131
|
+
character: 0
|
|
132
|
+
}) ?? 0;
|
|
133
|
+
const endIndex = document.offsetAt({
|
|
134
|
+
line: position.line + 100,
|
|
135
|
+
character: 0
|
|
136
|
+
}) ?? undefined;
|
|
137
|
+
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings$1.classMatch);
|
|
138
|
+
const lineText = document.getText({
|
|
139
|
+
start: {
|
|
140
|
+
line: position.line,
|
|
141
|
+
character: 0
|
|
142
|
+
},
|
|
143
|
+
end: {
|
|
144
|
+
line: position.line,
|
|
145
|
+
character: position.character
|
|
146
|
+
}
|
|
147
|
+
}).trim();
|
|
148
|
+
const lastInstance = getLastInstance(lineText, position, language);
|
|
149
|
+
if (lastInstance.isInstance == true && checkResult) {
|
|
150
|
+
return getCompletionItem(lastInstance.lastKey, lastInstance.triggerKey, lastInstance.isStart, lastInstance.language, css);
|
|
151
|
+
} else if (lastInstance.isInstance == true && checkConfigColorsBlock(document, textDocumentPosition.position) == true) {
|
|
152
|
+
return getConfigColorsCompletionItem(css);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return [];
|
|
157
|
+
});
|
|
158
|
+
connection.onCompletionResolve((item)=>{
|
|
159
|
+
return item;
|
|
160
|
+
});
|
|
161
|
+
connection.onDocumentColor(async (documentColor)=>{
|
|
162
|
+
if (settings$1 == null) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
if (settings$1.previewColors == true && CheckFilesExclude(documentColor.textDocument.uri)) {
|
|
166
|
+
const documentUri = documentColor.textDocument.uri;
|
|
167
|
+
const document = documents.get(documentUri);
|
|
168
|
+
if (document) {
|
|
169
|
+
const text = document.getText() ?? '';
|
|
170
|
+
if (typeof document == 'undefined') {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
const colorIndexs = await getDocumentColors(text, css);
|
|
174
|
+
const colorIndexSet = new Set();
|
|
175
|
+
const colorInformations = colorIndexs.filter((item)=>{
|
|
176
|
+
if (colorIndexSet.has(item.index.start)) {
|
|
177
|
+
return false;
|
|
178
|
+
} else {
|
|
179
|
+
colorIndexSet.add(item.index.start);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}).map((x)=>({
|
|
183
|
+
range: {
|
|
184
|
+
start: document.positionAt(x.index.start),
|
|
185
|
+
end: document.positionAt(x.index.end)
|
|
186
|
+
},
|
|
187
|
+
color: x.color
|
|
188
|
+
}));
|
|
189
|
+
return colorInformations;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [];
|
|
193
|
+
});
|
|
194
|
+
connection.onColorPresentation((params)=>{
|
|
195
|
+
if (settings$1.previewColors == true && CheckFilesExclude(params.textDocument.uri)) {
|
|
196
|
+
const document = documents.get(params.textDocument.uri);
|
|
197
|
+
if (document) {
|
|
198
|
+
const text = document.getText();
|
|
199
|
+
const colorRender = [
|
|
200
|
+
'(?<=colors:\\s*{\\s*.*)([^}]*)}'
|
|
201
|
+
];
|
|
202
|
+
const positionIndex = document.offsetAt(params.range.start) ?? 0;
|
|
203
|
+
const startIndex = document.offsetAt({
|
|
204
|
+
line: params.range.start.line - 100,
|
|
205
|
+
character: 0
|
|
206
|
+
}) ?? 0;
|
|
207
|
+
const endIndex = document.offsetAt({
|
|
208
|
+
line: params.range.start.line + 100,
|
|
209
|
+
character: 0
|
|
210
|
+
}) ?? undefined;
|
|
211
|
+
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, colorRender);
|
|
212
|
+
return getColorPresentation(params, checkResult !== null);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return [];
|
|
216
|
+
});
|
|
217
|
+
connection.onHover((textDocumentPosition)=>{
|
|
218
|
+
if (settings$1.inspect == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
219
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
220
|
+
const position = textDocumentPosition.position;
|
|
221
|
+
if (document) {
|
|
222
|
+
const text = document.getText();
|
|
223
|
+
const positionIndex = document.offsetAt(position) ?? 0;
|
|
224
|
+
const startIndex = document.offsetAt({
|
|
225
|
+
line: position.line - 100,
|
|
226
|
+
character: 0
|
|
227
|
+
}) ?? 0;
|
|
228
|
+
const endIndex = document.offsetAt({
|
|
229
|
+
line: position.line + 100,
|
|
230
|
+
character: 0
|
|
231
|
+
}) ?? undefined;
|
|
232
|
+
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings$1.classMatch);
|
|
233
|
+
if (checkResult) {
|
|
234
|
+
return doHover(checkResult.instanceContent, indexToRange(checkResult.index, document), customConfig);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
});
|
|
240
|
+
function CheckFilesExclude(path) {
|
|
241
|
+
for (const exclude of settings$1.files.exclude){
|
|
242
|
+
if (minimatch(path, exclude)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
function indexToRange(index, document) {
|
|
249
|
+
return {
|
|
250
|
+
start: document.positionAt(index.start),
|
|
251
|
+
end: document.positionAt(index.end)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
// Make the text document manager listen on the connection
|
|
255
|
+
// for open, change and close text document events
|
|
256
|
+
documents.listen(connection);
|
|
257
|
+
// Listen on the connection
|
|
258
|
+
connection.listen();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { serve 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\"","dev":"pnpm build --watch","type-check":"tsc --noEmit","lint":"eslint src","test":"jest"},"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.21","@master/css-language-service":"^2.0.0-rc.21","explore-config":"^3.0.16","js-beautify":"^1.15.1","minimatch":"^9.0.3","vscode-languageserver":"^7.0.0","vscode-languageserver-textdocument":"^1.0.11"},"sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","types":"./dist/index.d.ts"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.21"}
|
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 {};
|