volar-service-html 0.0.3 → 0.0.5

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,9 +1,10 @@
1
1
  import type { Service } from '@volar/language-service';
2
2
  import * as html from 'vscode-html-languageservice';
3
- import { TextDocument } from 'vscode-languageserver-textdocument';
3
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
4
4
  export interface Provide {
5
5
  'html/htmlDocument': (document: TextDocument) => html.HTMLDocument | undefined;
6
6
  'html/languageService': () => html.LanguageService;
7
+ 'html/documentContext': () => html.DocumentContext;
7
8
  'html/updateCustomData': (extraData: html.IHTMLDataProvider[]) => void;
8
9
  }
9
10
  export declare function getHtmlDocument(document: TextDocument): html.HTMLDocument;
package/out/index.js CHANGED
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getHtmlDocument = void 0;
27
27
  const html = __importStar(require("vscode-html-languageservice"));
28
- const vscode = __importStar(require("vscode-languageserver-protocol"));
29
28
  const path = __importStar(require("path"));
29
+ const vscode_uri_1 = require("vscode-uri");
30
30
  const parserLs = html.getLanguageService();
31
31
  const htmlDocuments = new WeakMap();
32
32
  function getHtmlDocument(document) {
@@ -51,7 +51,33 @@ exports.default = (options = {}) => (context) => {
51
51
  let shouldUpdateCustomData = true;
52
52
  let customData = [];
53
53
  let extraData = [];
54
- const htmlLs = html.getLanguageService({ fileSystemProvider: context.env.fileSystemProvider });
54
+ const fileSystemProvider = {
55
+ stat: async (uri) => await context.env.fs?.stat(uri) ?? {
56
+ type: html.FileType.Unknown,
57
+ ctime: 0,
58
+ mtime: 0,
59
+ size: 0,
60
+ },
61
+ readDirectory: async (uri) => context.env.fs?.readDirectory(uri) ?? [],
62
+ };
63
+ const documentContext = {
64
+ resolveReference(ref, base) {
65
+ if (ref.match(/^\w[\w\d+.-]*:/)) {
66
+ // starts with a schema
67
+ return ref;
68
+ }
69
+ if (ref[0] === '/') { // resolve absolute path against the current workspace folder
70
+ return base + ref;
71
+ }
72
+ const baseUri = vscode_uri_1.URI.parse(base);
73
+ const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
74
+ return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
75
+ },
76
+ };
77
+ const htmlLs = html.getLanguageService({
78
+ fileSystemProvider,
79
+ clientCapabilities: context.env.clientCapabilities,
80
+ });
55
81
  context.env.onDidChangeConfiguration?.(() => {
56
82
  shouldUpdateCustomData = true;
57
83
  });
@@ -63,18 +89,14 @@ exports.default = (options = {}) => (context) => {
63
89
  }
64
90
  },
65
91
  'html/languageService': () => htmlLs,
92
+ 'html/documentContext': () => documentContext,
66
93
  'html/updateCustomData': updateExtraCustomData,
67
94
  },
68
95
  triggerCharacters,
69
96
  async provideCompletionItems(document, position) {
70
97
  return worker(document, async (htmlDocument) => {
71
98
  const configs = await context.env.getConfiguration?.('html.completion');
72
- if (context.env.documentContext) {
73
- return htmlLs.doComplete2(document, position, htmlDocument, context.env.documentContext, configs);
74
- }
75
- else {
76
- return htmlLs.doComplete(document, position, htmlDocument, configs);
77
- }
99
+ return htmlLs.doComplete2(document, position, htmlDocument, documentContext, configs);
78
100
  });
79
101
  },
80
102
  provideRenameRange(document, position) {
@@ -104,9 +126,7 @@ exports.default = (options = {}) => (context) => {
104
126
  },
105
127
  provideDocumentLinks(document) {
106
128
  return worker(document, () => {
107
- if (!context.env.documentContext)
108
- return;
109
- return htmlLs.findDocumentLinks(document, context.env.documentContext);
129
+ return htmlLs.findDocumentLinks(document, documentContext);
110
130
  });
111
131
  },
112
132
  provideDocumentSymbols(document) {
@@ -141,11 +161,14 @@ exports.default = (options = {}) => (context) => {
141
161
  const content = document.getText();
142
162
  if (endPos.character === 0 && endPos.line > 0 && endOffset !== content.length) {
143
163
  // if selection ends after a new line, exclude that new line
144
- const prevLineStart = document.offsetAt(vscode.Position.create(endPos.line - 1, 0));
164
+ const prevLineStart = document.offsetAt({ line: endPos.line - 1, character: 0 });
145
165
  while (isEOL(content, endOffset - 1) && endOffset > prevLineStart) {
146
166
  endOffset--;
147
167
  }
148
- formatRange = vscode.Range.create(formatRange.start, document.positionAt(endOffset));
168
+ formatRange = {
169
+ start: formatRange.start,
170
+ end: document.positionAt(endOffset),
171
+ };
149
172
  }
150
173
  }
151
174
  return htmlLs.format(document, formatRange, {
@@ -280,8 +303,16 @@ function isNewlineCharacter(charCode) {
280
303
  }
281
304
  function provideFileSymbolsInternal(document, node, symbols) {
282
305
  const name = nodeToName(node);
283
- const range = vscode.Range.create(document.positionAt(node.start), document.positionAt(node.end));
284
- const symbol = vscode.DocumentSymbol.create(name, undefined, vscode.SymbolKind.Field, range, range);
306
+ const range = {
307
+ start: document.positionAt(node.start),
308
+ end: document.positionAt(node.end),
309
+ };
310
+ const symbol = {
311
+ name,
312
+ kind: 8,
313
+ range,
314
+ selectionRange: range,
315
+ };
285
316
  symbols.push(symbol);
286
317
  node.children.forEach(child => {
287
318
  symbol.children ??= [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-html",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -14,8 +14,10 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "vscode-html-languageservice": "^5.0.4",
17
- "vscode-languageserver-protocol": "^3.17.3",
17
+ "vscode-uri": "^3.0.7"
18
+ },
19
+ "devDependencies": {
18
20
  "vscode-languageserver-textdocument": "^1.0.8"
19
21
  },
20
- "gitHead": "28896539331e31b4ef1064b6839ea0924d5d28d0"
22
+ "gitHead": "7b58234769e16ccb8eed0e6eb03f58ed24b7df40"
21
23
  }