volar-service-html 0.0.0 → 0.0.1

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,6 +1,10 @@
1
- import type { ServiceContext, Service } from '@volar/language-service';
1
+ import type { ServiceContext, Service, InjectionKey } from '@volar/language-service';
2
2
  import * as html from 'vscode-html-languageservice';
3
3
  import { TextDocument } from 'vscode-languageserver-textdocument';
4
+ export declare const rulesInjectionKey: InjectionKey<{
5
+ htmlDocument: html.HTMLDocument;
6
+ languageService: html.LanguageService;
7
+ }>;
4
8
  export declare function getHtmlDocument(document: TextDocument): html.HTMLDocument;
5
9
  export interface PluginInstance extends ReturnType<Service> {
6
10
  getHtmlLs: () => html.LanguageService;
package/out/index.js CHANGED
@@ -23,12 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHtmlDocument = void 0;
26
+ exports.getHtmlDocument = exports.rulesInjectionKey = void 0;
27
27
  const html = __importStar(require("vscode-html-languageservice"));
28
28
  const vscode = __importStar(require("vscode-languageserver-protocol"));
29
29
  const path = __importStar(require("path"));
30
30
  const parserLs = html.getLanguageService();
31
31
  const htmlDocuments = new WeakMap();
32
+ exports.rulesInjectionKey = Symbol();
32
33
  function getHtmlDocument(document) {
33
34
  const cache = htmlDocuments.get(document);
34
35
  if (cache) {
@@ -56,18 +57,22 @@ exports.default = (options = {}) => (context) => {
56
57
  shouldUpdateCustomData = true;
57
58
  });
58
59
  return {
59
- triggerCharacters,
60
- async resolveRuleContext(context) {
61
- if (options.validLang === 'html') {
62
- await worker(context.document, (htmlDocument) => {
63
- context.html = {
64
- document: htmlDocument,
60
+ rules: {
61
+ provide: {
62
+ [exports.rulesInjectionKey](document) {
63
+ if (document.languageId !== (options.validLang ?? 'html'))
64
+ return;
65
+ const htmlDocument = getHtmlDocument(document);
66
+ if (!htmlDocument)
67
+ return;
68
+ return {
69
+ htmlDocument,
65
70
  languageService: htmlLs,
66
71
  };
67
- });
68
- }
69
- return context;
72
+ },
73
+ },
70
74
  },
75
+ triggerCharacters,
71
76
  getHtmlLs: () => htmlLs,
72
77
  updateCustomData: updateExtraCustomData,
73
78
  async provideCompletionItems(document, position) {
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "volar-service-html",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
7
- "rules.d.ts",
8
7
  "out/**/*.js",
9
8
  "out/**/*.d.ts"
10
9
  ],
@@ -26,5 +25,5 @@
26
25
  "optional": true
27
26
  }
28
27
  },
29
- "gitHead": "1011561ac4bbf79c53c3b80c27692569bf861519"
28
+ "gitHead": "5bf5152f076f25cb1ddbc7aa6978a8d1c7009fd6"
30
29
  }
package/rules.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import * as html from 'vscode-html-languageservice';
2
-
3
- declare module '@volar/language-service' {
4
- interface RuleContext {
5
- html?: {
6
- document: html.HTMLDocument;
7
- languageService: html.LanguageService;
8
- }
9
- }
10
- }