@astrojs/language-server 0.19.6 → 0.20.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 +10 -0
- package/dist/check.d.ts +6 -4
- package/dist/check.js +7 -4
- package/dist/importPackage.d.ts +6 -0
- package/dist/importPackage.js +41 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +1 -0
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +13 -0
- package/dist/plugins/typescript/snapshots/utils.js +9 -4
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ba0fab1: Load language integrations from the user's project instead of bundling them in the language server
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- fa3f0f7: Updated exports for `astro check`
|
|
12
|
+
|
|
3
13
|
## 0.19.6
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/check.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { Diagnostic } from 'vscode-languageserver';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Diagnostic } from 'vscode-languageserver-types';
|
|
2
|
+
import { LSConfig } from './core/config';
|
|
3
|
+
export { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
4
|
+
export { Diagnostic };
|
|
5
|
+
export interface GetDiagnosticsResult {
|
|
4
6
|
filePath: string;
|
|
5
7
|
text: string;
|
|
6
8
|
diagnostics: Diagnostic[];
|
|
@@ -9,7 +11,7 @@ export declare class AstroCheck {
|
|
|
9
11
|
private docManager;
|
|
10
12
|
private configManager;
|
|
11
13
|
private pluginHost;
|
|
12
|
-
constructor(workspacePath: string);
|
|
14
|
+
constructor(workspacePath: string, options?: LSConfig);
|
|
13
15
|
upsertDocument(doc: {
|
|
14
16
|
text: string;
|
|
15
17
|
uri: string;
|
package/dist/check.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AstroCheck = exports.DiagnosticSeverity = void 0;
|
|
4
|
-
const documents_1 = require("./core/documents");
|
|
5
4
|
const config_1 = require("./core/config");
|
|
5
|
+
const documents_1 = require("./core/documents");
|
|
6
6
|
const plugins_1 = require("./plugins");
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return
|
|
7
|
+
var vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
8
|
+
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return vscode_languageserver_types_1.DiagnosticSeverity; } });
|
|
9
9
|
class AstroCheck {
|
|
10
|
-
constructor(workspacePath) {
|
|
10
|
+
constructor(workspacePath, options) {
|
|
11
11
|
this.docManager = documents_1.DocumentManager.newInstance();
|
|
12
12
|
this.configManager = new config_1.ConfigManager();
|
|
13
13
|
this.pluginHost = new plugins_1.PluginHost(this.docManager);
|
|
14
14
|
this.initialize(workspacePath);
|
|
15
|
+
if (options) {
|
|
16
|
+
this.configManager.updateGlobalConfig(options);
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
upsertDocument(doc) {
|
|
17
20
|
this.docManager.openDocument({
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as svelte from '@astrojs/svelte/dist/editor.cjs';
|
|
2
|
+
import type * as vue from '@astrojs/svelte/dist/editor.cjs';
|
|
3
|
+
export declare function setIsTrusted(_isTrusted: boolean): void;
|
|
4
|
+
export declare function getPackagePath(packageName: string, fromPath: string): string | undefined;
|
|
5
|
+
export declare function importSvelteIntegration(fromPath: string): typeof svelte | undefined;
|
|
6
|
+
export declare function importVueIntegration(fromPath: string): typeof vue | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importVueIntegration = exports.importSvelteIntegration = exports.getPackagePath = exports.setIsTrusted = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
let isTrusted = true;
|
|
6
|
+
function setIsTrusted(_isTrusted) {
|
|
7
|
+
isTrusted = _isTrusted;
|
|
8
|
+
}
|
|
9
|
+
exports.setIsTrusted = setIsTrusted;
|
|
10
|
+
function getPackagePath(packageName, fromPath) {
|
|
11
|
+
const paths = [];
|
|
12
|
+
if (isTrusted) {
|
|
13
|
+
paths.unshift(fromPath);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const packageJSONPath = require.resolve(`${packageName}/package.json`, {
|
|
17
|
+
paths,
|
|
18
|
+
});
|
|
19
|
+
return (0, path_1.dirname)(packageJSONPath);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.getPackagePath = getPackagePath;
|
|
26
|
+
function importEditorIntegration(packageName, fromPath) {
|
|
27
|
+
const pkgPath = getPackagePath(packageName, fromPath);
|
|
28
|
+
if (pkgPath) {
|
|
29
|
+
const main = (0, path_1.resolve)(pkgPath, 'dist', 'editor.cjs');
|
|
30
|
+
return require(main);
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
function importSvelteIntegration(fromPath) {
|
|
35
|
+
return importEditorIntegration('@astrojs/svelte', fromPath);
|
|
36
|
+
}
|
|
37
|
+
exports.importSvelteIntegration = importSvelteIntegration;
|
|
38
|
+
function importVueIntegration(fromPath) {
|
|
39
|
+
return importEditorIntegration('@astrojs/vue', fromPath);
|
|
40
|
+
}
|
|
41
|
+
exports.importVueIntegration = importVueIntegration;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { AstroCheck, DiagnosticSeverity } from './check';
|
|
1
|
+
export { AstroCheck, Diagnostic, DiagnosticSeverity, GetDiagnosticsResult } from './check';
|
|
2
|
+
export { offsetAt } from './core/documents';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiagnosticSeverity = exports.AstroCheck = void 0;
|
|
3
|
+
exports.offsetAt = exports.DiagnosticSeverity = exports.AstroCheck = void 0;
|
|
4
4
|
var check_1 = require("./check");
|
|
5
5
|
Object.defineProperty(exports, "AstroCheck", { enumerable: true, get: function () { return check_1.AstroCheck; } });
|
|
6
6
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return check_1.DiagnosticSeverity; } });
|
|
7
|
+
var documents_1 = require("./core/documents");
|
|
8
|
+
Object.defineProperty(exports, "offsetAt", { enumerable: true, get: function () { return documents_1.offsetAt; } });
|
|
@@ -5,6 +5,7 @@ import { DiagnosticsProvider } from '../../interfaces';
|
|
|
5
5
|
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
6
6
|
export declare enum DiagnosticCodes {
|
|
7
7
|
SPREAD_EXPECTED = 1005,
|
|
8
|
+
IS_NOT_A_MODULE = 2306,
|
|
8
9
|
DUPLICATED_JSX_ATTRIBUTES = 17001,
|
|
9
10
|
MUST_HAVE_PARENT_ELEMENT = 2657,
|
|
10
11
|
CANT_RETURN_OUTSIDE_FUNC = 1108,
|
|
@@ -13,6 +13,7 @@ const utils_1 = require("../utils");
|
|
|
13
13
|
var DiagnosticCodes;
|
|
14
14
|
(function (DiagnosticCodes) {
|
|
15
15
|
DiagnosticCodes[DiagnosticCodes["SPREAD_EXPECTED"] = 1005] = "SPREAD_EXPECTED";
|
|
16
|
+
DiagnosticCodes[DiagnosticCodes["IS_NOT_A_MODULE"] = 2306] = "IS_NOT_A_MODULE";
|
|
16
17
|
DiagnosticCodes[DiagnosticCodes["DUPLICATED_JSX_ATTRIBUTES"] = 17001] = "DUPLICATED_JSX_ATTRIBUTES";
|
|
17
18
|
DiagnosticCodes[DiagnosticCodes["MUST_HAVE_PARENT_ELEMENT"] = 2657] = "MUST_HAVE_PARENT_ELEMENT";
|
|
18
19
|
DiagnosticCodes[DiagnosticCodes["CANT_RETURN_OUTSIDE_FUNC"] = 1108] = "CANT_RETURN_OUTSIDE_FUNC";
|
|
@@ -206,6 +207,18 @@ function isNoIsolatedModuleError(diagnostic) {
|
|
|
206
207
|
* Some diagnostics have JSX-specific nomenclature or unclear description. Enhance them for more clarity.
|
|
207
208
|
*/
|
|
208
209
|
function enhanceIfNecessary(diagnostic) {
|
|
210
|
+
// When the language integrations are not installed, the content of the imported snapshot is empty
|
|
211
|
+
// As such, it triggers the "is not a module error", which we can enhance with a more helpful message for the related framework
|
|
212
|
+
if (diagnostic.code === DiagnosticCodes.IS_NOT_A_MODULE) {
|
|
213
|
+
if (diagnostic.message.includes('.svelte')) {
|
|
214
|
+
diagnostic.message +=
|
|
215
|
+
'\n\nIs the `@astrojs/svelte` package installed? You can add it to your project by running the following command: `astro add svelte`. If already installed, restarting the language server might be necessary in order for the change to take effect';
|
|
216
|
+
}
|
|
217
|
+
if (diagnostic.message.includes('.vue')) {
|
|
218
|
+
diagnostic.message +=
|
|
219
|
+
'\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
|
+
}
|
|
221
|
+
}
|
|
209
222
|
// JSX element has no closing tag. JSX -> HTML
|
|
210
223
|
if (diagnostic.code === DiagnosticCodes.JSX_NO_CLOSING_TAG) {
|
|
211
224
|
return {
|
|
@@ -9,9 +9,8 @@ const astro2tsx_1 = __importDefault(require("../astro2tsx"));
|
|
|
9
9
|
const vscode_uri_1 = require("vscode-uri");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
11
|
const DocumentSnapshot_1 = require("./DocumentSnapshot");
|
|
12
|
-
const svelte_language_integration_1 = require("@astrojs/svelte-language-integration");
|
|
13
|
-
const vue_language_integration_1 = require("@astrojs/vue-language-integration");
|
|
14
12
|
const utils_2 = require("../../../utils");
|
|
13
|
+
const importPackage_1 = require("../../../importPackage");
|
|
15
14
|
// Utilities to create Snapshots from different contexts
|
|
16
15
|
function createFromDocument(document) {
|
|
17
16
|
const { code } = (0, astro2tsx_1.default)(document.getText(), classNameFromFilename(document.getURL()));
|
|
@@ -75,10 +74,16 @@ function createFromFrameworkFilePath(filePath, framework) {
|
|
|
75
74
|
const originalText = typescript_1.default.sys.readFile(filePath) ?? '';
|
|
76
75
|
let code = '';
|
|
77
76
|
if (framework === 'svelte') {
|
|
78
|
-
|
|
77
|
+
const svelteIntegration = (0, importPackage_1.importSvelteIntegration)(filePath);
|
|
78
|
+
if (svelteIntegration) {
|
|
79
|
+
code = svelteIntegration.toTSX(originalText, className);
|
|
80
|
+
}
|
|
79
81
|
}
|
|
80
82
|
else if (framework === 'vue') {
|
|
81
|
-
|
|
83
|
+
const vueIntegration = (0, importPackage_1.importVueIntegration)(filePath);
|
|
84
|
+
if (vueIntegration) {
|
|
85
|
+
code = vueIntegration.toTSX(originalText, className);
|
|
86
|
+
}
|
|
82
87
|
}
|
|
83
88
|
return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, typescript_1.default.ScriptKind.TSX);
|
|
84
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -19,8 +19,6 @@
|
|
|
19
19
|
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --timeout 20000 --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@astrojs/vue-language-integration": "^0.1.1",
|
|
23
|
-
"@astrojs/svelte-language-integration": "^0.1.6",
|
|
24
22
|
"@vscode/emmet-helper": "^2.8.4",
|
|
25
23
|
"source-map": "^0.7.3",
|
|
26
24
|
"typescript": "~4.6.4",
|
|
@@ -33,6 +31,8 @@
|
|
|
33
31
|
"vscode-uri": "^3.0.3"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
34
|
+
"@astrojs/svelte": "^0.2.1",
|
|
35
|
+
"@astrojs/vue": "^0.2.1",
|
|
36
36
|
"@types/chai": "^4.3.0",
|
|
37
37
|
"@types/mocha": "^9.1.0",
|
|
38
38
|
"@types/sinon": "^10.0.11",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"cross-env": "^7.0.3",
|
|
43
43
|
"mocha": "^9.2.2",
|
|
44
44
|
"sinon": "^13.0.1",
|
|
45
|
-
"
|
|
45
|
+
"svelte": "^3.49.0",
|
|
46
|
+
"ts-node": "^10.7.0",
|
|
47
|
+
"vue": "^3.2.37"
|
|
46
48
|
}
|
|
47
49
|
}
|