@astrojs/language-server 0.20.0 → 0.20.1
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 +7 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +0 -1
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +3 -7
- package/dist/plugins/typescript/language-service.js +13 -8
- package/dist/server.js +5 -6
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +19 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.20.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e6996f5: Fixed many situations where the language server would warn abusively about not being able to find Astro
|
|
8
|
+
- 4589c2b: Fix the language server not warning properly when a package is implicitely any due to missing types
|
|
9
|
+
|
|
3
10
|
## 0.20.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -12,7 +12,6 @@ export declare enum DiagnosticCodes {
|
|
|
12
12
|
ISOLATED_MODULE_COMPILE_ERR = 1208,
|
|
13
13
|
TYPE_NOT_ASSIGNABLE = 2322,
|
|
14
14
|
JSX_NO_CLOSING_TAG = 17008,
|
|
15
|
-
NO_DECL_IMPLICIT_ANY_TYPE = 7016,
|
|
16
15
|
JSX_ELEMENT_NO_CALL = 2604
|
|
17
16
|
}
|
|
18
17
|
export declare class DiagnosticsProviderImpl implements DiagnosticsProvider {
|
|
@@ -20,7 +20,6 @@ var DiagnosticCodes;
|
|
|
20
20
|
DiagnosticCodes[DiagnosticCodes["ISOLATED_MODULE_COMPILE_ERR"] = 1208] = "ISOLATED_MODULE_COMPILE_ERR";
|
|
21
21
|
DiagnosticCodes[DiagnosticCodes["TYPE_NOT_ASSIGNABLE"] = 2322] = "TYPE_NOT_ASSIGNABLE";
|
|
22
22
|
DiagnosticCodes[DiagnosticCodes["JSX_NO_CLOSING_TAG"] = 17008] = "JSX_NO_CLOSING_TAG";
|
|
23
|
-
DiagnosticCodes[DiagnosticCodes["NO_DECL_IMPLICIT_ANY_TYPE"] = 7016] = "NO_DECL_IMPLICIT_ANY_TYPE";
|
|
24
23
|
DiagnosticCodes[DiagnosticCodes["JSX_ELEMENT_NO_CALL"] = 2604] = "JSX_ELEMENT_NO_CALL";
|
|
25
24
|
})(DiagnosticCodes = exports.DiagnosticCodes || (exports.DiagnosticCodes = {}));
|
|
26
25
|
class DiagnosticsProviderImpl {
|
|
@@ -87,7 +86,6 @@ class DiagnosticsProviderImpl {
|
|
|
87
86
|
isNoSpreadExpected(diag, document) &&
|
|
88
87
|
isNoCantReturnOutsideFunction(diag) &&
|
|
89
88
|
isNoIsolatedModuleError(diag) &&
|
|
90
|
-
isNoImportImplicitAnyType(diag) &&
|
|
91
89
|
isNoJsxCannotHaveMultipleAttrsError(diag));
|
|
92
90
|
})
|
|
93
91
|
.map(enhanceIfNecessary);
|
|
@@ -173,9 +171,6 @@ function isNoJsxCannotHaveMultipleAttrsError(diagnostic) {
|
|
|
173
171
|
function isNoJSXMustHaveOneParent(diagnostic) {
|
|
174
172
|
return diagnostic.code !== DiagnosticCodes.MUST_HAVE_PARENT_ELEMENT;
|
|
175
173
|
}
|
|
176
|
-
function isNoImportImplicitAnyType(diagnostic) {
|
|
177
|
-
return diagnostic.code !== DiagnosticCodes.NO_DECL_IMPLICIT_ANY_TYPE;
|
|
178
|
-
}
|
|
179
174
|
/**
|
|
180
175
|
* When using the shorthand syntax for props TSX expects you to use the spread operator
|
|
181
176
|
* Since the shorthand syntax works differently in Astro and this is not required, hide this message
|
|
@@ -191,7 +186,7 @@ function isNoSpreadExpected(diagnostic, document) {
|
|
|
191
186
|
}
|
|
192
187
|
/**
|
|
193
188
|
* Ignore "Can't return outside of function body"
|
|
194
|
-
* Since the frontmatter is at the top level, users trying to return a Response
|
|
189
|
+
* Since the frontmatter is at the top level, users trying to return a Response for SSR mode run into this
|
|
195
190
|
*/
|
|
196
191
|
function isNoCantReturnOutsideFunction(diagnostic) {
|
|
197
192
|
return diagnostic.code !== DiagnosticCodes.CANT_RETURN_OUTSIDE_FUNC;
|
|
@@ -218,6 +213,7 @@ function enhanceIfNecessary(diagnostic) {
|
|
|
218
213
|
diagnostic.message +=
|
|
219
214
|
'\n\nIs the `@astrojs/vue` package installed? You can add it to your project by running the following command: `astro add vue`. If already installed, restarting the language server might be necessary in order for the change to take effect';
|
|
220
215
|
}
|
|
216
|
+
return diagnostic;
|
|
221
217
|
}
|
|
222
218
|
// JSX element has no closing tag. JSX -> HTML
|
|
223
219
|
if (diagnostic.code === DiagnosticCodes.JSX_NO_CLOSING_TAG) {
|
|
@@ -237,7 +233,7 @@ function enhanceIfNecessary(diagnostic) {
|
|
|
237
233
|
}
|
|
238
234
|
// For the rare case where an user might try to put a client directive on something that is not a component
|
|
239
235
|
if (diagnostic.code === DiagnosticCodes.TYPE_NOT_ASSIGNABLE) {
|
|
240
|
-
if (diagnostic.message.includes("Property 'client:") && diagnostic.message.includes("to type '
|
|
236
|
+
if (diagnostic.message.includes("Property 'client:") && diagnostic.message.includes("to type 'HTMLAttributes")) {
|
|
241
237
|
return {
|
|
242
238
|
...diagnostic,
|
|
243
239
|
message: 'Client directives are only available on framework components',
|
|
@@ -90,7 +90,9 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
90
90
|
const scriptFileNames = [];
|
|
91
91
|
// Before Astro 1.0, JSX definitions were inside of the language-server instead of inside Astro
|
|
92
92
|
// TODO: Remove this and astro-jsx.d.ts in types when we consider having support for Astro < 1.0 unnecessary
|
|
93
|
-
if (astroVersion.major === 0 || astroVersion.full === '1.0.0-beta.0')
|
|
93
|
+
if ((astroVersion.major === 0 || astroVersion.full === '1.0.0-beta.0') &&
|
|
94
|
+
!astroVersion.full.startsWith('0.0.0-rc-') // 1.0.0's RC is considered to be 0.0.0, so we have to check for it
|
|
95
|
+
) {
|
|
94
96
|
const astroTSXFile = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/astro-jsx.d.ts'));
|
|
95
97
|
scriptFileNames.push(astroTSXFile);
|
|
96
98
|
console.warn("Version lower than 1.0 detected, using internal types instead of Astro's");
|
|
@@ -219,19 +221,23 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
219
221
|
});
|
|
220
222
|
}
|
|
221
223
|
function getParsedTSConfig() {
|
|
222
|
-
let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {
|
|
224
|
+
let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {
|
|
225
|
+
compilerOptions: getDefaultCompilerOptions(astroVersion),
|
|
226
|
+
};
|
|
223
227
|
// If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
|
|
224
228
|
if (configJson.compilerOptions?.types) {
|
|
225
229
|
if (!configJson.compilerOptions?.types.includes('astro/env')) {
|
|
226
230
|
configJson.compilerOptions.types.push('astro/env');
|
|
227
231
|
}
|
|
228
|
-
if (astroVersion.major >= 1 &&
|
|
232
|
+
if ((astroVersion.major >= 1 || astroVersion.full.startsWith('0.0.0-rc-')) &&
|
|
229
233
|
astroVersion.full !== '1.0.0-beta.0' &&
|
|
230
234
|
!configJson.compilerOptions?.types.includes('astro/astro-jsx')) {
|
|
231
235
|
configJson.compilerOptions.types.push('astro/astro-jsx');
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
|
-
|
|
238
|
+
else {
|
|
239
|
+
configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(astroVersion), configJson.compilerOptions);
|
|
240
|
+
}
|
|
235
241
|
// Delete include so that .astro files don't get mistakenly excluded by the user
|
|
236
242
|
delete configJson.include;
|
|
237
243
|
// If the user supplied exclude, let's use theirs otherwise, use ours
|
|
@@ -241,6 +247,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
241
247
|
noEmit: true,
|
|
242
248
|
declaration: false,
|
|
243
249
|
resolveJsonModule: true,
|
|
250
|
+
allowSyntheticDefaultImports: true,
|
|
244
251
|
allowNonTsExtensions: true,
|
|
245
252
|
allowJs: true,
|
|
246
253
|
jsx: typescript_1.default.JsxEmit.Preserve,
|
|
@@ -267,16 +274,14 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
|
|
|
267
274
|
}
|
|
268
275
|
}
|
|
269
276
|
/**
|
|
270
|
-
* Default configuration used
|
|
277
|
+
* Default compiler configuration used when the user doesn't have any
|
|
271
278
|
*/
|
|
272
279
|
function getDefaultCompilerOptions(astroVersion) {
|
|
273
280
|
const types = ['astro/env'];
|
|
274
|
-
if (astroVersion.major >= 1 && astroVersion.full !== '1.0.0-beta.0') {
|
|
281
|
+
if ((astroVersion.major >= 1 && astroVersion.full !== '1.0.0-beta.0') || astroVersion.full.startsWith('0.0.0-rc-')) {
|
|
275
282
|
types.push('astro/astro-jsx');
|
|
276
283
|
}
|
|
277
284
|
return {
|
|
278
|
-
maxNodeModuleJsDepth: 2,
|
|
279
|
-
allowSyntheticDefaultImports: true,
|
|
280
285
|
types: types,
|
|
281
286
|
};
|
|
282
287
|
}
|
package/dist/server.js
CHANGED
|
@@ -49,6 +49,11 @@ function startLanguageServer(connection) {
|
|
|
49
49
|
const workspaceUris = params.workspaceFolders?.map((folder) => folder.uri.toString()) ?? [params.rootUri ?? ''];
|
|
50
50
|
workspaceUris.forEach((uri) => {
|
|
51
51
|
uri = (0, utils_1.urlToPath)(uri);
|
|
52
|
+
// If the workspace is not an Astro project, we shouldn't warn about not finding Astro
|
|
53
|
+
// Unless the extension enabled itself in an untitled workspace, in which case the warning is valid
|
|
54
|
+
if (!(0, utils_1.isAstroWorkspace)(uri) && uri !== '/' && uri !== '') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
52
57
|
const astroVersion = (0, utils_1.getUserAstroVersion)(uri);
|
|
53
58
|
if (astroVersion.exist === false) {
|
|
54
59
|
connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
|
|
@@ -56,12 +61,6 @@ function startLanguageServer(connection) {
|
|
|
56
61
|
type: vscode_languageserver_1.MessageType.Warning,
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
|
-
if (astroVersion.exist && astroVersion.major === 0 && astroVersion.minor < 24 && astroVersion.patch < 5) {
|
|
60
|
-
connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
|
|
61
|
-
message: `The version of Astro you're using (${astroVersion.full}) is not supported by this version of the Astro language server. Please upgrade Astro to any version higher than 0.23.4 or if using the VS Code extension, downgrade the extension to 0.8.10`,
|
|
62
|
-
type: vscode_languageserver_1.MessageType.Error,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
64
|
});
|
|
66
65
|
hasConfigurationCapability = !!(params.capabilities.workspace && !!params.capabilities.workspace.configuration);
|
|
67
66
|
pluginHost.initialize({
|
package/dist/utils.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPre
|
|
|
65
65
|
* @param milliseconds Number of milliseconds to debounce/throttle
|
|
66
66
|
*/
|
|
67
67
|
export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, milliseconds: number): T;
|
|
68
|
+
/**
|
|
69
|
+
* Try to determine if a workspace could be an Astro project based on the content of `package.json`
|
|
70
|
+
*/
|
|
71
|
+
export declare function isAstroWorkspace(workspacePath: string): boolean;
|
|
68
72
|
export interface AstroVersion {
|
|
69
73
|
full: string;
|
|
70
74
|
major: number;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserAstroVersion = 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;
|
|
3
|
+
exports.getUserAstroVersion = 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
5
|
/** Normalizes a document URI */
|
|
6
6
|
function normalizeUri(uri) {
|
|
@@ -197,6 +197,23 @@ function debounceThrottle(fn, milliseconds) {
|
|
|
197
197
|
return maybeCall;
|
|
198
198
|
}
|
|
199
199
|
exports.debounceThrottle = debounceThrottle;
|
|
200
|
+
/**
|
|
201
|
+
* Try to determine if a workspace could be an Astro project based on the content of `package.json`
|
|
202
|
+
*/
|
|
203
|
+
function isAstroWorkspace(workspacePath) {
|
|
204
|
+
try {
|
|
205
|
+
const astroPackageJson = require.resolve('./package.json', { paths: [workspacePath] });
|
|
206
|
+
const deps = Object.assign(require(astroPackageJson).dependencies ?? {}, require(astroPackageJson).devDependencies ?? {});
|
|
207
|
+
if (Object.keys(deps).includes('astro')) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
exports.isAstroWorkspace = isAstroWorkspace;
|
|
200
217
|
function getUserAstroVersion(basePath) {
|
|
201
218
|
let version = '0.0.0';
|
|
202
219
|
let exist = true;
|
|
@@ -213,7 +230,7 @@ function getUserAstroVersion(basePath) {
|
|
|
213
230
|
catch (e) {
|
|
214
231
|
// If we still couldn't find it, it probably just doesn't exist
|
|
215
232
|
exist = false;
|
|
216
|
-
console.error(
|
|
233
|
+
console.error(`${basePath} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
let [major, minor, patch] = version.split('.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/chai": "^4.3.0",
|
|
37
37
|
"@types/mocha": "^9.1.0",
|
|
38
38
|
"@types/sinon": "^10.0.11",
|
|
39
|
-
"astro": "^1.0.0-beta.
|
|
39
|
+
"astro": "^1.0.0-beta.72",
|
|
40
40
|
"astro-scripts": "0.0.1",
|
|
41
41
|
"chai": "^4.3.6",
|
|
42
42
|
"cross-env": "^7.0.3",
|