volar-service-markdown 0.0.30 → 0.0.32

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 (3) hide show
  1. package/index.d.ts +7 -11
  2. package/index.js +18 -11
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -1,15 +1,11 @@
1
- import { type ServicePlugin } from '@volar/language-service';
2
- import type { IMdLanguageService } from 'vscode-markdown-languageservice';
1
+ import type { DocumentSelector, Result, ServiceContext, ServicePlugin } from '@volar/language-service';
2
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
3
+ import type { DiagnosticOptions, IMdLanguageService } from 'vscode-markdown-languageservice';
3
4
  export interface Provide {
4
5
  'markdown/languageService': () => IMdLanguageService;
5
6
  }
6
- export interface CreateOptions {
7
- /**
8
- * The section to use for configuring validation options.
9
- *
10
- * @example 'markdown.validate'
11
- */
12
- configurationSection: string;
13
- }
14
- export declare function create(options: CreateOptions): ServicePlugin;
7
+ export declare function create({ documentSelector, getDiagnosticOptions, }?: {
8
+ documentSelector?: DocumentSelector;
9
+ getDiagnosticOptions?(document: TextDocument, context: ServiceContext): Result<DiagnosticOptions | undefined>;
10
+ }): ServicePlugin;
15
11
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -7,21 +7,20 @@ const vscode_markdown_languageservice_1 = require("vscode-markdown-languageservi
7
7
  const vscode_uri_1 = require("vscode-uri");
8
8
  const MarkdownIt = require("markdown-it");
9
9
  const md = new MarkdownIt();
10
- function isMarkdown(document) {
11
- return document.languageId === 'markdown';
12
- }
13
10
  function assert(condition, message) {
14
11
  if (!condition) {
15
12
  throw new Error(message);
16
13
  }
17
14
  }
18
- function create(options) {
15
+ function create({ documentSelector = ['markdown'], getDiagnosticOptions = async (_document, context) => {
16
+ return await context.env.getConfiguration?.('markdown.validate');
17
+ }, } = {}) {
19
18
  return {
20
19
  name: 'markdown',
21
20
  triggerCharacters: ['.', '/', '#'],
22
21
  create(context) {
23
22
  let lastProjectVersion;
24
- const { fs, getConfiguration, onDidChangeWatchedFiles } = context.env;
23
+ const { fs, onDidChangeWatchedFiles } = context.env;
25
24
  assert(fs, 'context.env.fs must be defined');
26
25
  assert(onDidChangeWatchedFiles, 'context.env.fs.onDidChangeWatchedFiles must be defined');
27
26
  const logger = {
@@ -73,7 +72,7 @@ function create(options) {
73
72
  },
74
73
  hasMarkdownDocument(resource) {
75
74
  const document = getTextDocument(resource.toString(), true);
76
- return Boolean(document && isMarkdown(document));
75
+ return Boolean(document && matchDocument(documentSelector, document));
77
76
  },
78
77
  onDidChangeMarkdownDocument: onDidChangeMarkdownDocument.event,
79
78
  onDidCreateMarkdownDocument: onDidCreateMarkdownDocument.event,
@@ -94,7 +93,7 @@ function create(options) {
94
93
  return { isDirectory: stat.type === 2 };
95
94
  }
96
95
  },
97
- workspaceFolders: []
96
+ workspaceFolders: [vscode_uri_1.URI.parse(context.env.workspaceFolder)],
98
97
  };
99
98
  const ls = (0, vscode_markdown_languageservice_1.createLanguageService)({
100
99
  logger,
@@ -120,7 +119,7 @@ function create(options) {
120
119
  const [_, sourceFile] = context.documents.getVirtualCodeByUri(uri);
121
120
  if (sourceFile?.generated) {
122
121
  for (const virtualCode of (0, language_service_1.forEachEmbeddedCode)(sourceFile.generated.code)) {
123
- if (virtualCode.languageId === 'markdown') {
122
+ if (matchDocument(documentSelector, virtualCode)) {
124
123
  const uri = context.documents.getVirtualCodeUri(sourceFile.id, virtualCode.id);
125
124
  const document = context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot);
126
125
  newVersions.set(document.uri, document);
@@ -129,7 +128,7 @@ function create(options) {
129
128
  }
130
129
  else if (sourceFile) {
131
130
  const document = context.documents.get(fileName, sourceFile.languageId, sourceFile.snapshot);
132
- if (document && isMarkdown(document)) {
131
+ if (document && matchDocument(documentSelector, document)) {
133
132
  newVersions.set(document.uri, document);
134
133
  }
135
134
  }
@@ -152,7 +151,7 @@ function create(options) {
152
151
  }
153
152
  };
154
153
  const prepare = (document) => {
155
- if (!isMarkdown(document)) {
154
+ if (!matchDocument(documentSelector, document)) {
156
155
  return false;
157
156
  }
158
157
  sync();
@@ -201,7 +200,7 @@ function create(options) {
201
200
  },
202
201
  async provideDiagnostics(document, token) {
203
202
  if (prepare(document)) {
204
- const configuration = await getConfiguration?.(options.configurationSection, document.uri);
203
+ const configuration = await getDiagnosticOptions(document, context);
205
204
  if (configuration) {
206
205
  return ls.computeDiagnostics(document, configuration, token);
207
206
  }
@@ -277,4 +276,12 @@ function create(options) {
277
276
  };
278
277
  }
279
278
  exports.create = create;
279
+ function matchDocument(selector, document) {
280
+ for (const sel of selector) {
281
+ if (sel === document.languageId || (typeof sel === 'object' && sel.language === document.languageId)) {
282
+ return true;
283
+ }
284
+ }
285
+ return false;
286
+ }
280
287
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-markdown",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "Integrate vscode-markdown-languageservice into Volar",
5
5
  "homepage": "https://github.com/volarjs/services/tree/master/packages/markdown",
6
6
  "bugs": "https://github.com/volarjs/services/issues",
@@ -34,12 +34,12 @@
34
34
  "vscode-languageserver-textdocument": "^1.0.11"
35
35
  },
36
36
  "peerDependencies": {
37
- "@volar/language-service": "~2.0.1"
37
+ "@volar/language-service": "~2.1.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@volar/language-service": {
41
41
  "optional": true
42
42
  }
43
43
  },
44
- "gitHead": "30c3cc3c76e90f75f14fe0c2fa4fd33b7ff06507"
44
+ "gitHead": "717049e7dcd5c30f451f6db8eb71eaba43f74c83"
45
45
  }