@astrojs/language-server 0.21.0 → 0.23.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/CHANGELOG.md +28 -0
- package/README.md +1 -2
- package/dist/check.js +4 -1
- package/dist/core/config/ConfigManager.d.ts +1 -2
- package/dist/core/config/ConfigManager.js +0 -7
- package/dist/importPackage.d.ts +4 -1
- package/dist/importPackage.js +22 -9
- package/dist/plugins/PluginHost.d.ts +1 -0
- package/dist/plugins/PluginHost.js +4 -0
- package/dist/plugins/astro/AstroPlugin.d.ts +5 -3
- package/dist/plugins/astro/AstroPlugin.js +35 -3
- package/dist/plugins/css/language-service.d.ts +1 -1
- package/dist/plugins/html/HTMLPlugin.d.ts +1 -2
- package/dist/plugins/html/HTMLPlugin.js +6 -20
- package/dist/plugins/interfaces.d.ts +5 -2
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +6 -5
- package/dist/plugins/typescript/TypeScriptPlugin.js +7 -8
- package/dist/plugins/typescript/astro2tsx.js +15 -1
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.js +55 -0
- package/dist/plugins/typescript/language-service.js +9 -11
- package/dist/server.js +10 -5
- package/dist/utils.d.ts +9 -7
- package/dist/utils.js +25 -16
- package/package.json +4 -1
- package/types/README.md +5 -0
- package/types/astro-jsx.d.ts +854 -477
- package/types/env.d.ts +22 -0
- package/dist/plugins/typescript/features/FormattingProvider.d.ts +0 -11
- package/dist/plugins/typescript/features/FormattingProvider.js +0 -132
package/dist/server.js
CHANGED
|
@@ -37,6 +37,7 @@ const plugins_1 = require("./plugins");
|
|
|
37
37
|
const utils_1 = require("./utils");
|
|
38
38
|
const utils_2 = require("./plugins/typescript/utils");
|
|
39
39
|
const CodeActionsProvider_1 = require("./plugins/typescript/features/CodeActionsProvider");
|
|
40
|
+
const LanguageServiceManager_1 = require("./plugins/typescript/LanguageServiceManager");
|
|
40
41
|
const TagCloseRequest = new vscode.RequestType('html/tag');
|
|
41
42
|
// Start the language server
|
|
42
43
|
function startLanguageServer(connection) {
|
|
@@ -47,6 +48,7 @@ function startLanguageServer(connection) {
|
|
|
47
48
|
let typescriptPlugin = undefined;
|
|
48
49
|
let hasConfigurationCapability = false;
|
|
49
50
|
connection.onInitialize((params) => {
|
|
51
|
+
const environment = params.initializationOptions?.environment ?? 'node';
|
|
50
52
|
const workspaceUris = params.workspaceFolders?.map((folder) => folder.uri.toString()) ?? [params.rootUri ?? ''];
|
|
51
53
|
workspaceUris.forEach((uri) => {
|
|
52
54
|
uri = (0, utils_1.urlToPath)(uri);
|
|
@@ -55,8 +57,8 @@ function startLanguageServer(connection) {
|
|
|
55
57
|
if (!(0, utils_1.isAstroWorkspace)(uri) && uri !== '/' && uri !== '') {
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
+
const astroInstall = (0, utils_1.getAstroInstall)([uri]);
|
|
61
|
+
if (!astroInstall) {
|
|
60
62
|
connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
|
|
61
63
|
message: `Couldn't find Astro in workspace "${uri}". Experience might be degraded. For the best experience, please make sure Astro is installed and then restart the language server`,
|
|
62
64
|
type: vscode_languageserver_1.MessageType.Warning,
|
|
@@ -72,9 +74,10 @@ function startLanguageServer(connection) {
|
|
|
72
74
|
pluginHost.registerPlugin(new HTMLPlugin_1.HTMLPlugin(configManager));
|
|
73
75
|
pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
|
|
74
76
|
// We don't currently support running the TypeScript and Astro plugin in the browser
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
if (environment === 'node') {
|
|
78
|
+
const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(documentManager, workspaceUris.map(utils_1.normalizeUri), configManager);
|
|
79
|
+
typescriptPlugin = new plugins_1.TypeScriptPlugin(configManager, languageServiceManager);
|
|
80
|
+
pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(configManager, languageServiceManager));
|
|
78
81
|
pluginHost.registerPlugin(typescriptPlugin);
|
|
79
82
|
}
|
|
80
83
|
return {
|
|
@@ -88,6 +91,7 @@ function startLanguageServer(connection) {
|
|
|
88
91
|
},
|
|
89
92
|
foldingRangeProvider: true,
|
|
90
93
|
definitionProvider: true,
|
|
94
|
+
typeDefinitionProvider: true,
|
|
91
95
|
renameProvider: true,
|
|
92
96
|
documentFormattingProvider: true,
|
|
93
97
|
codeActionProvider: {
|
|
@@ -182,6 +186,7 @@ function startLanguageServer(connection) {
|
|
|
182
186
|
// Features
|
|
183
187
|
connection.onHover((params) => pluginHost.doHover(params.textDocument, params.position));
|
|
184
188
|
connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
|
|
189
|
+
connection.onTypeDefinition((evt) => pluginHost.getTypeDefinition(evt.textDocument, evt.position));
|
|
185
190
|
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
186
191
|
connection.onCodeAction((evt, cancellationToken) => pluginHost.getCodeActions(evt.textDocument, evt.range, evt.context, cancellationToken));
|
|
187
192
|
connection.onCompletion(async (evt) => {
|
package/dist/utils.d.ts
CHANGED
|
@@ -69,11 +69,13 @@ export declare function debounceThrottle<T extends (...args: any) => void>(fn: T
|
|
|
69
69
|
* Try to determine if a workspace could be an Astro project based on the content of `package.json`
|
|
70
70
|
*/
|
|
71
71
|
export declare function isAstroWorkspace(workspacePath: string): boolean;
|
|
72
|
-
export interface
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
export interface AstroInstall {
|
|
73
|
+
path: string;
|
|
74
|
+
version: {
|
|
75
|
+
full: string;
|
|
76
|
+
major: number;
|
|
77
|
+
minor: number;
|
|
78
|
+
patch: number;
|
|
79
|
+
};
|
|
78
80
|
}
|
|
79
|
-
export declare function
|
|
81
|
+
export declare function getAstroInstall(basePaths: string[]): AstroInstall | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAstroInstall = exports.isAstroWorkspace = exports.debounceThrottle = exports.debounceSameArg = exports.getRegExpMatches = exports.regexLastIndexOf = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.modifyLines = exports.toPascalCase = exports.mergeDeep = exports.get = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
+
const importPackage_1 = require("./importPackage");
|
|
5
6
|
/** Normalizes a document URI */
|
|
6
7
|
function normalizeUri(uri) {
|
|
7
8
|
return vscode_uri_1.URI.parse(uri).toString();
|
|
@@ -214,23 +215,29 @@ function isAstroWorkspace(workspacePath) {
|
|
|
214
215
|
return false;
|
|
215
216
|
}
|
|
216
217
|
exports.isAstroWorkspace = isAstroWorkspace;
|
|
217
|
-
function
|
|
218
|
-
let
|
|
219
|
-
let
|
|
218
|
+
function getAstroInstall(basePaths) {
|
|
219
|
+
let path;
|
|
220
|
+
let version;
|
|
220
221
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
path = (0, importPackage_1.getPackagePath)('astro', basePaths);
|
|
223
|
+
if (!path) {
|
|
224
|
+
throw Error;
|
|
225
|
+
}
|
|
226
|
+
version = require(path + '/package.json').version;
|
|
223
227
|
}
|
|
224
228
|
catch {
|
|
225
229
|
// If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
|
|
226
230
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
231
|
+
path = (0, importPackage_1.getPackagePath)('./packages/astro', basePaths);
|
|
232
|
+
if (!path) {
|
|
233
|
+
throw Error;
|
|
234
|
+
}
|
|
235
|
+
version = require(path + '/package.json').version;
|
|
229
236
|
}
|
|
230
237
|
catch (e) {
|
|
231
238
|
// If we still couldn't find it, it probably just doesn't exist
|
|
232
|
-
|
|
233
|
-
|
|
239
|
+
console.error(`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
|
|
240
|
+
return undefined;
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
243
|
let [major, minor, patch] = version.split('.');
|
|
@@ -239,11 +246,13 @@ function getUserAstroVersion(basePath) {
|
|
|
239
246
|
patch = patchParts[0];
|
|
240
247
|
}
|
|
241
248
|
return {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
249
|
+
path,
|
|
250
|
+
version: {
|
|
251
|
+
full: version,
|
|
252
|
+
major: Number(major),
|
|
253
|
+
minor: Number(minor),
|
|
254
|
+
patch: Number(patch),
|
|
255
|
+
},
|
|
247
256
|
};
|
|
248
257
|
}
|
|
249
|
-
exports.
|
|
258
|
+
exports.getAstroInstall = getAstroInstall;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@vscode/emmet-helper": "^2.8.4",
|
|
23
|
+
"prettier": "^2.7.1",
|
|
24
|
+
"prettier-plugin-astro": "^0.5.3",
|
|
23
25
|
"source-map": "^0.7.3",
|
|
24
26
|
"typescript": "~4.6.4",
|
|
25
27
|
"vscode-css-languageservice": "^6.0.1",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"@astrojs/vue": "^0.5.0",
|
|
36
38
|
"@types/chai": "^4.3.0",
|
|
37
39
|
"@types/mocha": "^9.1.0",
|
|
40
|
+
"@types/prettier": "^2.7.0",
|
|
38
41
|
"@types/sinon": "^10.0.11",
|
|
39
42
|
"astro": "^1.0.0-beta.72",
|
|
40
43
|
"astro-scripts": "0.0.1",
|
package/types/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Types
|
|
2
|
+
|
|
3
|
+
**Heads up!** `env.d.ts` and `astro-jsx.d.ts` in this folder are only used as fallback by the language server whenever we're not able to load the real types from the user's project. The types here should be in line with the types from Astro, but only loosely as not being able to load the real types from the user's project is an uncommon situation and some things are not necessarily possible without relying on Astro's internals
|
|
4
|
+
|
|
5
|
+
As such, if you're making a PR to fix/improve something related to types, you should probably make a PR to [Astro itself](https://github.com/withastro/astro), not this project!
|