@master/css-language-server 2.0.0-rc.26 → 2.0.0-rc.28
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/core.cjs +152 -0
- package/dist/core.d.ts +21 -0
- package/dist/core.mjs +150 -0
- package/dist/index.cjs +7 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/settings.cjs +10 -0
- package/dist/settings.d.ts +6 -0
- package/dist/settings.mjs +8 -0
- package/package.json +1 -1
- package/dist/serve.cjs +0 -270
- package/dist/serve.d.ts +0 -1
- package/dist/serve.mjs +0 -268
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node = require('vscode-languageserver/node');
|
|
4
|
+
var vscodeLanguageserverTextdocument = require('vscode-languageserver-textdocument');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
|
+
var cssLanguageServiceSettings = require('@master/css-language-service');
|
|
8
|
+
var exploreConfig = require('@master/css-explore-config');
|
|
9
|
+
var extend = require('@techor/extend');
|
|
10
|
+
var settings = require('./settings.cjs');
|
|
11
|
+
|
|
12
|
+
class CSSLanguageServer {
|
|
13
|
+
customSettings;
|
|
14
|
+
workspaceFolders;
|
|
15
|
+
workspaceCSSLanguageService;
|
|
16
|
+
workspaceSettings;
|
|
17
|
+
workspaceConfigs;
|
|
18
|
+
connection;
|
|
19
|
+
documents;
|
|
20
|
+
constructor(customSettings){
|
|
21
|
+
this.customSettings = customSettings;
|
|
22
|
+
this.workspaceFolders = [];
|
|
23
|
+
this.workspaceCSSLanguageService = {};
|
|
24
|
+
this.workspaceSettings = {};
|
|
25
|
+
this.workspaceConfigs = {};
|
|
26
|
+
this.connection = node.createConnection(node.ProposedFeatures.all);
|
|
27
|
+
this.documents = new node.TextDocuments(vscodeLanguageserverTextdocument.TextDocument);
|
|
28
|
+
this.connection.onDidChangeConfiguration(this.revalidate);
|
|
29
|
+
this.documents.onDidSave(async (change)=>{
|
|
30
|
+
// if the saved file is the master.css file, we need to refresh the css instance
|
|
31
|
+
if (path.parse(change.document.uri).name === 'master.css') {
|
|
32
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(change.document.uri);
|
|
33
|
+
const workspaceFolder = this.findWorkspaceFolder(change.document.uri);
|
|
34
|
+
if (cssLanguageService) cssLanguageService.css.refresh(this.updateWorkspaceConfig(workspaceFolder.uri));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this.connection.onInitialize((params)=>{
|
|
38
|
+
if (params.workspaceFolders?.length) {
|
|
39
|
+
this.workspaceFolders = params.workspaceFolders;
|
|
40
|
+
} else {
|
|
41
|
+
if (params.rootUri) {
|
|
42
|
+
this.workspaceFolders.push({
|
|
43
|
+
name: '',
|
|
44
|
+
uri: params.rootUri
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
capabilities: cssLanguageServiceSettings.SERVER_CAPABILITIES
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
this.connection.onInitialized(async ()=>{
|
|
53
|
+
await this.workspaceFolders.map(async (folder)=>{
|
|
54
|
+
this.workspaceCSSLanguageService[folder.uri] = await this.createLanguageService(folder.uri);
|
|
55
|
+
});
|
|
56
|
+
this.connection.client.register(node.DidChangeConfigurationNotification.type, undefined);
|
|
57
|
+
});
|
|
58
|
+
this.connection.onHover((params)=>{
|
|
59
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
60
|
+
if (cssLanguageService) {
|
|
61
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
62
|
+
if (document) return cssLanguageService.inspectSyntax(document, params.position);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this.connection.onCompletion((params)=>{
|
|
66
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
67
|
+
if (cssLanguageService) {
|
|
68
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
69
|
+
if (document) return cssLanguageService.suggestSyntax(document, params.position, params.context);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
this.connection.onDocumentColor((params)=>{
|
|
73
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
74
|
+
if (cssLanguageService) {
|
|
75
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
76
|
+
if (document) return cssLanguageService.renderSyntaxColors(document);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.connection.onColorPresentation((params)=>{
|
|
80
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
81
|
+
if (cssLanguageService) {
|
|
82
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
83
|
+
if (document) return cssLanguageService.editSyntaxColors(document, params.color, params.range);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Make the text document manager listen on the connection
|
|
87
|
+
// for open, change and close text document events
|
|
88
|
+
this.documents.listen(this.connection);
|
|
89
|
+
}
|
|
90
|
+
async createLanguageService(workspaceURI) {
|
|
91
|
+
const { config, ...workspaceCSSLanguageServiceSettings } = await this.updateWorkspaceSettings(workspaceURI);
|
|
92
|
+
const workspaceConfig = this.workspaceConfigs[workspaceURI];
|
|
93
|
+
return new cssLanguageServiceSettings({
|
|
94
|
+
...workspaceCSSLanguageServiceSettings,
|
|
95
|
+
config: workspaceConfig
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async updateWorkspaceSettings(workspaceURI) {
|
|
99
|
+
const customWorkspaceSettings = await this.connection.workspace.getConfiguration({
|
|
100
|
+
scopeUri: workspaceURI,
|
|
101
|
+
section: 'masterCSS'
|
|
102
|
+
});
|
|
103
|
+
const resolvedSettings = extend(settings, this.customSettings, customWorkspaceSettings);
|
|
104
|
+
this.workspaceSettings[workspaceURI] = resolvedSettings;
|
|
105
|
+
this.updateWorkspaceConfig(workspaceURI);
|
|
106
|
+
return resolvedSettings;
|
|
107
|
+
}
|
|
108
|
+
updateWorkspaceConfig(workspaceURI) {
|
|
109
|
+
const workspaceSettings = this.workspaceSettings[workspaceURI];
|
|
110
|
+
const workspaceCWD = url.fileURLToPath(workspaceURI.replace('%3A', ':'));
|
|
111
|
+
let workspaceConfig;
|
|
112
|
+
if (typeof workspaceSettings.config === 'string') {
|
|
113
|
+
try {
|
|
114
|
+
workspaceConfig = exploreConfig({
|
|
115
|
+
name: workspaceSettings.config,
|
|
116
|
+
cwd: workspaceCWD
|
|
117
|
+
});
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.log('Config loading failed from', workspaceCWD);
|
|
120
|
+
console.error(e);
|
|
121
|
+
console.log('Fall back to default config');
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
workspaceConfig = workspaceSettings.config;
|
|
125
|
+
}
|
|
126
|
+
return this.workspaceConfigs[workspaceURI] = workspaceConfig;
|
|
127
|
+
}
|
|
128
|
+
// find the workspace language service for the given uri
|
|
129
|
+
findWorkspaceCSSLanguageService(uri) {
|
|
130
|
+
for(const workspaceURI in this.workspaceCSSLanguageService){
|
|
131
|
+
if (uri.startsWith(workspaceURI)) {
|
|
132
|
+
return this.workspaceCSSLanguageService[workspaceURI];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
findWorkspaceFolder(uri) {
|
|
137
|
+
const workspaceFolder = this.workspaceFolders.find((workspace)=>uri.startsWith(workspace.uri));
|
|
138
|
+
if (!workspaceFolder) {
|
|
139
|
+
throw new Error(`Workspace folder not found for ${uri}`);
|
|
140
|
+
}
|
|
141
|
+
return workspaceFolder;
|
|
142
|
+
}
|
|
143
|
+
// revalidate workspace language services by all documents
|
|
144
|
+
async revalidate() {
|
|
145
|
+
return await Promise.all(this.documents.all().map(async (textDocument)=>{
|
|
146
|
+
const workspaceFolder = this.findWorkspaceFolder(textDocument.uri);
|
|
147
|
+
return this.workspaceCSSLanguageService[workspaceFolder.uri] = await this.createLanguageService(workspaceFolder.uri);
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = CSSLanguageServer;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TextDocuments, WorkspaceFolder } from 'vscode-languageserver/node';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import CSSLanguageService from '@master/css-language-service';
|
|
4
|
+
import { Settings } from './settings';
|
|
5
|
+
import { Config } from '@master/css';
|
|
6
|
+
export default class CSSLanguageServer {
|
|
7
|
+
customSettings?: Settings | undefined;
|
|
8
|
+
workspaceFolders: WorkspaceFolder[];
|
|
9
|
+
workspaceCSSLanguageService: Record<string, CSSLanguageService>;
|
|
10
|
+
workspaceSettings: Record<string, Settings>;
|
|
11
|
+
workspaceConfigs: Record<string, Config | undefined>;
|
|
12
|
+
connection: import("vscode-languageserver/node")._Connection<import("vscode-languageserver/node")._, import("vscode-languageserver/node")._, import("vscode-languageserver/node")._, import("vscode-languageserver/node")._, import("vscode-languageserver/node")._, import("vscode-languageserver/node")._, import("vscode-languageserver/node")._>;
|
|
13
|
+
documents: TextDocuments<TextDocument>;
|
|
14
|
+
constructor(customSettings?: Settings | undefined);
|
|
15
|
+
createLanguageService(workspaceURI: string): Promise<CSSLanguageService>;
|
|
16
|
+
updateWorkspaceSettings(workspaceURI: string): Promise<Settings>;
|
|
17
|
+
updateWorkspaceConfig(workspaceURI: string): Config | undefined;
|
|
18
|
+
findWorkspaceCSSLanguageService(uri: string): CSSLanguageService | undefined;
|
|
19
|
+
findWorkspaceFolder(uri: string): WorkspaceFolder;
|
|
20
|
+
revalidate(): Promise<CSSLanguageService[]>;
|
|
21
|
+
}
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createConnection, ProposedFeatures, TextDocuments, DidChangeConfigurationNotification } from 'vscode-languageserver/node';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import cssLanguageServiceSettings, { SERVER_CAPABILITIES } from '@master/css-language-service';
|
|
6
|
+
import exploreConfig from '@master/css-explore-config';
|
|
7
|
+
import extend from '@techor/extend';
|
|
8
|
+
import settings from './settings.mjs';
|
|
9
|
+
|
|
10
|
+
class CSSLanguageServer {
|
|
11
|
+
customSettings;
|
|
12
|
+
workspaceFolders;
|
|
13
|
+
workspaceCSSLanguageService;
|
|
14
|
+
workspaceSettings;
|
|
15
|
+
workspaceConfigs;
|
|
16
|
+
connection;
|
|
17
|
+
documents;
|
|
18
|
+
constructor(customSettings){
|
|
19
|
+
this.customSettings = customSettings;
|
|
20
|
+
this.workspaceFolders = [];
|
|
21
|
+
this.workspaceCSSLanguageService = {};
|
|
22
|
+
this.workspaceSettings = {};
|
|
23
|
+
this.workspaceConfigs = {};
|
|
24
|
+
this.connection = createConnection(ProposedFeatures.all);
|
|
25
|
+
this.documents = new TextDocuments(TextDocument);
|
|
26
|
+
this.connection.onDidChangeConfiguration(this.revalidate);
|
|
27
|
+
this.documents.onDidSave(async (change)=>{
|
|
28
|
+
// if the saved file is the master.css file, we need to refresh the css instance
|
|
29
|
+
if (path.parse(change.document.uri).name === 'master.css') {
|
|
30
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(change.document.uri);
|
|
31
|
+
const workspaceFolder = this.findWorkspaceFolder(change.document.uri);
|
|
32
|
+
if (cssLanguageService) cssLanguageService.css.refresh(this.updateWorkspaceConfig(workspaceFolder.uri));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.connection.onInitialize((params)=>{
|
|
36
|
+
if (params.workspaceFolders?.length) {
|
|
37
|
+
this.workspaceFolders = params.workspaceFolders;
|
|
38
|
+
} else {
|
|
39
|
+
if (params.rootUri) {
|
|
40
|
+
this.workspaceFolders.push({
|
|
41
|
+
name: '',
|
|
42
|
+
uri: params.rootUri
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
capabilities: SERVER_CAPABILITIES
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
this.connection.onInitialized(async ()=>{
|
|
51
|
+
await this.workspaceFolders.map(async (folder)=>{
|
|
52
|
+
this.workspaceCSSLanguageService[folder.uri] = await this.createLanguageService(folder.uri);
|
|
53
|
+
});
|
|
54
|
+
this.connection.client.register(DidChangeConfigurationNotification.type, undefined);
|
|
55
|
+
});
|
|
56
|
+
this.connection.onHover((params)=>{
|
|
57
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
58
|
+
if (cssLanguageService) {
|
|
59
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
60
|
+
if (document) return cssLanguageService.inspectSyntax(document, params.position);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.connection.onCompletion((params)=>{
|
|
64
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
65
|
+
if (cssLanguageService) {
|
|
66
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
67
|
+
if (document) return cssLanguageService.suggestSyntax(document, params.position, params.context);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.connection.onDocumentColor((params)=>{
|
|
71
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
72
|
+
if (cssLanguageService) {
|
|
73
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
74
|
+
if (document) return cssLanguageService.renderSyntaxColors(document);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
this.connection.onColorPresentation((params)=>{
|
|
78
|
+
const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
|
|
79
|
+
if (cssLanguageService) {
|
|
80
|
+
const document = this.documents.get(params.textDocument.uri);
|
|
81
|
+
if (document) return cssLanguageService.editSyntaxColors(document, params.color, params.range);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Make the text document manager listen on the connection
|
|
85
|
+
// for open, change and close text document events
|
|
86
|
+
this.documents.listen(this.connection);
|
|
87
|
+
}
|
|
88
|
+
async createLanguageService(workspaceURI) {
|
|
89
|
+
const { config, ...workspaceCSSLanguageServiceSettings } = await this.updateWorkspaceSettings(workspaceURI);
|
|
90
|
+
const workspaceConfig = this.workspaceConfigs[workspaceURI];
|
|
91
|
+
return new cssLanguageServiceSettings({
|
|
92
|
+
...workspaceCSSLanguageServiceSettings,
|
|
93
|
+
config: workspaceConfig
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async updateWorkspaceSettings(workspaceURI) {
|
|
97
|
+
const customWorkspaceSettings = await this.connection.workspace.getConfiguration({
|
|
98
|
+
scopeUri: workspaceURI,
|
|
99
|
+
section: 'masterCSS'
|
|
100
|
+
});
|
|
101
|
+
const resolvedSettings = extend(settings, this.customSettings, customWorkspaceSettings);
|
|
102
|
+
this.workspaceSettings[workspaceURI] = resolvedSettings;
|
|
103
|
+
this.updateWorkspaceConfig(workspaceURI);
|
|
104
|
+
return resolvedSettings;
|
|
105
|
+
}
|
|
106
|
+
updateWorkspaceConfig(workspaceURI) {
|
|
107
|
+
const workspaceSettings = this.workspaceSettings[workspaceURI];
|
|
108
|
+
const workspaceCWD = fileURLToPath(workspaceURI.replace('%3A', ':'));
|
|
109
|
+
let workspaceConfig;
|
|
110
|
+
if (typeof workspaceSettings.config === 'string') {
|
|
111
|
+
try {
|
|
112
|
+
workspaceConfig = exploreConfig({
|
|
113
|
+
name: workspaceSettings.config,
|
|
114
|
+
cwd: workspaceCWD
|
|
115
|
+
});
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.log('Config loading failed from', workspaceCWD);
|
|
118
|
+
console.error(e);
|
|
119
|
+
console.log('Fall back to default config');
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
workspaceConfig = workspaceSettings.config;
|
|
123
|
+
}
|
|
124
|
+
return this.workspaceConfigs[workspaceURI] = workspaceConfig;
|
|
125
|
+
}
|
|
126
|
+
// find the workspace language service for the given uri
|
|
127
|
+
findWorkspaceCSSLanguageService(uri) {
|
|
128
|
+
for(const workspaceURI in this.workspaceCSSLanguageService){
|
|
129
|
+
if (uri.startsWith(workspaceURI)) {
|
|
130
|
+
return this.workspaceCSSLanguageService[workspaceURI];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
findWorkspaceFolder(uri) {
|
|
135
|
+
const workspaceFolder = this.workspaceFolders.find((workspace)=>uri.startsWith(workspace.uri));
|
|
136
|
+
if (!workspaceFolder) {
|
|
137
|
+
throw new Error(`Workspace folder not found for ${uri}`);
|
|
138
|
+
}
|
|
139
|
+
return workspaceFolder;
|
|
140
|
+
}
|
|
141
|
+
// revalidate workspace language services by all documents
|
|
142
|
+
async revalidate() {
|
|
143
|
+
return await Promise.all(this.documents.all().map(async (textDocument)=>{
|
|
144
|
+
const workspaceFolder = this.findWorkspaceFolder(textDocument.uri);
|
|
145
|
+
return this.workspaceCSSLanguageService[workspaceFolder.uri] = await this.createLanguageService(workspaceFolder.uri);
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { CSSLanguageServer as default };
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var core = require('./core.cjs');
|
|
6
|
+
var settings = require('./settings.cjs');
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
exports.CSSLanguageServer = core;
|
|
11
|
+
exports.default = core;
|
|
12
|
+
exports.settings = settings;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default, default as CSSLanguageServer } from './core';
|
|
2
|
+
export { default as settings, type Settings } from './settings';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as CSSLanguageServer, default } from './core.mjs';
|
|
2
|
+
export { default as settings } from './settings.mjs';
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
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.
|
|
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.28","@master/css-language-service":"^2.0.0-rc.28","@master/css-explore-config":"^2.0.0-rc.28","@techor/extend":"^3.0.18","js-beautify":"^1.15.1","vscode-languageserver":"^7.0.0","vscode-languageserver-textdocument":"^1.0.11"},"devDependencies":{"@master/css-shared":"^2.0.0-rc.28"},"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.28"}
|
package/dist/serve.cjs
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
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
|
-
try {
|
|
77
|
-
customConfig = exploreConfig(settings.config || 'master.css', {
|
|
78
|
-
cwd: configCWD,
|
|
79
|
-
found: (basename)=>console.log`Loaded **${basename}**`
|
|
80
|
-
});
|
|
81
|
-
css$1 = new css.MasterCSS(customConfig);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.log('Config loading failed');
|
|
84
|
-
console.error(e);
|
|
85
|
-
css$1 = new css.MasterCSS();
|
|
86
|
-
console.log('Using default config');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
connection.onInitialize((params)=>{
|
|
91
|
-
const capabilities = params.capabilities;
|
|
92
|
-
// Does the client support the `workspace/configuration` request?
|
|
93
|
-
// If not, we fall back using global settings.
|
|
94
|
-
hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
95
|
-
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
96
|
-
!!(capabilities.textDocument && capabilities.textDocument.publishDiagnostics && capabilities.textDocument.publishDiagnostics.relatedInformation);
|
|
97
|
-
const result = {
|
|
98
|
-
capabilities: {
|
|
99
|
-
textDocumentSync: node.TextDocumentSyncKind.Incremental,
|
|
100
|
-
// Tell the client that this server supports code completion.
|
|
101
|
-
completionProvider: {
|
|
102
|
-
resolveProvider: true,
|
|
103
|
-
workDoneProgress: false,
|
|
104
|
-
triggerCharacters: [
|
|
105
|
-
':',
|
|
106
|
-
'@',
|
|
107
|
-
'\''
|
|
108
|
-
]
|
|
109
|
-
},
|
|
110
|
-
colorProvider: {},
|
|
111
|
-
hoverProvider: true
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
if (hasWorkspaceFolderCapability) {
|
|
115
|
-
result.capabilities.workspace = {
|
|
116
|
-
workspaceFolders: {
|
|
117
|
-
supported: true
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
});
|
|
123
|
-
connection.onInitialized(()=>{
|
|
124
|
-
if (hasConfigurationCapability) {
|
|
125
|
-
// Register for all configuration changes.
|
|
126
|
-
connection.client.register(node.DidChangeConfigurationNotification.type, undefined);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
connection.onCompletion((textDocumentPosition)=>{
|
|
130
|
-
if (settings.suggestions == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
131
|
-
const documentUri = textDocumentPosition.textDocument.uri;
|
|
132
|
-
const document = documents.get(documentUri);
|
|
133
|
-
const language = documentUri.substring(documentUri.lastIndexOf('.') + 1);
|
|
134
|
-
const position = textDocumentPosition.position;
|
|
135
|
-
if (document) {
|
|
136
|
-
const text = document.getText();
|
|
137
|
-
const positionIndex = document.offsetAt(position) ?? 0;
|
|
138
|
-
const startIndex = document.offsetAt({
|
|
139
|
-
line: position.line - 100,
|
|
140
|
-
character: 0
|
|
141
|
-
}) ?? 0;
|
|
142
|
-
const endIndex = document.offsetAt({
|
|
143
|
-
line: position.line + 100,
|
|
144
|
-
character: 0
|
|
145
|
-
}) ?? undefined;
|
|
146
|
-
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings.classMatch);
|
|
147
|
-
const lineText = document.getText({
|
|
148
|
-
start: {
|
|
149
|
-
line: position.line,
|
|
150
|
-
character: 0
|
|
151
|
-
},
|
|
152
|
-
end: {
|
|
153
|
-
line: position.line,
|
|
154
|
-
character: position.character
|
|
155
|
-
}
|
|
156
|
-
}).trim();
|
|
157
|
-
const lastInstance = cssLanguageService.getLastInstance(lineText, position, language);
|
|
158
|
-
if (lastInstance.isInstance == true && checkResult) {
|
|
159
|
-
return cssLanguageService.getCompletionItem(lastInstance.lastKey, lastInstance.triggerKey, lastInstance.isStart, lastInstance.language, css$1);
|
|
160
|
-
} else if (lastInstance.isInstance == true && cssLanguageService.checkConfigColorsBlock(document, textDocumentPosition.position) == true) {
|
|
161
|
-
return cssLanguageService.getConfigColorsCompletionItem(css$1);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return [];
|
|
166
|
-
});
|
|
167
|
-
connection.onCompletionResolve((item)=>{
|
|
168
|
-
return item;
|
|
169
|
-
});
|
|
170
|
-
connection.onDocumentColor(async (documentColor)=>{
|
|
171
|
-
if (settings == null) {
|
|
172
|
-
return [];
|
|
173
|
-
}
|
|
174
|
-
if (settings.previewColors && CheckFilesExclude(documentColor.textDocument.uri)) {
|
|
175
|
-
const documentUri = documentColor.textDocument.uri;
|
|
176
|
-
const document = documents.get(documentUri);
|
|
177
|
-
if (document) {
|
|
178
|
-
const text = document.getText() ?? '';
|
|
179
|
-
if (typeof document == 'undefined') {
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
const colorIndexes = await cssLanguageService.getDocumentColors(text, css$1);
|
|
183
|
-
const colorIndexSet = new Set();
|
|
184
|
-
const colorInformation = colorIndexes.filter((item)=>{
|
|
185
|
-
if (colorIndexSet.has(item.index.start)) {
|
|
186
|
-
return false;
|
|
187
|
-
} else {
|
|
188
|
-
colorIndexSet.add(item.index.start);
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
}).map((x)=>({
|
|
192
|
-
range: {
|
|
193
|
-
start: document.positionAt(x.index.start),
|
|
194
|
-
end: document.positionAt(x.index.end)
|
|
195
|
-
},
|
|
196
|
-
color: x.color
|
|
197
|
-
}));
|
|
198
|
-
return colorInformation;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return [];
|
|
202
|
-
});
|
|
203
|
-
connection.onColorPresentation((params)=>{
|
|
204
|
-
if (settings.previewColors && CheckFilesExclude(params.textDocument.uri)) {
|
|
205
|
-
const document = documents.get(params.textDocument.uri);
|
|
206
|
-
if (document) {
|
|
207
|
-
const text = document.getText();
|
|
208
|
-
const colorRender = [
|
|
209
|
-
'(?<=colors:\\s*{\\s*.*)([^}]*)}'
|
|
210
|
-
];
|
|
211
|
-
const positionIndex = document.offsetAt(params.range.start) ?? 0;
|
|
212
|
-
const startIndex = document.offsetAt({
|
|
213
|
-
line: params.range.start.line - 100,
|
|
214
|
-
character: 0
|
|
215
|
-
}) ?? 0;
|
|
216
|
-
const endIndex = document.offsetAt({
|
|
217
|
-
line: params.range.start.line + 100,
|
|
218
|
-
character: 0
|
|
219
|
-
}) ?? undefined;
|
|
220
|
-
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, colorRender);
|
|
221
|
-
return cssLanguageService.getColorPresentation(params, checkResult !== null);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return [];
|
|
225
|
-
});
|
|
226
|
-
connection.onHover((textDocumentPosition)=>{
|
|
227
|
-
if (settings.inspect == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
228
|
-
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
229
|
-
const position = textDocumentPosition.position;
|
|
230
|
-
if (document) {
|
|
231
|
-
const text = document.getText();
|
|
232
|
-
const positionIndex = document.offsetAt(position) ?? 0;
|
|
233
|
-
const startIndex = document.offsetAt({
|
|
234
|
-
line: position.line - 100,
|
|
235
|
-
character: 0
|
|
236
|
-
}) ?? 0;
|
|
237
|
-
const endIndex = document.offsetAt({
|
|
238
|
-
line: position.line + 100,
|
|
239
|
-
character: 0
|
|
240
|
-
}) ?? undefined;
|
|
241
|
-
const checkResult = cssLanguageService.positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings.classMatch);
|
|
242
|
-
if (checkResult) {
|
|
243
|
-
return cssLanguageService.doHover(checkResult.instanceContent, indexToRange(checkResult.index, document), customConfig);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return null;
|
|
248
|
-
});
|
|
249
|
-
function CheckFilesExclude(path) {
|
|
250
|
-
for (const exclude of settings.files.exclude){
|
|
251
|
-
if (minimatch.minimatch(path, exclude)) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
function indexToRange(index, document) {
|
|
258
|
-
return {
|
|
259
|
-
start: document.positionAt(index.start),
|
|
260
|
-
end: document.positionAt(index.end)
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
// Make the text document manager listen on the connection
|
|
264
|
-
// for open, change and close text document events
|
|
265
|
-
documents.listen(connection);
|
|
266
|
-
// Listen on the connection
|
|
267
|
-
connection.listen();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
module.exports = serve;
|
package/dist/serve.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function serve(): void;
|
package/dist/serve.mjs
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
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
|
-
try {
|
|
75
|
-
customConfig = exploreConfig(settings$1.config || 'master.css', {
|
|
76
|
-
cwd: configCWD,
|
|
77
|
-
found: (basename)=>console.log`Loaded **${basename}**`
|
|
78
|
-
});
|
|
79
|
-
css = new MasterCSS(customConfig);
|
|
80
|
-
} catch (e) {
|
|
81
|
-
console.log('Config loading failed');
|
|
82
|
-
console.error(e);
|
|
83
|
-
css = new MasterCSS();
|
|
84
|
-
console.log('Using default config');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
connection.onInitialize((params)=>{
|
|
89
|
-
const capabilities = params.capabilities;
|
|
90
|
-
// Does the client support the `workspace/configuration` request?
|
|
91
|
-
// If not, we fall back using global settings.
|
|
92
|
-
hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
93
|
-
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
94
|
-
!!(capabilities.textDocument && capabilities.textDocument.publishDiagnostics && capabilities.textDocument.publishDiagnostics.relatedInformation);
|
|
95
|
-
const result = {
|
|
96
|
-
capabilities: {
|
|
97
|
-
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
98
|
-
// Tell the client that this server supports code completion.
|
|
99
|
-
completionProvider: {
|
|
100
|
-
resolveProvider: true,
|
|
101
|
-
workDoneProgress: false,
|
|
102
|
-
triggerCharacters: [
|
|
103
|
-
':',
|
|
104
|
-
'@',
|
|
105
|
-
'\''
|
|
106
|
-
]
|
|
107
|
-
},
|
|
108
|
-
colorProvider: {},
|
|
109
|
-
hoverProvider: true
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
if (hasWorkspaceFolderCapability) {
|
|
113
|
-
result.capabilities.workspace = {
|
|
114
|
-
workspaceFolders: {
|
|
115
|
-
supported: true
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
});
|
|
121
|
-
connection.onInitialized(()=>{
|
|
122
|
-
if (hasConfigurationCapability) {
|
|
123
|
-
// Register for all configuration changes.
|
|
124
|
-
connection.client.register(DidChangeConfigurationNotification.type, undefined);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
connection.onCompletion((textDocumentPosition)=>{
|
|
128
|
-
if (settings$1.suggestions == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
129
|
-
const documentUri = textDocumentPosition.textDocument.uri;
|
|
130
|
-
const document = documents.get(documentUri);
|
|
131
|
-
const language = documentUri.substring(documentUri.lastIndexOf('.') + 1);
|
|
132
|
-
const position = textDocumentPosition.position;
|
|
133
|
-
if (document) {
|
|
134
|
-
const text = document.getText();
|
|
135
|
-
const positionIndex = document.offsetAt(position) ?? 0;
|
|
136
|
-
const startIndex = document.offsetAt({
|
|
137
|
-
line: position.line - 100,
|
|
138
|
-
character: 0
|
|
139
|
-
}) ?? 0;
|
|
140
|
-
const endIndex = document.offsetAt({
|
|
141
|
-
line: position.line + 100,
|
|
142
|
-
character: 0
|
|
143
|
-
}) ?? undefined;
|
|
144
|
-
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings$1.classMatch);
|
|
145
|
-
const lineText = document.getText({
|
|
146
|
-
start: {
|
|
147
|
-
line: position.line,
|
|
148
|
-
character: 0
|
|
149
|
-
},
|
|
150
|
-
end: {
|
|
151
|
-
line: position.line,
|
|
152
|
-
character: position.character
|
|
153
|
-
}
|
|
154
|
-
}).trim();
|
|
155
|
-
const lastInstance = getLastInstance(lineText, position, language);
|
|
156
|
-
if (lastInstance.isInstance == true && checkResult) {
|
|
157
|
-
return getCompletionItem(lastInstance.lastKey, lastInstance.triggerKey, lastInstance.isStart, lastInstance.language, css);
|
|
158
|
-
} else if (lastInstance.isInstance == true && checkConfigColorsBlock(document, textDocumentPosition.position) == true) {
|
|
159
|
-
return getConfigColorsCompletionItem(css);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return [];
|
|
164
|
-
});
|
|
165
|
-
connection.onCompletionResolve((item)=>{
|
|
166
|
-
return item;
|
|
167
|
-
});
|
|
168
|
-
connection.onDocumentColor(async (documentColor)=>{
|
|
169
|
-
if (settings$1 == null) {
|
|
170
|
-
return [];
|
|
171
|
-
}
|
|
172
|
-
if (settings$1.previewColors && CheckFilesExclude(documentColor.textDocument.uri)) {
|
|
173
|
-
const documentUri = documentColor.textDocument.uri;
|
|
174
|
-
const document = documents.get(documentUri);
|
|
175
|
-
if (document) {
|
|
176
|
-
const text = document.getText() ?? '';
|
|
177
|
-
if (typeof document == 'undefined') {
|
|
178
|
-
return [];
|
|
179
|
-
}
|
|
180
|
-
const colorIndexes = await getDocumentColors(text, css);
|
|
181
|
-
const colorIndexSet = new Set();
|
|
182
|
-
const colorInformation = colorIndexes.filter((item)=>{
|
|
183
|
-
if (colorIndexSet.has(item.index.start)) {
|
|
184
|
-
return false;
|
|
185
|
-
} else {
|
|
186
|
-
colorIndexSet.add(item.index.start);
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
}).map((x)=>({
|
|
190
|
-
range: {
|
|
191
|
-
start: document.positionAt(x.index.start),
|
|
192
|
-
end: document.positionAt(x.index.end)
|
|
193
|
-
},
|
|
194
|
-
color: x.color
|
|
195
|
-
}));
|
|
196
|
-
return colorInformation;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return [];
|
|
200
|
-
});
|
|
201
|
-
connection.onColorPresentation((params)=>{
|
|
202
|
-
if (settings$1.previewColors && CheckFilesExclude(params.textDocument.uri)) {
|
|
203
|
-
const document = documents.get(params.textDocument.uri);
|
|
204
|
-
if (document) {
|
|
205
|
-
const text = document.getText();
|
|
206
|
-
const colorRender = [
|
|
207
|
-
'(?<=colors:\\s*{\\s*.*)([^}]*)}'
|
|
208
|
-
];
|
|
209
|
-
const positionIndex = document.offsetAt(params.range.start) ?? 0;
|
|
210
|
-
const startIndex = document.offsetAt({
|
|
211
|
-
line: params.range.start.line - 100,
|
|
212
|
-
character: 0
|
|
213
|
-
}) ?? 0;
|
|
214
|
-
const endIndex = document.offsetAt({
|
|
215
|
-
line: params.range.start.line + 100,
|
|
216
|
-
character: 0
|
|
217
|
-
}) ?? undefined;
|
|
218
|
-
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, colorRender);
|
|
219
|
-
return getColorPresentation(params, checkResult !== null);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return [];
|
|
223
|
-
});
|
|
224
|
-
connection.onHover((textDocumentPosition)=>{
|
|
225
|
-
if (settings$1.inspect == true && CheckFilesExclude(textDocumentPosition.textDocument.uri)) {
|
|
226
|
-
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
227
|
-
const position = textDocumentPosition.position;
|
|
228
|
-
if (document) {
|
|
229
|
-
const text = document.getText();
|
|
230
|
-
const positionIndex = document.offsetAt(position) ?? 0;
|
|
231
|
-
const startIndex = document.offsetAt({
|
|
232
|
-
line: position.line - 100,
|
|
233
|
-
character: 0
|
|
234
|
-
}) ?? 0;
|
|
235
|
-
const endIndex = document.offsetAt({
|
|
236
|
-
line: position.line + 100,
|
|
237
|
-
character: 0
|
|
238
|
-
}) ?? undefined;
|
|
239
|
-
const checkResult = positionCheck(text.substring(startIndex, endIndex), positionIndex, startIndex, settings$1.classMatch);
|
|
240
|
-
if (checkResult) {
|
|
241
|
-
return doHover(checkResult.instanceContent, indexToRange(checkResult.index, document), customConfig);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return null;
|
|
246
|
-
});
|
|
247
|
-
function CheckFilesExclude(path) {
|
|
248
|
-
for (const exclude of settings$1.files.exclude){
|
|
249
|
-
if (minimatch(path, exclude)) {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
function indexToRange(index, document) {
|
|
256
|
-
return {
|
|
257
|
-
start: document.positionAt(index.start),
|
|
258
|
-
end: document.positionAt(index.end)
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
// Make the text document manager listen on the connection
|
|
262
|
-
// for open, change and close text document events
|
|
263
|
-
documents.listen(connection);
|
|
264
|
-
// Listen on the connection
|
|
265
|
-
connection.listen();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export { serve as default };
|