volar-service-css 0.0.17 → 0.0.19

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