@master/css-language-server 2.0.0-rc.34 → 2.0.0-rc.36

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 CHANGED
@@ -4,7 +4,7 @@ var node = require('vscode-languageserver/node');
4
4
  var vscodeLanguageserverTextdocument = require('vscode-languageserver-textdocument');
5
5
  var path = require('path');
6
6
  var url = require('url');
7
- var cssLanguageServiceSettings = require('@master/css-language-service');
7
+ var CSSLanguageService = require('@master/css-language-service');
8
8
  var exploreConfig = require('@master/css-explore-config');
9
9
  var extend = require('@techor/extend');
10
10
  var settings = require('./settings.cjs');
@@ -17,24 +17,44 @@ class CSSLanguageServer {
17
17
  workspaceConfigs;
18
18
  connection;
19
19
  documents;
20
+ disposables;
20
21
  constructor(customSettings){
21
22
  this.customSettings = customSettings;
22
23
  this.workspaceFolders = [];
23
24
  this.workspaceCSSLanguageService = {};
24
25
  this.workspaceSettings = {};
25
26
  this.workspaceConfigs = {};
26
- this.connection = node.createConnection(node.ProposedFeatures.all);
27
+ this.disposables = [];
28
+ if (process.argv.includes('--stdio')) {
29
+ console.log = (...args)=>{
30
+ console.warn(...args);
31
+ };
32
+ this.connection = node.createConnection(process.stdin, process.stdout);
33
+ } else {
34
+ this.connection = node.createConnection(new node.IPCMessageReader(process), new node.IPCMessageWriter(process));
35
+ }
27
36
  this.documents = new node.TextDocuments(vscodeLanguageserverTextdocument.TextDocument);
28
- this.connection.onDidChangeConfiguration(this.revalidate);
29
- this.documents.onDidSave(async (change)=>{
37
+ this.disposables.push(this.documents.onDidSave(async (change)=>{
30
38
  // 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));
39
+ const name = path.parse(change.document.uri).name;
40
+ if (name === 'master.css' || name.endsWith('.css')) {
41
+ // const cssLanguageService = this.findWorkspaceCSSLanguageService(change.document.uri)
42
+ // const workspaceFolder = this.findWorkspaceFolder(change.document.uri)
43
+ // if (cssLanguageService)
44
+ // cssLanguageService.css.refresh(this.updateWorkspaceConfig(workspaceFolder.uri))
45
+ this.connection.sendRequest('masterCSS/restart', {
46
+ title: 'Updating configuration...'
47
+ });
35
48
  }
36
- });
37
- this.connection.onInitialize((params)=>{
49
+ }), // Make the text document manager listen on the connection
50
+ // for open, change and close text document events
51
+ this.documents.listen(this.connection), this.connection.onDidChangeConfiguration(({ settings })=>{
52
+ if (settings?.masterCSS) {
53
+ this.connection.sendNotification('masterCSS/globalSettingsChanged', settings.masterCSS);
54
+ this.customSettings = settings.masterCSS;
55
+ this.reload();
56
+ }
57
+ }), this.connection.onInitialize((params)=>{
38
58
  if (params.workspaceFolders?.length) {
39
59
  this.workspaceFolders = params.workspaceFolders;
40
60
  } else {
@@ -46,51 +66,45 @@ class CSSLanguageServer {
46
66
  }
47
67
  }
48
68
  return {
49
- capabilities: cssLanguageServiceSettings.SERVER_CAPABILITIES
69
+ capabilities: CSSLanguageService.SERVER_CAPABILITIES
50
70
  };
51
- });
52
- this.connection.onInitialized(async ()=>{
71
+ }), this.connection.onInitialized(async ()=>{
53
72
  await this.workspaceFolders.map(async (folder)=>{
54
73
  this.workspaceCSSLanguageService[folder.uri] = await this.createLanguageService(folder.uri);
55
74
  });
56
75
  this.connection.client.register(node.DidChangeConfigurationNotification.type, undefined);
57
- });
58
- this.connection.onHover((params)=>{
76
+ }), this.connection.onHover((params)=>{
59
77
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
60
78
  if (cssLanguageService) {
61
79
  const document = this.documents.get(params.textDocument.uri);
62
80
  if (document) return cssLanguageService.inspectSyntax(document, params.position);
63
81
  }
64
- });
65
- this.connection.onCompletion((params)=>{
82
+ }), this.connection.onCompletion((params)=>{
66
83
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
67
84
  if (cssLanguageService) {
68
85
  const document = this.documents.get(params.textDocument.uri);
69
86
  if (document) return cssLanguageService.suggestSyntax(document, params.position, params.context);
70
87
  }
71
- });
72
- this.connection.onDocumentColor((params)=>{
88
+ }), this.connection.onDocumentColor((params)=>{
73
89
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
74
90
  if (cssLanguageService) {
75
91
  const document = this.documents.get(params.textDocument.uri);
76
92
  if (document) return cssLanguageService.renderSyntaxColors(document);
77
93
  }
78
- });
79
- this.connection.onColorPresentation((params)=>{
94
+ }), this.connection.onColorPresentation((params)=>{
80
95
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
81
96
  if (cssLanguageService) {
82
97
  const document = this.documents.get(params.textDocument.uri);
83
98
  if (document) return cssLanguageService.editSyntaxColors(document, params.color, params.range);
84
99
  }
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);
100
+ }), this.connection.onShutdown(()=>{
101
+ this.dispose();
102
+ }));
89
103
  }
90
104
  async createLanguageService(workspaceURI) {
91
105
  const { config, ...workspaceCSSLanguageServiceSettings } = await this.updateWorkspaceSettings(workspaceURI);
92
106
  const workspaceConfig = this.workspaceConfigs[workspaceURI];
93
- return new cssLanguageServiceSettings({
107
+ return new CSSLanguageService({
94
108
  ...workspaceCSSLanguageServiceSettings,
95
109
  config: workspaceConfig
96
110
  });
@@ -141,12 +155,23 @@ class CSSLanguageServer {
141
155
  return workspaceFolder;
142
156
  }
143
157
  // revalidate workspace language services by all documents
144
- async revalidate() {
145
- return await Promise.all(this.documents.all().map(async (textDocument)=>{
158
+ async revalidate(documents = this.documents.all()) {
159
+ this.connection.sendNotification('masterCSS/revalidate');
160
+ return await Promise.all(documents.map(async (textDocument)=>{
146
161
  const workspaceFolder = this.findWorkspaceFolder(textDocument.uri);
147
162
  return this.workspaceCSSLanguageService[workspaceFolder.uri] = await this.createLanguageService(workspaceFolder.uri);
148
163
  }));
149
164
  }
165
+ async reload() {
166
+ await Promise.all(Object.keys(this.workspaceCSSLanguageService).map(async (workspaceURI)=>{
167
+ this.workspaceCSSLanguageService[workspaceURI] = await this.createLanguageService(workspaceURI);
168
+ }));
169
+ }
170
+ dispose() {
171
+ this.connection.sendNotification('masterCSS/dispose');
172
+ this.disposables.forEach((disposable)=>disposable.dispose());
173
+ this.disposables.length = 0;
174
+ }
150
175
  }
151
176
 
152
177
  module.exports = CSSLanguageServer;
package/dist/core.d.ts CHANGED
@@ -9,13 +9,16 @@ export default class CSSLanguageServer {
9
9
  workspaceCSSLanguageService: Record<string, CSSLanguageService>;
10
10
  workspaceSettings: Record<string, Settings>;
11
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")._>;
12
+ connection: import("vscode-languageserver/node").Connection;
13
13
  documents: TextDocuments<TextDocument>;
14
+ private disposables;
14
15
  constructor(customSettings?: Settings | undefined);
15
16
  createLanguageService(workspaceURI: string): Promise<CSSLanguageService>;
16
17
  updateWorkspaceSettings(workspaceURI: string): Promise<Settings>;
17
18
  updateWorkspaceConfig(workspaceURI: string): Config | undefined;
18
19
  findWorkspaceCSSLanguageService(uri: string): CSSLanguageService | undefined;
19
20
  findWorkspaceFolder(uri: string): WorkspaceFolder;
20
- revalidate(): Promise<CSSLanguageService[]>;
21
+ revalidate(documents?: TextDocument[]): Promise<CSSLanguageService[]>;
22
+ reload(): Promise<void>;
23
+ dispose(): void;
21
24
  }
package/dist/core.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { createConnection, ProposedFeatures, TextDocuments, DidChangeConfigurationNotification } from 'vscode-languageserver/node';
1
+ import { createConnection, IPCMessageReader, IPCMessageWriter, TextDocuments, DidChangeConfigurationNotification } from 'vscode-languageserver/node';
2
2
  import { TextDocument } from 'vscode-languageserver-textdocument';
3
3
  import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- import cssLanguageServiceSettings, { SERVER_CAPABILITIES } from '@master/css-language-service';
5
+ import CSSLanguageService, { SERVER_CAPABILITIES } from '@master/css-language-service';
6
6
  import exploreConfig from '@master/css-explore-config';
7
7
  import extend from '@techor/extend';
8
8
  import settings from './settings.mjs';
@@ -15,24 +15,44 @@ class CSSLanguageServer {
15
15
  workspaceConfigs;
16
16
  connection;
17
17
  documents;
18
+ disposables;
18
19
  constructor(customSettings){
19
20
  this.customSettings = customSettings;
20
21
  this.workspaceFolders = [];
21
22
  this.workspaceCSSLanguageService = {};
22
23
  this.workspaceSettings = {};
23
24
  this.workspaceConfigs = {};
24
- this.connection = createConnection(ProposedFeatures.all);
25
+ this.disposables = [];
26
+ if (process.argv.includes('--stdio')) {
27
+ console.log = (...args)=>{
28
+ console.warn(...args);
29
+ };
30
+ this.connection = createConnection(process.stdin, process.stdout);
31
+ } else {
32
+ this.connection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
33
+ }
25
34
  this.documents = new TextDocuments(TextDocument);
26
- this.connection.onDidChangeConfiguration(this.revalidate);
27
- this.documents.onDidSave(async (change)=>{
35
+ this.disposables.push(this.documents.onDidSave(async (change)=>{
28
36
  // 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));
37
+ const name = path.parse(change.document.uri).name;
38
+ if (name === 'master.css' || name.endsWith('.css')) {
39
+ // const cssLanguageService = this.findWorkspaceCSSLanguageService(change.document.uri)
40
+ // const workspaceFolder = this.findWorkspaceFolder(change.document.uri)
41
+ // if (cssLanguageService)
42
+ // cssLanguageService.css.refresh(this.updateWorkspaceConfig(workspaceFolder.uri))
43
+ this.connection.sendRequest('masterCSS/restart', {
44
+ title: 'Updating configuration...'
45
+ });
33
46
  }
34
- });
35
- this.connection.onInitialize((params)=>{
47
+ }), // Make the text document manager listen on the connection
48
+ // for open, change and close text document events
49
+ this.documents.listen(this.connection), this.connection.onDidChangeConfiguration(({ settings })=>{
50
+ if (settings?.masterCSS) {
51
+ this.connection.sendNotification('masterCSS/globalSettingsChanged', settings.masterCSS);
52
+ this.customSettings = settings.masterCSS;
53
+ this.reload();
54
+ }
55
+ }), this.connection.onInitialize((params)=>{
36
56
  if (params.workspaceFolders?.length) {
37
57
  this.workspaceFolders = params.workspaceFolders;
38
58
  } else {
@@ -46,49 +66,43 @@ class CSSLanguageServer {
46
66
  return {
47
67
  capabilities: SERVER_CAPABILITIES
48
68
  };
49
- });
50
- this.connection.onInitialized(async ()=>{
69
+ }), this.connection.onInitialized(async ()=>{
51
70
  await this.workspaceFolders.map(async (folder)=>{
52
71
  this.workspaceCSSLanguageService[folder.uri] = await this.createLanguageService(folder.uri);
53
72
  });
54
73
  this.connection.client.register(DidChangeConfigurationNotification.type, undefined);
55
- });
56
- this.connection.onHover((params)=>{
74
+ }), this.connection.onHover((params)=>{
57
75
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
58
76
  if (cssLanguageService) {
59
77
  const document = this.documents.get(params.textDocument.uri);
60
78
  if (document) return cssLanguageService.inspectSyntax(document, params.position);
61
79
  }
62
- });
63
- this.connection.onCompletion((params)=>{
80
+ }), this.connection.onCompletion((params)=>{
64
81
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
65
82
  if (cssLanguageService) {
66
83
  const document = this.documents.get(params.textDocument.uri);
67
84
  if (document) return cssLanguageService.suggestSyntax(document, params.position, params.context);
68
85
  }
69
- });
70
- this.connection.onDocumentColor((params)=>{
86
+ }), this.connection.onDocumentColor((params)=>{
71
87
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
72
88
  if (cssLanguageService) {
73
89
  const document = this.documents.get(params.textDocument.uri);
74
90
  if (document) return cssLanguageService.renderSyntaxColors(document);
75
91
  }
76
- });
77
- this.connection.onColorPresentation((params)=>{
92
+ }), this.connection.onColorPresentation((params)=>{
78
93
  const cssLanguageService = this.findWorkspaceCSSLanguageService(params.textDocument.uri);
79
94
  if (cssLanguageService) {
80
95
  const document = this.documents.get(params.textDocument.uri);
81
96
  if (document) return cssLanguageService.editSyntaxColors(document, params.color, params.range);
82
97
  }
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);
98
+ }), this.connection.onShutdown(()=>{
99
+ this.dispose();
100
+ }));
87
101
  }
88
102
  async createLanguageService(workspaceURI) {
89
103
  const { config, ...workspaceCSSLanguageServiceSettings } = await this.updateWorkspaceSettings(workspaceURI);
90
104
  const workspaceConfig = this.workspaceConfigs[workspaceURI];
91
- return new cssLanguageServiceSettings({
105
+ return new CSSLanguageService({
92
106
  ...workspaceCSSLanguageServiceSettings,
93
107
  config: workspaceConfig
94
108
  });
@@ -139,12 +153,23 @@ class CSSLanguageServer {
139
153
  return workspaceFolder;
140
154
  }
141
155
  // revalidate workspace language services by all documents
142
- async revalidate() {
143
- return await Promise.all(this.documents.all().map(async (textDocument)=>{
156
+ async revalidate(documents = this.documents.all()) {
157
+ this.connection.sendNotification('masterCSS/revalidate');
158
+ return await Promise.all(documents.map(async (textDocument)=>{
144
159
  const workspaceFolder = this.findWorkspaceFolder(textDocument.uri);
145
160
  return this.workspaceCSSLanguageService[workspaceFolder.uri] = await this.createLanguageService(workspaceFolder.uri);
146
161
  }));
147
162
  }
163
+ async reload() {
164
+ await Promise.all(Object.keys(this.workspaceCSSLanguageService).map(async (workspaceURI)=>{
165
+ this.workspaceCSSLanguageService[workspaceURI] = await this.createLanguageService(workspaceURI);
166
+ }));
167
+ }
168
+ dispose() {
169
+ this.connection.sendNotification('masterCSS/dispose');
170
+ this.disposables.forEach((disposable)=>disposable.dispose());
171
+ this.disposables.length = 0;
172
+ }
148
173
  }
149
174
 
150
175
  export { CSSLanguageServer as default };
package/dist/settings.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var cssLanguageServiceSettings = require('@master/css-language-service');
3
+ var CSSLanguageService = require('@master/css-language-service');
4
4
 
5
5
  const settings = {
6
- ...cssLanguageServiceSettings,
6
+ ...CSSLanguageService.settings,
7
7
  config: 'master.css'
8
8
  };
9
9
 
package/dist/settings.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import cssLanguageServiceSettings from '@master/css-language-service';
1
+ import { settings as settings$1 } from '@master/css-language-service';
2
2
 
3
3
  const settings = {
4
- ...cssLanguageServiceSettings,
4
+ ...settings$1,
5
5
  config: 'master.css'
6
6
  };
7
7
 
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.34","@master/css-language-service":"^2.0.0-rc.34","@master/css-explore-config":"^2.0.0-rc.34","@techor/extend":"^3.0.20","js-beautify":"^1.15.1","vscode-languageserver":"^7.0.0","vscode-languageserver-textdocument":"^1.0.11"},"devDependencies":{"@master/css-shared":"^2.0.0-rc.34"},"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.34"}
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.36","@master/css-explore-config":"^2.0.0-rc.36","@master/css-language-service":"^2.0.0-rc.36","@techor/extend":"^3.0.22","js-beautify":"^1.15.1","vscode-languageserver":"^9.0.1","vscode-languageserver-textdocument":"^1.0.11"},"devDependencies":{"@master/css-shared":"^2.0.0-rc.36"},"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.36"}