@astrojs/language-server 2.15.0 → 2.15.3

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.
@@ -9,16 +9,22 @@ export declare const SUPPORTED_FRONTMATTER_EXTENSIONS: {
9
9
  export declare const SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS: string[];
10
10
  export declare const frontmatterRE: RegExp;
11
11
  export type CollectionConfig = {
12
- folder: URI;
13
- config: {
14
- collections: {
15
- hasSchema: boolean;
16
- name: string;
17
- }[];
18
- entries: Record<string, string>;
19
- };
12
+ reload: (folders: {
13
+ uri: string;
14
+ }[]) => void;
15
+ configs: {
16
+ folder: URI;
17
+ config: CollectionConfigInstance;
18
+ }[];
20
19
  };
21
- export declare function getFrontmatterLanguagePlugin(collectionConfigs: CollectionConfig[]): LanguagePlugin<URI, FrontmatterHolder>;
20
+ export type CollectionConfigInstance = {
21
+ collections: {
22
+ hasSchema: boolean;
23
+ name: string;
24
+ }[];
25
+ entries: Record<string, string>;
26
+ };
27
+ export declare function getFrontmatterLanguagePlugin(collectionConfig: CollectionConfig): LanguagePlugin<URI, FrontmatterHolder>;
22
28
  export declare class FrontmatterHolder implements VirtualCode {
23
29
  fileName: string;
24
30
  languageId: string;
@@ -8,14 +8,14 @@ exports.SUPPORTED_FRONTMATTER_EXTENSIONS = { md: 'markdown', mdx: 'mdx', mdoc: '
8
8
  exports.SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS = Object.keys(exports.SUPPORTED_FRONTMATTER_EXTENSIONS);
9
9
  const SUPPORTED_FRONTMATTER_EXTENSIONS_VALUES = Object.values(exports.SUPPORTED_FRONTMATTER_EXTENSIONS);
10
10
  exports.frontmatterRE = /^---(.*?)^---/ms;
11
- function getCollectionName(collectionConfigs, fileURI) {
12
- for (const collection of collectionConfigs) {
11
+ function getCollectionName(collectionConfig, fileURI) {
12
+ for (const collection of collectionConfig.configs) {
13
13
  if (collection.config.entries[fileURI]) {
14
14
  return collection.config.entries[fileURI];
15
15
  }
16
16
  }
17
17
  }
18
- function getFrontmatterLanguagePlugin(collectionConfigs) {
18
+ function getFrontmatterLanguagePlugin(collectionConfig) {
19
19
  return {
20
20
  getLanguageId(scriptId) {
21
21
  const fileType = exports.SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS.find((ext) => scriptId.path.endsWith(`.${ext}`));
@@ -25,7 +25,7 @@ function getFrontmatterLanguagePlugin(collectionConfigs) {
25
25
  },
26
26
  createVirtualCode(scriptId, languageId, snapshot) {
27
27
  if (SUPPORTED_FRONTMATTER_EXTENSIONS_VALUES.includes(languageId)) {
28
- return new FrontmatterHolder(scriptId.fsPath.replace(/\\/g, '/'), languageId, snapshot, getCollectionName(collectionConfigs,
28
+ return new FrontmatterHolder(scriptId.fsPath.replace(/\\/g, '/'), languageId, snapshot, getCollectionName(collectionConfig,
29
29
  // The scriptId here is encoded and somewhat normalized, as such we can't use it directly to compare with
30
30
  // the file URLs in the collection config entries that Astro generates.
31
31
  decodeURIComponent(scriptId.toString()).toLowerCase()));
@@ -1,5 +1,5 @@
1
1
  import { type Connection, type LanguagePlugin } from '@volar/language-server/node';
2
2
  import { URI } from 'vscode-uri';
3
3
  import { type CollectionConfig } from './core/frontmatterHolders.js';
4
- export declare function getLanguagePlugins(collectionConfigs: CollectionConfig[]): LanguagePlugin<URI, import("@volar/language-server/node").VirtualCode>[];
5
- export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript'), collectionConfigs: CollectionConfig[]): import("@volar/language-server/node").LanguageServicePlugin<any>[];
4
+ export declare function getLanguagePlugins(collectionConfig: CollectionConfig): LanguagePlugin<URI, import("@volar/language-server/node").VirtualCode>[];
5
+ export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript'), collectionConfig: CollectionConfig): import("@volar/language-server/node").LanguageServicePlugin<any>[];
@@ -19,18 +19,16 @@ const html_js_1 = require("./plugins/html.js");
19
19
  const index_js_1 = require("./plugins/typescript-addons/index.js");
20
20
  const index_js_2 = require("./plugins/typescript/index.js");
21
21
  const yaml_js_1 = require("./plugins/yaml.js");
22
- function getLanguagePlugins(collectionConfigs) {
22
+ function getLanguagePlugins(collectionConfig) {
23
23
  const languagePlugins = [
24
24
  (0, core_1.getAstroLanguagePlugin)(),
25
25
  (0, vue_js_1.getVueLanguagePlugin)(),
26
26
  (0, svelte_js_1.getSvelteLanguagePlugin)(),
27
+ (0, frontmatterHolders_js_1.getFrontmatterLanguagePlugin)(collectionConfig),
27
28
  ];
28
- if (collectionConfigs.length) {
29
- languagePlugins.push((0, frontmatterHolders_js_1.getFrontmatterLanguagePlugin)(collectionConfigs));
30
- }
31
29
  return languagePlugins;
32
30
  }
33
- function getLanguageServicePlugins(connection, ts, collectionConfigs) {
31
+ function getLanguageServicePlugins(connection, ts, collectionConfig) {
34
32
  const LanguageServicePlugins = [
35
33
  (0, html_js_1.create)(),
36
34
  (0, volar_service_css_1.create)(),
@@ -40,10 +38,8 @@ function getLanguageServicePlugins(connection, ts, collectionConfigs) {
40
38
  (0, index_js_1.create)(),
41
39
  (0, astro_js_1.create)(ts),
42
40
  getPrettierService(),
41
+ (0, yaml_js_1.create)(collectionConfig),
43
42
  ];
44
- if (collectionConfigs.length) {
45
- LanguageServicePlugins.push((0, yaml_js_1.create)(collectionConfigs));
46
- }
47
43
  return LanguageServicePlugins;
48
44
  function getPrettierService() {
49
45
  let prettier;
@@ -17,12 +17,18 @@ connection.onInitialize((params) => {
17
17
  }
18
18
  const { typescript, diagnosticMessages } = (0, node_1.loadTsdkByPath)(tsdk, params.locale);
19
19
  contentIntellisenseEnabled = params.initializationOptions?.contentIntellisense ?? false;
20
- let collectionConfigs = [];
21
- if (contentIntellisenseEnabled) {
22
- // The vast majority of clients support workspaceFolders, but notably our tests currently don't
23
- // Ref: https://github.com/volarjs/volar.js/issues/229
24
- const folders = params.workspaceFolders ?? (params.rootUri ? [{ uri: params.rootUri }] : []) ?? [];
25
- collectionConfigs = folders.flatMap((folder) => {
20
+ const collectionConfig = {
21
+ reload(folders) {
22
+ this.configs = loadCollectionConfig(folders);
23
+ },
24
+ configs: contentIntellisenseEnabled
25
+ ? loadCollectionConfig(
26
+ // The vast majority of clients support workspaceFolders, but sometimes some unusual environments like tests don't
27
+ params.workspaceFolders ?? (params.rootUri ? [{ uri: params.rootUri }] : []) ?? [])
28
+ : [],
29
+ };
30
+ function loadCollectionConfig(folders) {
31
+ return folders.flatMap((folder) => {
26
32
  try {
27
33
  const folderUri = vscode_uri_1.URI.parse(folder.uri);
28
34
  let config = server.fileSystem.readFile(vscode_uri_1.Utils.joinPath(folderUri, '.astro/collections/collections.json'));
@@ -43,7 +49,7 @@ connection.onInitialize((params) => {
43
49
  }
44
50
  return server.initialize(params, (0, node_1.createTypeScriptProject)(typescript, diagnosticMessages, ({ env }) => {
45
51
  return {
46
- languagePlugins: (0, languageServerPlugin_js_1.getLanguagePlugins)(collectionConfigs),
52
+ languagePlugins: (0, languageServerPlugin_js_1.getLanguagePlugins)(collectionConfig),
47
53
  setup({ project }) {
48
54
  const { languageServiceHost, configFileName } = project.typescript;
49
55
  const rootPath = configFileName
@@ -63,7 +69,7 @@ connection.onInitialize((params) => {
63
69
  (0, index_js_1.addAstroTypes)(typeof astroInstall === 'string' ? undefined : astroInstall, typescript, languageServiceHost);
64
70
  },
65
71
  };
66
- }), (0, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript, collectionConfigs));
72
+ }), (0, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript, collectionConfig));
67
73
  });
68
74
  connection.onInitialized(() => {
69
75
  server.initialized();
@@ -83,6 +89,13 @@ connection.onInitialized(() => {
83
89
  ];
84
90
  if (contentIntellisenseEnabled) {
85
91
  extensions.push(...frontmatterHolders_js_1.SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS);
92
+ server.fileWatcher.watchFiles(['**/*.schema.json', '**/collections.json']);
93
+ server.fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
94
+ const shouldReload = changes.some((change) => change.uri.endsWith('.schema.json') || change.uri.endsWith('collections.json'));
95
+ if (shouldReload) {
96
+ server.project.reload();
97
+ }
98
+ });
86
99
  }
87
100
  server.fileWatcher.watchFiles([`**/*.{${extensions.join(',')}}`]);
88
101
  });
@@ -1,3 +1,7 @@
1
1
  import type { LanguageServicePlugin } from '@volar/language-service';
2
+ import type { Provide } from 'volar-service-yaml';
2
3
  import type { CollectionConfig } from '../core/frontmatterHolders.js';
3
- export declare const create: (collectionConfigs: CollectionConfig[]) => LanguageServicePlugin;
4
+ type LanguageSettings = Parameters<ReturnType<Provide['yaml/languageService']>['configure']>['0'];
5
+ export declare function getSettings(collectionConfig: CollectionConfig): LanguageSettings;
6
+ export declare const create: (collectionConfig: CollectionConfig) => LanguageServicePlugin;
7
+ export {};
@@ -1,34 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
+ exports.getSettings = getSettings;
4
5
  const language_server_1 = require("@volar/language-server");
5
6
  const volar_service_yaml_1 = require("volar-service-yaml");
6
7
  const vscode_uri_1 = require("vscode-uri");
7
8
  const frontmatterHolders_js_1 = require("../core/frontmatterHolders.js");
8
- const create = (collectionConfigs) => {
9
- const yamlPlugin = (0, volar_service_yaml_1.create)({
10
- getLanguageSettings() {
11
- const schemas = collectionConfigs.flatMap((workspaceCollectionConfig) => {
12
- return workspaceCollectionConfig.config.collections.flatMap((collection) => {
13
- return {
14
- fileMatch: frontmatterHolders_js_1.SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS.map((ext) => `volar-embedded-content://yaml_frontmatter_${collection.name}/**/*${ext}`),
15
- uri: vscode_uri_1.Utils.joinPath(workspaceCollectionConfig.folder, '.astro/collections', `${collection.name}.schema.json`).toString(),
16
- };
17
- });
18
- });
9
+ function getSettings(collectionConfig) {
10
+ const schemas = collectionConfig.configs.flatMap((workspaceCollectionConfig) => {
11
+ return workspaceCollectionConfig.config.collections.flatMap((collection) => {
19
12
  return {
20
- completion: true,
21
- format: false,
22
- hover: true,
23
- validate: true,
24
- customTags: [],
25
- yamlVersion: '1.2',
26
- isKubernetes: false,
27
- parentSkeletonSelectedFirst: false,
28
- disableDefaultProperties: false,
29
- schemas: schemas,
13
+ fileMatch: frontmatterHolders_js_1.SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS.map((ext) => `volar-embedded-content://yaml_frontmatter_${collection.name}/**/*${ext}`),
14
+ uri: vscode_uri_1.Utils.joinPath(workspaceCollectionConfig.folder, '.astro/collections', `${collection.name}.schema.json`).toString(),
30
15
  };
31
- },
16
+ });
17
+ });
18
+ return {
19
+ completion: true,
20
+ format: false,
21
+ hover: true,
22
+ validate: true,
23
+ customTags: [],
24
+ yamlVersion: '1.2',
25
+ isKubernetes: false,
26
+ parentSkeletonSelectedFirst: false,
27
+ disableDefaultProperties: false,
28
+ schemas: schemas,
29
+ };
30
+ }
31
+ const create = (collectionConfig) => {
32
+ const yamlPlugin = (0, volar_service_yaml_1.create)({
33
+ getLanguageSettings: () => getSettings(collectionConfig),
32
34
  });
33
35
  return {
34
36
  ...yamlPlugin,
@@ -41,16 +43,16 @@ const create = (collectionConfigs) => {
41
43
  const languageService = yamlPluginInstance.provide?.['yaml/languageService']();
42
44
  if (languageService && context.env.onDidChangeWatchedFiles) {
43
45
  context.env.onDidChangeWatchedFiles(async (events) => {
44
- let hasChanges = false;
45
- for (const change of events.changes) {
46
- if (!change.uri.endsWith('.schema.json'))
47
- return;
48
- if (languageService.resetSchema(change.uri)) {
49
- hasChanges = true;
50
- }
46
+ const changedSchemas = events.changes.filter((change) => change.uri.endsWith('.schema.json'));
47
+ const changedConfig = events.changes.some((change) => change.uri.endsWith('collections.json'));
48
+ if (changedConfig) {
49
+ collectionConfig.reload(
50
+ // For some reason, context.env.workspaceFolders is not an array of WorkspaceFolders nor the older format, strange
51
+ context.env.workspaceFolders.map((folder) => ({ uri: folder.toString() })));
52
+ languageService.configure(getSettings(collectionConfig));
51
53
  }
52
- if (hasChanges) {
53
- // TODO: Figure out how to refresh the diagnostics
54
+ for (const change of changedSchemas) {
55
+ languageService.resetSchema(change.uri);
54
56
  }
55
57
  });
56
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "2.15.0",
3
+ "version": "2.15.3",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {