@master/css-language-server 2.0.0-rc.61 → 2.0.0-rc.63

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
@@ -15,6 +15,7 @@ class CSSLanguageServer {
15
15
  customSettings;
16
16
  workspaceFolders;
17
17
  workspaces;
18
+ globalWorkspace;
18
19
  documents;
19
20
  initializing;
20
21
  clientCapabilities;
@@ -25,7 +26,12 @@ class CSSLanguageServer {
25
26
  this.connection = connection;
26
27
  this.customSettings = customSettings;
27
28
  this.workspaceFolders = [];
28
- this.workspaces = [];
29
+ this.workspaces = new Map();
30
+ this.globalWorkspace = {
31
+ uri: '',
32
+ openedTextDocuments: [],
33
+ languageServiceSettings: this.settings
34
+ };
29
35
  this.clientCapabilities = {};
30
36
  this.disposables = [];
31
37
  this.documents = new node.TextDocuments(vscodeLanguageserverTextdocument.TextDocument);
@@ -52,15 +58,6 @@ class CSSLanguageServer {
52
58
  this.clientCapabilities = params.capabilities;
53
59
  if (params.workspaceFolders?.length) {
54
60
  this.workspaceFolders = params.workspaceFolders;
55
- } else {
56
- /**
57
- * @deprecated — in favour of workspaceFolders
58
- */ if (params.rootUri) {
59
- this.workspaceFolders.push({
60
- name: '',
61
- uri: params.rootUri
62
- });
63
- }
64
61
  }
65
62
  return {
66
63
  capabilities: CSSLanguageService.SERVER_CAPABILITIES
@@ -69,7 +66,7 @@ class CSSLanguageServer {
69
66
  async onHover(params) {
70
67
  await this.init();
71
68
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
72
- if (workspace.languageService) {
69
+ if (workspace?.languageService) {
73
70
  const document = this.documents.get(params.textDocument.uri);
74
71
  if (document) return workspace.languageService.inspectSyntax(document, params.position);
75
72
  }
@@ -77,7 +74,7 @@ class CSSLanguageServer {
77
74
  async onCompletion(params) {
78
75
  await this.init();
79
76
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
80
- if (workspace.languageService) {
77
+ if (workspace?.languageService) {
81
78
  const document = this.documents.get(params.textDocument.uri);
82
79
  if (document) return workspace.languageService.suggestSyntax(document, params.position, params.context);
83
80
  }
@@ -85,7 +82,7 @@ class CSSLanguageServer {
85
82
  async onDocumentColor(params) {
86
83
  await this.init();
87
84
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
88
- if (workspace.languageService) {
85
+ if (workspace?.languageService) {
89
86
  const document = this.documents.get(params.textDocument.uri);
90
87
  if (document) return workspace.languageService.renderSyntaxColors(document);
91
88
  }
@@ -93,7 +90,7 @@ class CSSLanguageServer {
93
90
  async onColorPresentation(params) {
94
91
  await this.init();
95
92
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
96
- if (workspace.languageService) {
93
+ if (workspace?.languageService) {
97
94
  const document = this.documents.get(params.textDocument.uri);
98
95
  if (document) return workspace.languageService.editSyntaxColors(document, params.color, params.range);
99
96
  }
@@ -103,7 +100,7 @@ class CSSLanguageServer {
103
100
  const workspace = this.findClosestWorkspace(params.document.uri);
104
101
  if (!workspace || workspace.openedTextDocuments.includes(params.document)) return;
105
102
  if (!workspace.openedTextDocuments.length) {
106
- this.initLanguageService(workspace);
103
+ this.initWorkspaceLanguageService(workspace);
107
104
  }
108
105
  workspace.openedTextDocuments.push(params.document);
109
106
  }
@@ -150,7 +147,11 @@ class CSSLanguageServer {
150
147
  const resolvedWorkspaceDirectories = new Set([
151
148
  workspaceFolderCWD
152
149
  ]);
153
- this.console.info(`Registered workspace folder ${workspaceFolderURI}`);
150
+ if (workspaceFolderCWD) {
151
+ this.console.info(`Registered workspace folder ${workspaceFolderURI}`);
152
+ } else {
153
+ this.console.info(`Registered global workspace folder`);
154
+ }
154
155
  if (workspaces === 'auto') {
155
156
  (await glob('**/master.css.*', {
156
157
  cwd: workspaceFolderCWD,
@@ -173,25 +174,31 @@ class CSSLanguageServer {
173
174
  resolvedWorkspaceDirectories.forEach(async (workspaceDir)=>{
174
175
  const workspaceURI = vscodeUri.URI.file(workspaceDir).toString();
175
176
  this.console.info(`Added workspace ${workspaceURI}`);
176
- this.workspaces.push({
177
+ this.workspaces.set(workspaceURI, {
177
178
  uri: workspaceURI,
178
179
  openedTextDocuments: [],
179
180
  languageServiceSettings
180
181
  });
181
182
  });
182
183
  }
183
- initLanguageService(workspace) {
184
+ initWorkspaceLanguageService(workspace) {
184
185
  let workspaceConfig;
185
- try {
186
- workspaceConfig = exploreConfig({
187
- cwd: vscodeUri.URI.parse(workspace.uri).fsPath,
188
- found: undefined
189
- });
190
- } catch (e) {
191
- this.console.info(`Failed to load config from ${workspace}`);
192
- this.console.error(e);
186
+ if (workspace !== this.globalWorkspace) {
187
+ try {
188
+ workspaceConfig = exploreConfig({
189
+ cwd: workspace.uri && vscodeUri.URI.parse(workspace.uri).fsPath,
190
+ found: undefined
191
+ });
192
+ } catch (e) {
193
+ this.console.info(`Failed to load config from ${workspace}`);
194
+ this.console.error(e);
195
+ }
196
+ if (workspaceConfig) {
197
+ this.console.info(`Initialized workspace ${workspaceConfig ? '(with config file)' : ''} ${workspace.uri}`);
198
+ } else {
199
+ this.console.info(`Initialized workspace ${workspace.uri}`);
200
+ }
193
201
  }
194
- this.console.info(`Initialized workspace ${workspaceConfig ? '(with config file)' : ''} ${workspace.uri}`);
195
202
  workspace.languageService = new CSSLanguageService({
196
203
  ...workspace.languageServiceSettings,
197
204
  config: workspaceConfig
@@ -203,18 +210,15 @@ class CSSLanguageServer {
203
210
  }
204
211
  findClosestWorkspace(textDocumentURI) {
205
212
  let foundWorkspace;
206
- for (const workspace of this.workspaces){
207
- if (textDocumentURI.startsWith(workspace.uri) && (!foundWorkspace || workspace.uri.length > foundWorkspace.uri.length)) {
213
+ for (const [uri, workspace] of this.workspaces){
214
+ if (!uri) continue;
215
+ if (textDocumentURI.startsWith(uri) && (!foundWorkspace || uri.length > (foundWorkspace.uri || '').length)) {
208
216
  foundWorkspace = workspace;
209
217
  }
210
218
  }
211
- if (process.env.DEBUG && !foundWorkspace) {
212
- this.console.info(`This is an external document ${textDocumentURI} assigned to the first workspace`);
213
- }
214
- return foundWorkspace || this.workspaces[0];
215
- }
216
- getWorkspace(uri) {
217
- return Array.from(this.workspaces).find((workspace)=>workspace.uri === uri);
219
+ if (foundWorkspace) return foundWorkspace;
220
+ this.console.info(`This is an external document ${textDocumentURI} with the global workspace`);
221
+ return this.globalWorkspace;
218
222
  }
219
223
  stop() {
220
224
  this.connection.sendNotification('masterCSS/dispose');
package/dist/core.d.ts CHANGED
@@ -12,7 +12,8 @@ export default class CSSLanguageServer {
12
12
  connection: Connection;
13
13
  customSettings?: Settings | undefined;
14
14
  workspaceFolders: WorkspaceFolder[];
15
- workspaces: Workspace[];
15
+ workspaces: Map<string, Workspace>;
16
+ globalWorkspace: Workspace;
16
17
  documents: TextDocuments<TextDocument>;
17
18
  initializing?: Promise<void>;
18
19
  clientCapabilities: ClientCapabilities;
@@ -34,9 +35,8 @@ export default class CSSLanguageServer {
34
35
  onDidSave(params: TextDocumentChangeEvent<TextDocument>): Promise<void>;
35
36
  onDidChangeConfiguration({ settings }: DidChangeConfigurationParams): Promise<void>;
36
37
  private initWorkspaceFolder;
37
- initLanguageService(workspace: Workspace): void;
38
+ initWorkspaceLanguageService(workspace: Workspace): void;
38
39
  destroyLanguageService(workspace: Workspace): void;
39
40
  findClosestWorkspace(textDocumentURI: string): Workspace;
40
- getWorkspace(uri: string): Workspace | undefined;
41
41
  stop(): void;
42
42
  }
package/dist/core.mjs CHANGED
@@ -13,6 +13,7 @@ class CSSLanguageServer {
13
13
  customSettings;
14
14
  workspaceFolders;
15
15
  workspaces;
16
+ globalWorkspace;
16
17
  documents;
17
18
  initializing;
18
19
  clientCapabilities;
@@ -23,7 +24,12 @@ class CSSLanguageServer {
23
24
  this.connection = connection;
24
25
  this.customSettings = customSettings;
25
26
  this.workspaceFolders = [];
26
- this.workspaces = [];
27
+ this.workspaces = new Map();
28
+ this.globalWorkspace = {
29
+ uri: '',
30
+ openedTextDocuments: [],
31
+ languageServiceSettings: this.settings
32
+ };
27
33
  this.clientCapabilities = {};
28
34
  this.disposables = [];
29
35
  this.documents = new TextDocuments(TextDocument);
@@ -50,15 +56,6 @@ class CSSLanguageServer {
50
56
  this.clientCapabilities = params.capabilities;
51
57
  if (params.workspaceFolders?.length) {
52
58
  this.workspaceFolders = params.workspaceFolders;
53
- } else {
54
- /**
55
- * @deprecated — in favour of workspaceFolders
56
- */ if (params.rootUri) {
57
- this.workspaceFolders.push({
58
- name: '',
59
- uri: params.rootUri
60
- });
61
- }
62
59
  }
63
60
  return {
64
61
  capabilities: SERVER_CAPABILITIES
@@ -67,7 +64,7 @@ class CSSLanguageServer {
67
64
  async onHover(params) {
68
65
  await this.init();
69
66
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
70
- if (workspace.languageService) {
67
+ if (workspace?.languageService) {
71
68
  const document = this.documents.get(params.textDocument.uri);
72
69
  if (document) return workspace.languageService.inspectSyntax(document, params.position);
73
70
  }
@@ -75,7 +72,7 @@ class CSSLanguageServer {
75
72
  async onCompletion(params) {
76
73
  await this.init();
77
74
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
78
- if (workspace.languageService) {
75
+ if (workspace?.languageService) {
79
76
  const document = this.documents.get(params.textDocument.uri);
80
77
  if (document) return workspace.languageService.suggestSyntax(document, params.position, params.context);
81
78
  }
@@ -83,7 +80,7 @@ class CSSLanguageServer {
83
80
  async onDocumentColor(params) {
84
81
  await this.init();
85
82
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
86
- if (workspace.languageService) {
83
+ if (workspace?.languageService) {
87
84
  const document = this.documents.get(params.textDocument.uri);
88
85
  if (document) return workspace.languageService.renderSyntaxColors(document);
89
86
  }
@@ -91,7 +88,7 @@ class CSSLanguageServer {
91
88
  async onColorPresentation(params) {
92
89
  await this.init();
93
90
  const workspace = this.findClosestWorkspace(params.textDocument.uri);
94
- if (workspace.languageService) {
91
+ if (workspace?.languageService) {
95
92
  const document = this.documents.get(params.textDocument.uri);
96
93
  if (document) return workspace.languageService.editSyntaxColors(document, params.color, params.range);
97
94
  }
@@ -101,7 +98,7 @@ class CSSLanguageServer {
101
98
  const workspace = this.findClosestWorkspace(params.document.uri);
102
99
  if (!workspace || workspace.openedTextDocuments.includes(params.document)) return;
103
100
  if (!workspace.openedTextDocuments.length) {
104
- this.initLanguageService(workspace);
101
+ this.initWorkspaceLanguageService(workspace);
105
102
  }
106
103
  workspace.openedTextDocuments.push(params.document);
107
104
  }
@@ -148,7 +145,11 @@ class CSSLanguageServer {
148
145
  const resolvedWorkspaceDirectories = new Set([
149
146
  workspaceFolderCWD
150
147
  ]);
151
- this.console.info(`Registered workspace folder ${workspaceFolderURI}`);
148
+ if (workspaceFolderCWD) {
149
+ this.console.info(`Registered workspace folder ${workspaceFolderURI}`);
150
+ } else {
151
+ this.console.info(`Registered global workspace folder`);
152
+ }
152
153
  if (workspaces === 'auto') {
153
154
  (await glob('**/master.css.*', {
154
155
  cwd: workspaceFolderCWD,
@@ -171,25 +172,31 @@ class CSSLanguageServer {
171
172
  resolvedWorkspaceDirectories.forEach(async (workspaceDir)=>{
172
173
  const workspaceURI = URI.file(workspaceDir).toString();
173
174
  this.console.info(`Added workspace ${workspaceURI}`);
174
- this.workspaces.push({
175
+ this.workspaces.set(workspaceURI, {
175
176
  uri: workspaceURI,
176
177
  openedTextDocuments: [],
177
178
  languageServiceSettings
178
179
  });
179
180
  });
180
181
  }
181
- initLanguageService(workspace) {
182
+ initWorkspaceLanguageService(workspace) {
182
183
  let workspaceConfig;
183
- try {
184
- workspaceConfig = exploreConfig({
185
- cwd: URI.parse(workspace.uri).fsPath,
186
- found: undefined
187
- });
188
- } catch (e) {
189
- this.console.info(`Failed to load config from ${workspace}`);
190
- this.console.error(e);
184
+ if (workspace !== this.globalWorkspace) {
185
+ try {
186
+ workspaceConfig = exploreConfig({
187
+ cwd: workspace.uri && URI.parse(workspace.uri).fsPath,
188
+ found: undefined
189
+ });
190
+ } catch (e) {
191
+ this.console.info(`Failed to load config from ${workspace}`);
192
+ this.console.error(e);
193
+ }
194
+ if (workspaceConfig) {
195
+ this.console.info(`Initialized workspace ${workspaceConfig ? '(with config file)' : ''} ${workspace.uri}`);
196
+ } else {
197
+ this.console.info(`Initialized workspace ${workspace.uri}`);
198
+ }
191
199
  }
192
- this.console.info(`Initialized workspace ${workspaceConfig ? '(with config file)' : ''} ${workspace.uri}`);
193
200
  workspace.languageService = new CSSLanguageService({
194
201
  ...workspace.languageServiceSettings,
195
202
  config: workspaceConfig
@@ -201,18 +208,15 @@ class CSSLanguageServer {
201
208
  }
202
209
  findClosestWorkspace(textDocumentURI) {
203
210
  let foundWorkspace;
204
- for (const workspace of this.workspaces){
205
- if (textDocumentURI.startsWith(workspace.uri) && (!foundWorkspace || workspace.uri.length > foundWorkspace.uri.length)) {
211
+ for (const [uri, workspace] of this.workspaces){
212
+ if (!uri) continue;
213
+ if (textDocumentURI.startsWith(uri) && (!foundWorkspace || uri.length > (foundWorkspace.uri || '').length)) {
206
214
  foundWorkspace = workspace;
207
215
  }
208
216
  }
209
- if (process.env.DEBUG && !foundWorkspace) {
210
- this.console.info(`This is an external document ${textDocumentURI} assigned to the first workspace`);
211
- }
212
- return foundWorkspace || this.workspaces[0];
213
- }
214
- getWorkspace(uri) {
215
- return Array.from(this.workspaces).find((workspace)=>workspace.uri === uri);
217
+ if (foundWorkspace) return foundWorkspace;
218
+ this.console.info(`This is an external document ${textDocumentURI} with the global workspace`);
219
+ return this.globalWorkspace;
216
220
  }
217
221
  stop() {
218
222
  this.connection.sendNotification('masterCSS/dispose');
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","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.61","@master/css-explore-config":"^2.0.0-rc.61","@master/css-language-service":"^2.0.0-rc.61","@techor/extend":"^3.2.0","fast-glob":"^3.3.2","js-beautify":"^1.15.1","nanoid":"^5.0.6","vscode-languageserver":"^9.0.1","vscode-languageserver-textdocument":"^1.0.11","vscode-uri":"^3.0.8"},"devDependencies":{"shared":"^2.0.0-rc.61"},"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":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.61"}
1
+ {"name":"@master/css-language-server","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","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.63","@master/css-explore-config":"^2.0.0-rc.63","@master/css-language-service":"^2.0.0-rc.63","@techor/extend":"^3.2.0","fast-glob":"^3.3.2","js-beautify":"^1.15.1","nanoid":"^5.0.6","vscode-languageserver":"^9.0.1","vscode-languageserver-textdocument":"^1.0.11","vscode-uri":"^3.0.8"},"devDependencies":{"shared":"^2.0.0-rc.63"},"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":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.63"}