volar-service-css 0.0.4 → 0.0.6

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.
Files changed (2) hide show
  1. package/out/index.js +40 -11
  2. package/package.json +4 -3
package/out/index.js CHANGED
@@ -23,8 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const path = __importStar(require("path"));
26
+ const path_1 = require("path");
27
27
  const css = __importStar(require("vscode-css-languageservice"));
28
+ const vscode_uri_1 = require("vscode-uri");
28
29
  exports.default = () => (context) => {
29
30
  // https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/css-language-features/server/src/cssServer.ts#L97
30
31
  const triggerCharacters = ['/', '-', ':'];
@@ -33,9 +34,41 @@ exports.default = () => (context) => {
33
34
  }
34
35
  let inited = false;
35
36
  const stylesheets = new WeakMap();
36
- const cssLs = css.getCSSLanguageService({ fileSystemProvider: context.env.fileSystemProvider });
37
- const scssLs = css.getSCSSLanguageService({ fileSystemProvider: context.env.fileSystemProvider });
38
- const lessLs = css.getLESSLanguageService({ fileSystemProvider: context.env.fileSystemProvider });
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
+ });
39
72
  const postcssLs = {
40
73
  ...scssLs,
41
74
  doValidation: (document, stylesheet, documentSettings) => {
@@ -55,9 +88,7 @@ exports.default = () => (context) => {
55
88
  async provideCompletionItems(document, position) {
56
89
  return worker(document, async (stylesheet, cssLs) => {
57
90
  const settings = await context.env.getConfiguration?.(document.languageId);
58
- const cssResult = context.env.documentContext
59
- ? await cssLs.doComplete2(document, position, stylesheet, context.env.documentContext, settings?.completion)
60
- : await cssLs.doComplete(document, position, stylesheet, settings?.completion);
91
+ const cssResult = await cssLs.doComplete2(document, position, stylesheet, documentContext, settings?.completion);
61
92
  return cssResult;
62
93
  });
63
94
  },
@@ -112,9 +143,7 @@ exports.default = () => (context) => {
112
143
  },
113
144
  async provideDocumentLinks(document) {
114
145
  return await worker(document, (stylesheet, cssLs) => {
115
- if (!context.env.documentContext)
116
- return;
117
- return cssLs.findDocumentLinks2(document, stylesheet, context.env.documentContext);
146
+ return cssLs.findDocumentLinks2(document, stylesheet, documentContext);
118
147
  });
119
148
  },
120
149
  provideDocumentSymbols(document) {
@@ -175,7 +204,7 @@ exports.default = () => (context) => {
175
204
  const newData = [];
176
205
  for (const customDataPath of customData) {
177
206
  try {
178
- const jsonPath = path.resolve(customDataPath);
207
+ const jsonPath = path_1.posix.resolve(customDataPath);
179
208
  newData.push(css.newCSSDataProvider(require(jsonPath)));
180
209
  }
181
210
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-css",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,10 +13,11 @@
13
13
  "directory": "packages/css"
14
14
  },
15
15
  "dependencies": {
16
- "vscode-css-languageservice": "^6.2.3"
16
+ "vscode-css-languageservice": "^6.2.3",
17
+ "vscode-uri": "^3.0.7"
17
18
  },
18
19
  "devDependencies": {
19
20
  "vscode-languageserver-textdocument": "^1.0.8"
20
21
  },
21
- "gitHead": "f5d49495d6698761f4df8c9ef2747cc01fc777d6"
22
+ "gitHead": "a4ee5d50ec7d4c37c7b24e019ee0ee2d701bb8bb"
22
23
  }