volar-service-css 0.0.11 → 0.0.12

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/out/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export interface Provide {
5
5
  'css/stylesheet': (document: TextDocument) => css.Stylesheet | undefined;
6
6
  'css/languageService': (languageId: string) => css.LanguageService | undefined;
7
7
  }
8
- declare const _default: () => Service<Provide>;
9
- export default _default;
8
+ export declare function create(): Service<Provide>;
9
+ export default create;
package/out/index.js CHANGED
@@ -23,228 +23,233 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.create = void 0;
26
27
  const path_1 = require("path");
27
28
  const css = __importStar(require("vscode-css-languageservice"));
28
29
  const vscode_uri_1 = require("vscode-uri");
29
- exports.default = () => (context) => {
30
- // https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/css-language-features/server/src/cssServer.ts#L97
31
- const triggerCharacters = ['/', '-', ':'];
32
- if (!context) {
33
- return { triggerCharacters };
34
- }
35
- let inited = false;
36
- const stylesheets = new WeakMap();
37
- const fileSystemProvider = {
38
- stat: async (uri) => await context.env.fs?.stat(uri) ?? {
39
- type: css.FileType.Unknown,
40
- ctime: 0,
41
- mtime: 0,
42
- size: 0,
43
- },
44
- readDirectory: async (uri) => context.env.fs?.readDirectory(uri) ?? [],
45
- };
46
- const documentContext = {
47
- resolveReference(ref, base) {
48
- if (ref.match(/^\w[\w\d+.-]*:/)) {
49
- // starts with a schema
50
- return ref;
51
- }
52
- if (ref[0] === '/') { // resolve absolute path against the current workspace folder
53
- return base + ref;
54
- }
55
- const baseUri = vscode_uri_1.URI.parse(base);
56
- const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
57
- return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
58
- },
59
- };
60
- const cssLs = css.getCSSLanguageService({
61
- fileSystemProvider,
62
- clientCapabilities: context.env.clientCapabilities,
63
- });
64
- const scssLs = css.getSCSSLanguageService({
65
- fileSystemProvider,
66
- clientCapabilities: context.env.clientCapabilities,
67
- });
68
- const lessLs = css.getLESSLanguageService({
69
- fileSystemProvider,
70
- clientCapabilities: context.env.clientCapabilities,
71
- });
72
- const postcssLs = {
73
- ...scssLs,
74
- doValidation: (document, stylesheet, documentSettings) => {
75
- let errors = scssLs.doValidation(document, stylesheet, documentSettings);
76
- errors = errors.filter(error => error.code !== 'css-semicolonexpected');
77
- errors = errors.filter(error => error.code !== 'css-ruleorselectorexpected');
78
- errors = errors.filter(error => error.code !== 'unknownAtRules');
79
- return errors;
80
- },
81
- };
82
- return {
83
- provide: {
84
- 'css/stylesheet': getStylesheet,
85
- 'css/languageService': getCssLs,
86
- },
87
- triggerCharacters,
88
- async provideCompletionItems(document, position) {
89
- return worker(document, async (stylesheet, cssLs) => {
90
- const settings = await context.env.getConfiguration?.(document.languageId);
91
- const cssResult = await cssLs.doComplete2(document, position, stylesheet, documentContext, settings?.completion);
92
- return cssResult;
93
- });
94
- },
95
- provideRenameRange(document, position) {
96
- return worker(document, (stylesheet, cssLs) => {
97
- return cssLs.prepareRename(document, position, stylesheet);
98
- });
99
- },
100
- provideRenameEdits(document, position, newName) {
101
- return worker(document, (stylesheet, cssLs) => {
102
- return cssLs.doRename(document, position, newName, stylesheet);
103
- });
104
- },
105
- provideCodeActions(document, range, context) {
106
- return worker(document, (stylesheet, cssLs) => {
107
- return cssLs.doCodeActions2(document, range, context, stylesheet);
108
- });
109
- },
110
- provideDefinition(document, position) {
111
- return worker(document, (stylesheet, cssLs) => {
112
- const location = cssLs.findDefinition(document, position, stylesheet);
113
- if (location) {
114
- return [{
115
- targetUri: location.uri,
116
- targetRange: location.range,
117
- targetSelectionRange: location.range,
118
- }];
30
+ function create() {
31
+ return (context) => {
32
+ // https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/css-language-features/server/src/cssServer.ts#L97
33
+ const triggerCharacters = ['/', '-', ':'];
34
+ if (!context) {
35
+ return { triggerCharacters };
36
+ }
37
+ let inited = false;
38
+ const stylesheets = new WeakMap();
39
+ const fileSystemProvider = {
40
+ stat: async (uri) => await context.env.fs?.stat(uri) ?? {
41
+ type: css.FileType.Unknown,
42
+ ctime: 0,
43
+ mtime: 0,
44
+ size: 0,
45
+ },
46
+ readDirectory: async (uri) => context.env.fs?.readDirectory(uri) ?? [],
47
+ };
48
+ const documentContext = {
49
+ resolveReference(ref, base) {
50
+ if (ref.match(/^\w[\w\d+.-]*:/)) {
51
+ // starts with a schema
52
+ return ref;
119
53
  }
120
- });
121
- },
122
- async provideDiagnostics(document) {
123
- return worker(document, async (stylesheet, cssLs) => {
124
- const settings = await context.env.getConfiguration?.(document.languageId);
125
- return cssLs.doValidation(document, stylesheet, settings);
126
- });
127
- },
128
- async provideHover(document, position) {
129
- return worker(document, async (stylesheet, cssLs) => {
130
- const settings = await context.env.getConfiguration?.(document.languageId);
131
- return cssLs.doHover(document, position, stylesheet, settings?.hover);
132
- });
133
- },
134
- provideReferences(document, position) {
135
- return worker(document, (stylesheet, cssLs) => {
136
- return cssLs.findReferences(document, position, stylesheet);
137
- });
138
- },
139
- provideDocumentHighlights(document, position) {
140
- return worker(document, (stylesheet, cssLs) => {
141
- return cssLs.findDocumentHighlights(document, position, stylesheet);
142
- });
143
- },
144
- async provideDocumentLinks(document) {
145
- return await worker(document, (stylesheet, cssLs) => {
146
- return cssLs.findDocumentLinks2(document, stylesheet, documentContext);
147
- });
148
- },
149
- provideDocumentSymbols(document) {
150
- return worker(document, (stylesheet, cssLs) => {
151
- return cssLs.findDocumentSymbols2(document, stylesheet);
152
- });
153
- },
154
- provideDocumentColors(document) {
155
- return worker(document, (stylesheet, cssLs) => {
156
- return cssLs.findDocumentColors(document, stylesheet);
157
- });
158
- },
159
- provideColorPresentations(document, color, range) {
160
- return worker(document, (stylesheet, cssLs) => {
161
- return cssLs.getColorPresentations(document, stylesheet, color, range);
162
- });
163
- },
164
- provideFoldingRanges(document) {
165
- return worker(document, (stylesheet, cssLs) => {
166
- return cssLs.getFoldingRanges(document, stylesheet);
167
- });
168
- },
169
- provideSelectionRanges(document, positions) {
170
- return worker(document, (stylesheet, cssLs) => {
171
- return cssLs.getSelectionRanges(document, positions, stylesheet);
172
- });
173
- },
174
- async provideDocumentFormattingEdits(document, formatRange, options) {
175
- return worker(document, async (_stylesheet, cssLs) => {
176
- const options_2 = await context.env.getConfiguration?.(document.languageId + '.format');
177
- if (options_2?.enable === false) {
178
- return;
54
+ if (ref[0] === '/') { // resolve absolute path against the current workspace folder
55
+ return base + ref;
179
56
  }
180
- return cssLs.format(document, formatRange, {
181
- ...options_2,
182
- ...options,
57
+ const baseUri = vscode_uri_1.URI.parse(base);
58
+ const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
59
+ return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
60
+ },
61
+ };
62
+ const cssLs = css.getCSSLanguageService({
63
+ fileSystemProvider,
64
+ clientCapabilities: context.env.clientCapabilities,
65
+ });
66
+ const scssLs = css.getSCSSLanguageService({
67
+ fileSystemProvider,
68
+ clientCapabilities: context.env.clientCapabilities,
69
+ });
70
+ const lessLs = css.getLESSLanguageService({
71
+ fileSystemProvider,
72
+ clientCapabilities: context.env.clientCapabilities,
73
+ });
74
+ const postcssLs = {
75
+ ...scssLs,
76
+ doValidation: (document, stylesheet, documentSettings) => {
77
+ let errors = scssLs.doValidation(document, stylesheet, documentSettings);
78
+ errors = errors.filter(error => error.code !== 'css-semicolonexpected');
79
+ errors = errors.filter(error => error.code !== 'css-ruleorselectorexpected');
80
+ errors = errors.filter(error => error.code !== 'unknownAtRules');
81
+ return errors;
82
+ },
83
+ };
84
+ return {
85
+ provide: {
86
+ 'css/stylesheet': getStylesheet,
87
+ 'css/languageService': getCssLs,
88
+ },
89
+ triggerCharacters,
90
+ async provideCompletionItems(document, position) {
91
+ return worker(document, async (stylesheet, cssLs) => {
92
+ const settings = await context.env.getConfiguration?.(document.languageId);
93
+ const cssResult = await cssLs.doComplete2(document, position, stylesheet, documentContext, settings?.completion);
94
+ return cssResult;
95
+ });
96
+ },
97
+ provideRenameRange(document, position) {
98
+ return worker(document, (stylesheet, cssLs) => {
99
+ return cssLs.prepareRename(document, position, stylesheet);
100
+ });
101
+ },
102
+ provideRenameEdits(document, position, newName) {
103
+ return worker(document, (stylesheet, cssLs) => {
104
+ return cssLs.doRename(document, position, newName, stylesheet);
105
+ });
106
+ },
107
+ provideCodeActions(document, range, context) {
108
+ return worker(document, (stylesheet, cssLs) => {
109
+ return cssLs.doCodeActions2(document, range, context, stylesheet);
110
+ });
111
+ },
112
+ provideDefinition(document, position) {
113
+ return worker(document, (stylesheet, cssLs) => {
114
+ const location = cssLs.findDefinition(document, position, stylesheet);
115
+ if (location) {
116
+ return [{
117
+ targetUri: location.uri,
118
+ targetRange: location.range,
119
+ targetSelectionRange: location.range,
120
+ }];
121
+ }
122
+ });
123
+ },
124
+ async provideDiagnostics(document) {
125
+ return worker(document, async (stylesheet, cssLs) => {
126
+ const settings = await context.env.getConfiguration?.(document.languageId);
127
+ return cssLs.doValidation(document, stylesheet, settings);
128
+ });
129
+ },
130
+ async provideHover(document, position) {
131
+ return worker(document, async (stylesheet, cssLs) => {
132
+ const settings = await context.env.getConfiguration?.(document.languageId);
133
+ return cssLs.doHover(document, position, stylesheet, settings?.hover);
134
+ });
135
+ },
136
+ provideReferences(document, position) {
137
+ return worker(document, (stylesheet, cssLs) => {
138
+ return cssLs.findReferences(document, position, stylesheet);
139
+ });
140
+ },
141
+ provideDocumentHighlights(document, position) {
142
+ return worker(document, (stylesheet, cssLs) => {
143
+ return cssLs.findDocumentHighlights(document, position, stylesheet);
144
+ });
145
+ },
146
+ async provideDocumentLinks(document) {
147
+ return await worker(document, (stylesheet, cssLs) => {
148
+ return cssLs.findDocumentLinks2(document, stylesheet, documentContext);
149
+ });
150
+ },
151
+ provideDocumentSymbols(document) {
152
+ return worker(document, (stylesheet, cssLs) => {
153
+ return cssLs.findDocumentSymbols2(document, stylesheet);
154
+ });
155
+ },
156
+ provideDocumentColors(document) {
157
+ return worker(document, (stylesheet, cssLs) => {
158
+ return cssLs.findDocumentColors(document, stylesheet);
159
+ });
160
+ },
161
+ provideColorPresentations(document, color, range) {
162
+ return worker(document, (stylesheet, cssLs) => {
163
+ return cssLs.getColorPresentations(document, stylesheet, color, range);
164
+ });
165
+ },
166
+ provideFoldingRanges(document) {
167
+ return worker(document, (stylesheet, cssLs) => {
168
+ return cssLs.getFoldingRanges(document, stylesheet);
169
+ });
170
+ },
171
+ provideSelectionRanges(document, positions) {
172
+ return worker(document, (stylesheet, cssLs) => {
173
+ return cssLs.getSelectionRanges(document, positions, stylesheet);
174
+ });
175
+ },
176
+ async provideDocumentFormattingEdits(document, formatRange, options) {
177
+ return worker(document, async (_stylesheet, cssLs) => {
178
+ const options_2 = await context.env.getConfiguration?.(document.languageId + '.format');
179
+ if (options_2?.enable === false) {
180
+ return;
181
+ }
182
+ return cssLs.format(document, formatRange, {
183
+ ...options_2,
184
+ ...options,
185
+ });
186
+ });
187
+ },
188
+ };
189
+ async function initCustomData() {
190
+ if (!inited) {
191
+ context?.env.onDidChangeConfiguration?.(async () => {
192
+ const customData = await getCustomData();
193
+ cssLs.setDataProviders(true, customData);
194
+ scssLs.setDataProviders(true, customData);
195
+ lessLs.setDataProviders(true, customData);
183
196
  });
184
- });
185
- },
186
- };
187
- async function initCustomData() {
188
- if (!inited) {
189
- context?.env.onDidChangeConfiguration?.(async () => {
190
197
  const customData = await getCustomData();
191
198
  cssLs.setDataProviders(true, customData);
192
199
  scssLs.setDataProviders(true, customData);
193
200
  lessLs.setDataProviders(true, customData);
194
- });
195
- const customData = await getCustomData();
196
- cssLs.setDataProviders(true, customData);
197
- scssLs.setDataProviders(true, customData);
198
- lessLs.setDataProviders(true, customData);
199
- inited = true;
200
- }
201
- }
202
- async function getCustomData() {
203
- const customData = await context?.env.getConfiguration?.('css.customData') ?? [];
204
- const newData = [];
205
- for (const customDataPath of customData) {
206
- try {
207
- const jsonPath = path_1.posix.resolve(customDataPath);
208
- newData.push(css.newCSSDataProvider(require(jsonPath)));
201
+ inited = true;
209
202
  }
210
- catch (error) {
211
- console.error(error);
203
+ }
204
+ async function getCustomData() {
205
+ const customData = await context?.env.getConfiguration?.('css.customData') ?? [];
206
+ const newData = [];
207
+ for (const customDataPath of customData) {
208
+ try {
209
+ const jsonPath = path_1.posix.resolve(customDataPath);
210
+ newData.push(css.newCSSDataProvider(require(jsonPath)));
211
+ }
212
+ catch (error) {
213
+ console.error(error);
214
+ }
212
215
  }
216
+ return newData;
213
217
  }
214
- return newData;
215
- }
216
- function getCssLs(lang) {
217
- switch (lang) {
218
- case 'css': return cssLs;
219
- case 'scss': return scssLs;
220
- case 'less': return lessLs;
221
- case 'postcss': return postcssLs;
218
+ function getCssLs(lang) {
219
+ switch (lang) {
220
+ case 'css': return cssLs;
221
+ case 'scss': return scssLs;
222
+ case 'less': return lessLs;
223
+ case 'postcss': return postcssLs;
224
+ }
222
225
  }
223
- }
224
- function getStylesheet(document) {
225
- const cache = stylesheets.get(document);
226
- if (cache) {
227
- const [cacheVersion, cacheStylesheet] = cache;
228
- if (cacheVersion === document.version) {
229
- return cacheStylesheet;
226
+ function getStylesheet(document) {
227
+ const cache = stylesheets.get(document);
228
+ if (cache) {
229
+ const [cacheVersion, cacheStylesheet] = cache;
230
+ if (cacheVersion === document.version) {
231
+ return cacheStylesheet;
232
+ }
230
233
  }
234
+ const cssLs = getCssLs(document.languageId);
235
+ if (!cssLs)
236
+ return;
237
+ const stylesheet = cssLs.parseStylesheet(document);
238
+ stylesheets.set(document, [document.version, stylesheet]);
239
+ return stylesheet;
231
240
  }
232
- const cssLs = getCssLs(document.languageId);
233
- if (!cssLs)
234
- return;
235
- const stylesheet = cssLs.parseStylesheet(document);
236
- stylesheets.set(document, [document.version, stylesheet]);
237
- return stylesheet;
238
- }
239
- async function worker(document, callback) {
240
- const stylesheet = getStylesheet(document);
241
- if (!stylesheet)
242
- return;
243
- const cssLs = getCssLs(document.languageId);
244
- if (!cssLs)
245
- return;
246
- await initCustomData();
247
- return callback(stylesheet, cssLs);
248
- }
249
- };
241
+ async function worker(document, callback) {
242
+ const stylesheet = getStylesheet(document);
243
+ if (!stylesheet)
244
+ return;
245
+ const cssLs = getCssLs(document.languageId);
246
+ if (!cssLs)
247
+ return;
248
+ await initCustomData();
249
+ return callback(stylesheet, cssLs);
250
+ }
251
+ };
252
+ }
253
+ exports.create = create;
254
+ exports.default = create;
250
255
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-css",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -27,5 +27,5 @@
27
27
  "optional": true
28
28
  }
29
29
  },
30
- "gitHead": "5be7c0c4fc41f4ebe3d8f3d272d3a0d8377973ad"
30
+ "gitHead": "7422c8d99d498df660ff9be3491545a5b45b3622"
31
31
  }