@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.
- package/dist/core/frontmatterHolders.d.ts +15 -9
- package/dist/core/frontmatterHolders.js +4 -4
- package/dist/languageServerPlugin.d.ts +2 -2
- package/dist/languageServerPlugin.js +4 -8
- package/dist/nodeServer.js +21 -8
- package/dist/plugins/yaml.d.ts +5 -1
- package/dist/plugins/yaml.js +33 -31
- package/package.json +1 -1
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
12
|
+
reload: (folders: {
|
|
13
|
+
uri: string;
|
|
14
|
+
}[]) => void;
|
|
15
|
+
configs: {
|
|
16
|
+
folder: URI;
|
|
17
|
+
config: CollectionConfigInstance;
|
|
18
|
+
}[];
|
|
20
19
|
};
|
|
21
|
-
export
|
|
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(
|
|
12
|
-
for (const collection of
|
|
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(
|
|
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(
|
|
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(
|
|
5
|
-
export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript'),
|
|
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(
|
|
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,
|
|
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;
|
package/dist/nodeServer.js
CHANGED
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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)(
|
|
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,
|
|
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
|
});
|
package/dist/plugins/yaml.d.ts
CHANGED
|
@@ -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
|
-
|
|
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 {};
|
package/dist/plugins/yaml.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
+
for (const change of changedSchemas) {
|
|
55
|
+
languageService.resetSchema(change.uri);
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
58
|
}
|