@astrojs/language-server 2.14.2 → 2.15.0
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/check.js +10 -3
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +49 -44
- package/dist/importPackage.d.ts +14 -1
- package/dist/importPackage.js +36 -9
- package/dist/languageServerPlugin.d.ts +2 -2
- package/dist/languageServerPlugin.js +2 -17
- package/dist/nodeServer.js +22 -3
- package/dist/plugins/typescript/index.js +8 -0
- package/dist/utils.d.ts +2 -10
- package/dist/utils.js +7 -37
- package/package.json +7 -7
package/dist/check.js
CHANGED
|
@@ -113,16 +113,19 @@ class AstroCheck {
|
|
|
113
113
|
initialize() {
|
|
114
114
|
this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
|
|
115
115
|
const tsconfigPath = this.getTsconfig();
|
|
116
|
-
const astroInstall = (0, utils_js_1.getAstroInstall)([this.workspacePath]);
|
|
117
116
|
const languagePlugins = [
|
|
118
|
-
(0, index_js_1.getAstroLanguagePlugin)(
|
|
117
|
+
(0, index_js_1.getAstroLanguagePlugin)(),
|
|
119
118
|
(0, svelte_js_1.getSvelteLanguagePlugin)(),
|
|
120
119
|
(0, vue_js_1.getVueLanguagePlugin)(),
|
|
121
120
|
];
|
|
122
121
|
const services = [...(0, index_js_2.create)(this.ts), (0, astro_js_1.create)(this.ts)];
|
|
123
122
|
if (tsconfigPath) {
|
|
124
123
|
const includeProjectReference = false; // #920
|
|
125
|
-
this.linter = kit.createTypeScriptChecker(languagePlugins, services, tsconfigPath, includeProjectReference)
|
|
124
|
+
this.linter = kit.createTypeScriptChecker(languagePlugins, services, tsconfigPath, includeProjectReference, ({ project }) => {
|
|
125
|
+
const { languageServiceHost } = project.typescript;
|
|
126
|
+
const astroInstall = (0, utils_js_1.getAstroInstall)([this.workspacePath]);
|
|
127
|
+
(0, index_js_1.addAstroTypes)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts, languageServiceHost);
|
|
128
|
+
});
|
|
126
129
|
}
|
|
127
130
|
else {
|
|
128
131
|
this.linter = kit.createTypeScriptInferredChecker(languagePlugins, services, () => {
|
|
@@ -131,6 +134,10 @@ class AstroCheck {
|
|
|
131
134
|
ignore: ['node_modules'],
|
|
132
135
|
absolute: true,
|
|
133
136
|
});
|
|
137
|
+
}, undefined, ({ project }) => {
|
|
138
|
+
const { languageServiceHost } = project.typescript;
|
|
139
|
+
const astroInstall = (0, utils_js_1.getAstroInstall)([this.workspacePath]);
|
|
140
|
+
(0, index_js_1.addAstroTypes)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts, languageServiceHost);
|
|
134
141
|
});
|
|
135
142
|
}
|
|
136
143
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { type CodeMapping, type LanguagePlugin, type VirtualCode } from '@volar/
|
|
|
3
3
|
import type ts from 'typescript';
|
|
4
4
|
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
5
|
import type { URI } from 'vscode-uri';
|
|
6
|
-
import {
|
|
6
|
+
import type { PackageInfo } from '../importPackage.js';
|
|
7
7
|
import type { AstroMetadata } from './parseAstro';
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function addAstroTypes(astroInstall: PackageInfo | undefined, ts: typeof import('typescript'), host: ts.LanguageServiceHost): void;
|
|
9
|
+
export declare function getAstroLanguagePlugin(): LanguagePlugin<URI, AstroVirtualCode>;
|
|
9
10
|
export declare class AstroVirtualCode implements VirtualCode {
|
|
10
11
|
fileName: string;
|
|
11
12
|
snapshot: ts.IScriptSnapshot;
|
package/dist/core/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.AstroVirtualCode = void 0;
|
|
27
|
+
exports.addAstroTypes = addAstroTypes;
|
|
27
28
|
exports.getAstroLanguagePlugin = getAstroLanguagePlugin;
|
|
28
29
|
const path = __importStar(require("node:path"));
|
|
29
30
|
const language_core_1 = require("@volar/language-core");
|
|
@@ -33,7 +34,54 @@ const parseAstro_1 = require("./parseAstro");
|
|
|
33
34
|
const parseCSS_1 = require("./parseCSS");
|
|
34
35
|
const parseHTML_1 = require("./parseHTML");
|
|
35
36
|
const parseJS_js_1 = require("./parseJS.js");
|
|
36
|
-
|
|
37
|
+
const decoratedHosts = new WeakSet();
|
|
38
|
+
function addAstroTypes(astroInstall, ts, host) {
|
|
39
|
+
if (decoratedHosts.has(host)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
decoratedHosts.add(host);
|
|
43
|
+
const getScriptFileNames = host.getScriptFileNames.bind(host);
|
|
44
|
+
const getCompilationSettings = host.getCompilationSettings.bind(host);
|
|
45
|
+
host.getScriptFileNames = () => {
|
|
46
|
+
const languageServerTypesDirectory = (0, utils_js_1.getLanguageServerTypesDir)(ts);
|
|
47
|
+
const fileNames = getScriptFileNames();
|
|
48
|
+
const addedFileNames = [];
|
|
49
|
+
if (astroInstall) {
|
|
50
|
+
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.directory, filePath))));
|
|
51
|
+
// If Astro version is < 4.0.8, add jsx-runtime-augment.d.ts to the files to fake `JSX` being available from "astro/jsx-runtime".
|
|
52
|
+
// TODO: Remove this once a majority of users are on Astro 4.0.8+, erika - 2023-12-28
|
|
53
|
+
if (astroInstall.version.major < 4 ||
|
|
54
|
+
(astroInstall.version.major === 4 &&
|
|
55
|
+
astroInstall.version.minor === 0 &&
|
|
56
|
+
astroInstall.version.patch < 8)) {
|
|
57
|
+
addedFileNames.push(...['./jsx-runtime-augment.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// If we don't have an Astro installation, add the fallback types from the language server.
|
|
62
|
+
// See the README in packages/language-server/types for more information.
|
|
63
|
+
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))));
|
|
64
|
+
}
|
|
65
|
+
return [...fileNames, ...addedFileNames];
|
|
66
|
+
};
|
|
67
|
+
host.getCompilationSettings = () => {
|
|
68
|
+
const baseCompilationSettings = getCompilationSettings();
|
|
69
|
+
return {
|
|
70
|
+
...baseCompilationSettings,
|
|
71
|
+
module: ts.ModuleKind.ESNext ?? 99,
|
|
72
|
+
target: ts.ScriptTarget.ESNext ?? 99,
|
|
73
|
+
jsx: ts.JsxEmit.Preserve ?? 1,
|
|
74
|
+
resolveJsonModule: true,
|
|
75
|
+
allowJs: true, // Needed for inline scripts, which are virtual .js files
|
|
76
|
+
isolatedModules: true,
|
|
77
|
+
moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
|
|
78
|
+
!baseCompilationSettings.moduleResolution
|
|
79
|
+
? ts.ModuleResolutionKind.Node10
|
|
80
|
+
: baseCompilationSettings.moduleResolution,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function getAstroLanguagePlugin() {
|
|
37
85
|
return {
|
|
38
86
|
getLanguageId(uri) {
|
|
39
87
|
if (uri.path.endsWith('.astro')) {
|
|
@@ -77,49 +125,6 @@ function getAstroLanguagePlugin(astroInstall, ts) {
|
|
|
77
125
|
}
|
|
78
126
|
return result;
|
|
79
127
|
},
|
|
80
|
-
resolveLanguageServiceHost(host) {
|
|
81
|
-
return {
|
|
82
|
-
...host,
|
|
83
|
-
getScriptFileNames() {
|
|
84
|
-
const languageServerTypesDirectory = (0, utils_js_1.getLanguageServerTypesDir)(ts);
|
|
85
|
-
const fileNames = host.getScriptFileNames();
|
|
86
|
-
const addedFileNames = [];
|
|
87
|
-
if (astroInstall) {
|
|
88
|
-
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath))));
|
|
89
|
-
// If Astro version is < 4.0.8, add jsx-runtime-augment.d.ts to the files to fake `JSX` being available from "astro/jsx-runtime".
|
|
90
|
-
// TODO: Remove this once a majority of users are on Astro 4.0.8+, erika - 2023-12-28
|
|
91
|
-
if (astroInstall.version.major < 4 ||
|
|
92
|
-
(astroInstall.version.major === 4 &&
|
|
93
|
-
astroInstall.version.minor === 0 &&
|
|
94
|
-
astroInstall.version.patch < 8)) {
|
|
95
|
-
addedFileNames.push(...['./jsx-runtime-augment.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// If we don't have an Astro installation, add the fallback types from the language server.
|
|
100
|
-
// See the README in packages/language-server/types for more information.
|
|
101
|
-
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))));
|
|
102
|
-
}
|
|
103
|
-
return [...fileNames, ...addedFileNames];
|
|
104
|
-
},
|
|
105
|
-
getCompilationSettings() {
|
|
106
|
-
const baseCompilationSettings = host.getCompilationSettings();
|
|
107
|
-
return {
|
|
108
|
-
...baseCompilationSettings,
|
|
109
|
-
module: ts.ModuleKind.ESNext ?? 99,
|
|
110
|
-
target: ts.ScriptTarget.ESNext ?? 99,
|
|
111
|
-
jsx: ts.JsxEmit.Preserve ?? 1,
|
|
112
|
-
resolveJsonModule: true,
|
|
113
|
-
allowJs: true, // Needed for inline scripts, which are virtual .js files
|
|
114
|
-
isolatedModules: true,
|
|
115
|
-
moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
|
|
116
|
-
!baseCompilationSettings.moduleResolution
|
|
117
|
-
? ts.ModuleResolutionKind.Node10
|
|
118
|
-
: baseCompilationSettings.moduleResolution,
|
|
119
|
-
};
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
128
|
},
|
|
124
129
|
};
|
|
125
130
|
}
|
package/dist/importPackage.d.ts
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import type * as svelte from '@astrojs/svelte/dist/editor.cjs';
|
|
2
2
|
import type * as vue from '@astrojs/vue/dist/editor.cjs';
|
|
3
3
|
import type * as prettier from 'prettier';
|
|
4
|
+
type PackageVersion = {
|
|
5
|
+
full: string;
|
|
6
|
+
major: number;
|
|
7
|
+
minor: number;
|
|
8
|
+
patch: number;
|
|
9
|
+
};
|
|
4
10
|
export declare function setIsTrusted(_isTrusted: boolean): void;
|
|
11
|
+
export type PackageInfo = {
|
|
12
|
+
entrypoint: string;
|
|
13
|
+
directory: string;
|
|
14
|
+
version: PackageVersion;
|
|
15
|
+
};
|
|
5
16
|
/**
|
|
6
17
|
* Get the path of a package's directory from the paths in `fromPath`, if `root` is set to false, it will return the path of the package's entry point
|
|
7
18
|
*/
|
|
8
|
-
export declare function
|
|
19
|
+
export declare function getPackageInfo(packageName: string, fromPath: string[]): PackageInfo | undefined;
|
|
9
20
|
export declare function importSvelteIntegration(fromPath: string): typeof svelte | undefined;
|
|
10
21
|
export declare function importVueIntegration(fromPath: string): typeof vue | undefined;
|
|
11
22
|
export declare function importPrettier(fromPath: string): typeof prettier | undefined;
|
|
12
23
|
export declare function getPrettierPluginPath(fromPath: string): string | undefined;
|
|
13
24
|
export declare function getWorkspacePnpPath(workspacePath: string): string | null;
|
|
25
|
+
export declare function parsePackageVersion(version: string): PackageVersion;
|
|
26
|
+
export {};
|
package/dist/importPackage.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setIsTrusted = setIsTrusted;
|
|
4
|
-
exports.
|
|
4
|
+
exports.getPackageInfo = getPackageInfo;
|
|
5
5
|
exports.importSvelteIntegration = importSvelteIntegration;
|
|
6
6
|
exports.importVueIntegration = importVueIntegration;
|
|
7
7
|
exports.importPrettier = importPrettier;
|
|
8
8
|
exports.getPrettierPluginPath = getPrettierPluginPath;
|
|
9
9
|
exports.getWorkspacePnpPath = getWorkspacePnpPath;
|
|
10
|
+
exports.parsePackageVersion = parsePackageVersion;
|
|
10
11
|
const node_path_1 = require("node:path");
|
|
11
12
|
let isTrusted = true;
|
|
12
13
|
function setIsTrusted(_isTrusted) {
|
|
@@ -15,22 +16,25 @@ function setIsTrusted(_isTrusted) {
|
|
|
15
16
|
/**
|
|
16
17
|
* Get the path of a package's directory from the paths in `fromPath`, if `root` is set to false, it will return the path of the package's entry point
|
|
17
18
|
*/
|
|
18
|
-
function
|
|
19
|
+
function getPackageInfo(packageName, fromPath) {
|
|
19
20
|
const paths = [];
|
|
20
21
|
if (isTrusted) {
|
|
21
22
|
paths.unshift(...fromPath);
|
|
22
23
|
}
|
|
23
24
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
:
|
|
25
|
+
const packageJSON = require.resolve(packageName + '/package.json', { paths });
|
|
26
|
+
return {
|
|
27
|
+
directory: (0, node_path_1.dirname)(packageJSON),
|
|
28
|
+
entrypoint: require.resolve(packageName, { paths }),
|
|
29
|
+
version: parsePackageVersion(require(packageJSON).version),
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
catch {
|
|
29
33
|
return undefined;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
function importEditorIntegration(packageName, fromPath) {
|
|
33
|
-
const pkgPath =
|
|
37
|
+
const pkgPath = getPackageInfo(packageName, [fromPath])?.directory;
|
|
34
38
|
if (pkgPath) {
|
|
35
39
|
try {
|
|
36
40
|
const main = (0, node_path_1.resolve)(pkgPath, 'dist', 'editor.cjs');
|
|
@@ -53,14 +57,24 @@ function importVueIntegration(fromPath) {
|
|
|
53
57
|
return importEditorIntegration('@astrojs/vue', fromPath);
|
|
54
58
|
}
|
|
55
59
|
function importPrettier(fromPath) {
|
|
56
|
-
|
|
60
|
+
let prettierPkg = getPackageInfo('prettier', [fromPath, __dirname]);
|
|
57
61
|
if (!prettierPkg) {
|
|
58
62
|
return undefined;
|
|
59
63
|
}
|
|
60
|
-
|
|
64
|
+
if (prettierPkg.version.major < 3) {
|
|
65
|
+
console.error(`Prettier version ${prettierPkg.version.full} from ${prettierPkg.directory} is not supported, please update to at least version 3.0.0. Falling back to bundled version to ensure formatting works correctly.`);
|
|
66
|
+
prettierPkg = getPackageInfo('prettier', [__dirname]);
|
|
67
|
+
if (!prettierPkg) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return require(prettierPkg.entrypoint);
|
|
61
72
|
}
|
|
62
73
|
function getPrettierPluginPath(fromPath) {
|
|
63
|
-
const prettierPluginPath =
|
|
74
|
+
const prettierPluginPath = getPackageInfo('prettier-plugin-astro', [
|
|
75
|
+
fromPath,
|
|
76
|
+
__dirname,
|
|
77
|
+
])?.entrypoint;
|
|
64
78
|
if (!prettierPluginPath) {
|
|
65
79
|
return undefined;
|
|
66
80
|
}
|
|
@@ -76,4 +90,17 @@ function getWorkspacePnpPath(workspacePath) {
|
|
|
76
90
|
return null;
|
|
77
91
|
}
|
|
78
92
|
}
|
|
93
|
+
function parsePackageVersion(version) {
|
|
94
|
+
let [major, minor, patch] = version.split('.');
|
|
95
|
+
if (patch.includes('-')) {
|
|
96
|
+
const patchParts = patch.split('-');
|
|
97
|
+
patch = patchParts[0];
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
full: version,
|
|
101
|
+
major: Number(major),
|
|
102
|
+
minor: Number(minor),
|
|
103
|
+
patch: Number(patch),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
79
106
|
//# sourceMappingURL=importPackage.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Connection, type LanguagePlugin
|
|
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(
|
|
4
|
+
export declare function getLanguagePlugins(collectionConfigs: CollectionConfig[]): LanguagePlugin<URI, import("@volar/language-server/node").VirtualCode>[];
|
|
5
5
|
export declare function getLanguageServicePlugins(connection: Connection, ts: typeof import('typescript'), collectionConfigs: CollectionConfig[]): import("@volar/language-server/node").LanguageServicePlugin<any>[];
|
|
@@ -8,7 +8,6 @@ const core_1 = require("./core");
|
|
|
8
8
|
const svelte_js_1 = require("./core/svelte.js");
|
|
9
9
|
const vue_js_1 = require("./core/vue.js");
|
|
10
10
|
const importPackage_js_1 = require("./importPackage.js");
|
|
11
|
-
const utils_js_1 = require("./utils.js");
|
|
12
11
|
// Services
|
|
13
12
|
const volar_service_css_1 = require("volar-service-css");
|
|
14
13
|
const volar_service_emmet_1 = require("volar-service-emmet");
|
|
@@ -20,29 +19,15 @@ const html_js_1 = require("./plugins/html.js");
|
|
|
20
19
|
const index_js_1 = require("./plugins/typescript-addons/index.js");
|
|
21
20
|
const index_js_2 = require("./plugins/typescript/index.js");
|
|
22
21
|
const yaml_js_1 = require("./plugins/yaml.js");
|
|
23
|
-
function getLanguagePlugins(
|
|
22
|
+
function getLanguagePlugins(collectionConfigs) {
|
|
24
23
|
const languagePlugins = [
|
|
24
|
+
(0, core_1.getAstroLanguagePlugin)(),
|
|
25
25
|
(0, vue_js_1.getVueLanguagePlugin)(),
|
|
26
26
|
(0, svelte_js_1.getSvelteLanguagePlugin)(),
|
|
27
27
|
];
|
|
28
|
-
const rootPath = tsconfig
|
|
29
|
-
? tsconfig.split('/').slice(0, -1).join('/')
|
|
30
|
-
: serviceEnv.workspaceFolders[0].fsPath;
|
|
31
|
-
const nearestPackageJson = ts.findConfigFile(rootPath, ts.sys.fileExists, 'package.json');
|
|
32
|
-
const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
|
|
33
|
-
nearestPackageJson: nearestPackageJson,
|
|
34
|
-
readDirectory: ts.sys.readDirectory,
|
|
35
|
-
});
|
|
36
|
-
if (astroInstall === 'not-found') {
|
|
37
|
-
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
38
|
-
message: `Couldn't find Astro in workspace "${rootPath}". Experience might be degraded. For the best experience, please make sure Astro is installed into your project and restart the language server.`,
|
|
39
|
-
type: node_1.MessageType.Warning,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
28
|
if (collectionConfigs.length) {
|
|
43
29
|
languagePlugins.push((0, frontmatterHolders_js_1.getFrontmatterLanguagePlugin)(collectionConfigs));
|
|
44
30
|
}
|
|
45
|
-
languagePlugins.unshift((0, core_1.getAstroLanguagePlugin)(typeof astroInstall === 'string' ? undefined : astroInstall, ts));
|
|
46
31
|
return languagePlugins;
|
|
47
32
|
}
|
|
48
33
|
function getLanguageServicePlugins(connection, ts, collectionConfigs) {
|
package/dist/nodeServer.js
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const node_1 = require("@volar/language-server/node");
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
5
|
const frontmatterHolders_js_1 = require("./core/frontmatterHolders.js");
|
|
6
|
+
const index_js_1 = require("./core/index.js");
|
|
6
7
|
const languageServerPlugin_js_1 = require("./languageServerPlugin.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
7
9
|
const connection = (0, node_1.createConnection)();
|
|
8
10
|
const server = (0, node_1.createServer)(connection);
|
|
9
11
|
let contentIntellisenseEnabled = false;
|
|
@@ -39,10 +41,27 @@ connection.onInitialize((params) => {
|
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
|
-
return server.initialize(params, (0, node_1.createTypeScriptProject)(typescript, diagnosticMessages, ({ env
|
|
44
|
+
return server.initialize(params, (0, node_1.createTypeScriptProject)(typescript, diagnosticMessages, ({ env }) => {
|
|
43
45
|
return {
|
|
44
|
-
languagePlugins: (0, languageServerPlugin_js_1.getLanguagePlugins)(
|
|
45
|
-
setup() {
|
|
46
|
+
languagePlugins: (0, languageServerPlugin_js_1.getLanguagePlugins)(collectionConfigs),
|
|
47
|
+
setup({ project }) {
|
|
48
|
+
const { languageServiceHost, configFileName } = project.typescript;
|
|
49
|
+
const rootPath = configFileName
|
|
50
|
+
? configFileName.split('/').slice(0, -1).join('/')
|
|
51
|
+
: env.workspaceFolders[0].fsPath;
|
|
52
|
+
const nearestPackageJson = typescript.findConfigFile(rootPath, typescript.sys.fileExists, 'package.json');
|
|
53
|
+
const astroInstall = (0, utils_js_1.getAstroInstall)([rootPath], {
|
|
54
|
+
nearestPackageJson: nearestPackageJson,
|
|
55
|
+
readDirectory: typescript.sys.readDirectory,
|
|
56
|
+
});
|
|
57
|
+
if (astroInstall === 'not-found') {
|
|
58
|
+
connection.sendNotification(node_1.ShowMessageNotification.type, {
|
|
59
|
+
message: `Couldn't find Astro in workspace "${rootPath}". Experience might be degraded. For the best experience, please make sure Astro is installed into your project and restart the language server.`,
|
|
60
|
+
type: node_1.MessageType.Warning,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
(0, index_js_1.addAstroTypes)(typeof astroInstall === 'string' ? undefined : astroInstall, typescript, languageServiceHost);
|
|
64
|
+
},
|
|
46
65
|
};
|
|
47
66
|
}), (0, languageServerPlugin_js_1.getLanguageServicePlugins)(connection, typescript, collectionConfigs));
|
|
48
67
|
});
|
|
@@ -17,6 +17,14 @@ const create = (ts) => {
|
|
|
17
17
|
const typeScriptPlugin = plugin.create(context);
|
|
18
18
|
return {
|
|
19
19
|
...typeScriptPlugin,
|
|
20
|
+
async provideFileRenameEdits(oldUri, newUri, token) {
|
|
21
|
+
const astroConfig = await context.env.getConfiguration?.('astro');
|
|
22
|
+
// Check for `false` explicitly, as the default value is `true`, but it might not be set explicitly depending on the editor
|
|
23
|
+
if (astroConfig?.updateImportsOnFileMove.enabled === false) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return typeScriptPlugin.provideFileRenameEdits(oldUri, newUri, token);
|
|
27
|
+
},
|
|
20
28
|
async provideCompletionItems(document, position, completionContext, token) {
|
|
21
29
|
const originalCompletions = await typeScriptPlugin.provideCompletionItems(document, position, completionContext, token);
|
|
22
30
|
if (!originalCompletions)
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
path: string;
|
|
3
|
-
version: {
|
|
4
|
-
full: string;
|
|
5
|
-
major: number;
|
|
6
|
-
minor: number;
|
|
7
|
-
patch: number;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
1
|
+
import type { PackageInfo } from './importPackage.js';
|
|
10
2
|
export declare function getLanguageServerTypesDir(ts: typeof import('typescript')): string;
|
|
11
3
|
export declare function getAstroInstall(basePaths: string[], checkForAstro?: {
|
|
12
4
|
nearestPackageJson: string | undefined;
|
|
13
5
|
readDirectory: typeof import('typescript').sys.readDirectory;
|
|
14
|
-
}):
|
|
6
|
+
}): PackageInfo | 'not-an-astro-project' | 'not-found';
|
package/dist/utils.js
CHANGED
|
@@ -31,8 +31,6 @@ function getLanguageServerTypesDir(ts) {
|
|
|
31
31
|
return ts.sys.resolvePath(path.resolve(__dirname, '../types'));
|
|
32
32
|
}
|
|
33
33
|
function getAstroInstall(basePaths, checkForAstro) {
|
|
34
|
-
let astroPath;
|
|
35
|
-
let version;
|
|
36
34
|
if (checkForAstro && checkForAstro.nearestPackageJson) {
|
|
37
35
|
basePaths.push(path.dirname(checkForAstro.nearestPackageJson));
|
|
38
36
|
let deps = new Set();
|
|
@@ -52,44 +50,16 @@ function getAstroInstall(basePaths, checkForAstro) {
|
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
version = require(path.resolve(astroPath, 'package.json')).version;
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
|
|
64
|
-
try {
|
|
65
|
-
astroPath = (0, importPackage_js_1.getPackagePath)('./packages/astro', basePaths);
|
|
66
|
-
if (!astroPath) {
|
|
67
|
-
throw Error;
|
|
68
|
-
}
|
|
69
|
-
version = require(path.resolve(astroPath, 'package.json')).version;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
// If we still couldn't find it, it probably just doesn't exist
|
|
53
|
+
let astroPackage = (0, importPackage_js_1.getPackageInfo)('astro', basePaths);
|
|
54
|
+
if (!astroPackage) {
|
|
55
|
+
// If we couldn't find it inside the workspace's node_modules, it might means we're in the Astro development monorepo
|
|
56
|
+
astroPackage = (0, importPackage_js_1.getPackageInfo)('./packages/astro', basePaths);
|
|
57
|
+
if (!astroPackage) {
|
|
73
58
|
console.error(`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
|
|
59
|
+
// If we still couldn't find it, it probably just doesn't exist
|
|
74
60
|
return 'not-found';
|
|
75
61
|
}
|
|
76
62
|
}
|
|
77
|
-
|
|
78
|
-
return 'not-found';
|
|
79
|
-
}
|
|
80
|
-
let [major, minor, patch] = version.split('.');
|
|
81
|
-
if (patch.includes('-')) {
|
|
82
|
-
const patchParts = patch.split('-');
|
|
83
|
-
patch = patchParts[0];
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
path: astroPath,
|
|
87
|
-
version: {
|
|
88
|
-
full: version,
|
|
89
|
-
major: Number(major),
|
|
90
|
-
minor: Number(minor),
|
|
91
|
-
patch: Number(patch),
|
|
92
|
-
},
|
|
93
|
-
};
|
|
63
|
+
return astroPackage;
|
|
94
64
|
}
|
|
95
65
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
"@astrojs/compiler": "^2.10.3",
|
|
24
24
|
"@astrojs/yaml2ts": "^0.2.1",
|
|
25
25
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
26
|
-
"@volar/kit": "~2.4.
|
|
27
|
-
"@volar/language-core": "~2.4.
|
|
28
|
-
"@volar/language-server": "~2.4.
|
|
29
|
-
"@volar/language-service": "~2.4.
|
|
30
|
-
"@volar/typescript": "~2.4.0",
|
|
26
|
+
"@volar/kit": "~2.4.5",
|
|
27
|
+
"@volar/language-core": "~2.4.5",
|
|
28
|
+
"@volar/language-server": "~2.4.5",
|
|
29
|
+
"@volar/language-service": "~2.4.5",
|
|
31
30
|
"fast-glob": "^3.2.12",
|
|
32
31
|
"muggle-string": "^0.4.1",
|
|
33
32
|
"volar-service-css": "0.0.61",
|
|
@@ -46,7 +45,8 @@
|
|
|
46
45
|
"@types/chai": "^4.3.5",
|
|
47
46
|
"@types/mocha": "^10.0.1",
|
|
48
47
|
"@types/node": "^18.17.8",
|
|
49
|
-
"@volar/test-utils": "~2.4.
|
|
48
|
+
"@volar/test-utils": "~2.4.5",
|
|
49
|
+
"@volar/typescript": "~2.4.5",
|
|
50
50
|
"astro": "^4.14.0",
|
|
51
51
|
"chai": "^4.3.7",
|
|
52
52
|
"mocha": "^10.2.0",
|