volar-service-html 0.0.2 → 0.0.4

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,17 +1,14 @@
1
- import { ServiceContext, Service, InjectionKey } from '@volar/language-service';
1
+ import type { Service } from '@volar/language-service';
2
2
  import * as html from 'vscode-html-languageservice';
3
- import { TextDocument } from 'vscode-languageserver-textdocument';
4
- export declare const injectionKeys: {
5
- htmlDocument: InjectionKey<[TextDocument], html.HTMLDocument>;
6
- languageService: InjectionKey<[], html.LanguageService>;
7
- };
8
- export declare function getHtmlDocument(document: TextDocument): html.HTMLDocument;
9
- export interface PluginInstance extends ReturnType<Service> {
10
- getHtmlLs: () => html.LanguageService;
11
- updateCustomData(extraData: html.IHTMLDataProvider[]): void;
3
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
4
+ export interface Provide {
5
+ 'html/htmlDocument': (document: TextDocument) => html.HTMLDocument | undefined;
6
+ 'html/languageService': () => html.LanguageService;
7
+ 'html/updateCustomData': (extraData: html.IHTMLDataProvider[]) => void;
12
8
  }
9
+ export declare function getHtmlDocument(document: TextDocument): html.HTMLDocument;
13
10
  declare const _default: (options?: {
14
11
  validLang?: string;
15
12
  disableCustomData?: boolean;
16
- }) => (context: ServiceContext | undefined) => PluginInstance;
13
+ }) => Service<Provide>;
17
14
  export default _default;
package/out/index.js CHANGED
@@ -23,17 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHtmlDocument = exports.injectionKeys = void 0;
27
- const language_service_1 = require("@volar/language-service");
26
+ exports.getHtmlDocument = void 0;
28
27
  const html = __importStar(require("vscode-html-languageservice"));
29
- const vscode = __importStar(require("vscode-languageserver-protocol"));
30
28
  const path = __importStar(require("path"));
31
29
  const parserLs = html.getLanguageService();
32
30
  const htmlDocuments = new WeakMap();
33
- exports.injectionKeys = {
34
- htmlDocument: 'html/htmlDocument',
35
- languageService: 'html/languageService',
36
- };
37
31
  function getHtmlDocument(document) {
38
32
  const cache = htmlDocuments.get(document);
39
33
  if (cache) {
@@ -62,16 +56,15 @@ exports.default = (options = {}) => (context) => {
62
56
  });
63
57
  return {
64
58
  provide: {
65
- ...(0, language_service_1.defineProvide)(exports.injectionKeys.htmlDocument, document => {
59
+ 'html/htmlDocument': (document) => {
66
60
  if (document.languageId === (options.validLang ?? 'html')) {
67
61
  return getHtmlDocument(document);
68
62
  }
69
- }),
70
- ...(0, language_service_1.defineProvide)(exports.injectionKeys.languageService, () => htmlLs),
63
+ },
64
+ 'html/languageService': () => htmlLs,
65
+ 'html/updateCustomData': updateExtraCustomData,
71
66
  },
72
67
  triggerCharacters,
73
- getHtmlLs: () => htmlLs,
74
- updateCustomData: updateExtraCustomData,
75
68
  async provideCompletionItems(document, position) {
76
69
  return worker(document, async (htmlDocument) => {
77
70
  const configs = await context.env.getConfiguration?.('html.completion');
@@ -147,11 +140,14 @@ exports.default = (options = {}) => (context) => {
147
140
  const content = document.getText();
148
141
  if (endPos.character === 0 && endPos.line > 0 && endOffset !== content.length) {
149
142
  // if selection ends after a new line, exclude that new line
150
- const prevLineStart = document.offsetAt(vscode.Position.create(endPos.line - 1, 0));
143
+ const prevLineStart = document.offsetAt({ line: endPos.line - 1, character: 0 });
151
144
  while (isEOL(content, endOffset - 1) && endOffset > prevLineStart) {
152
145
  endOffset--;
153
146
  }
154
- formatRange = vscode.Range.create(formatRange.start, document.positionAt(endOffset));
147
+ formatRange = {
148
+ start: formatRange.start,
149
+ end: document.positionAt(endOffset),
150
+ };
155
151
  }
156
152
  }
157
153
  return htmlLs.format(document, formatRange, {
@@ -286,8 +282,16 @@ function isNewlineCharacter(charCode) {
286
282
  }
287
283
  function provideFileSymbolsInternal(document, node, symbols) {
288
284
  const name = nodeToName(node);
289
- const range = vscode.Range.create(document.positionAt(node.start), document.positionAt(node.end));
290
- const symbol = vscode.DocumentSymbol.create(name, undefined, vscode.SymbolKind.Field, range, range);
285
+ const range = {
286
+ start: document.positionAt(node.start),
287
+ end: document.positionAt(node.end),
288
+ };
289
+ const symbol = {
290
+ name,
291
+ kind: 8,
292
+ range,
293
+ selectionRange: range,
294
+ };
291
295
  symbols.push(symbol);
292
296
  node.children.forEach(child => {
293
297
  symbol.children ??= [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-html",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,17 +13,10 @@
13
13
  "directory": "packages/html"
14
14
  },
15
15
  "dependencies": {
16
- "vscode-html-languageservice": "^5.0.4",
17
- "vscode-languageserver-protocol": "^3.17.3",
18
- "vscode-languageserver-textdocument": "^1.0.8"
19
- },
20
- "peerDependencies": {
21
- "@volar/language-service": "*"
16
+ "vscode-html-languageservice": "^5.0.4"
22
17
  },
23
- "peerDependenciesMeta": {
24
- "@volar/language-service": {
25
- "optional": true
26
- }
18
+ "devDependencies": {
19
+ "vscode-languageserver-textdocument": "^1.0.8"
27
20
  },
28
- "gitHead": "19482084693c7349f461dc75ec52ee6917739c51"
21
+ "gitHead": "f5d49495d6698761f4df8c9ef2747cc01fc777d6"
29
22
  }