@astrojs/language-server 2.1.3 → 2.2.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.d.ts +22 -7
- package/dist/check.js +44 -18
- package/dist/importPackage.d.ts +4 -1
- package/dist/importPackage.js +8 -3
- package/dist/index.js +2 -1
- package/dist/languageServerPlugin.js +3 -3
- package/package.json +1 -1
package/dist/check.d.ts
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
import * as kit from '@volar/kit';
|
|
2
|
-
|
|
2
|
+
import { Diagnostic, DiagnosticSeverity } from '@volar/language-server';
|
|
3
|
+
export { DiagnosticSeverity, Diagnostic };
|
|
3
4
|
export interface CheckResult {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
status: 'completed' | 'cancelled' | undefined;
|
|
6
|
+
fileChecked: number;
|
|
7
|
+
errors: number;
|
|
8
|
+
warnings: number;
|
|
9
|
+
hints: number;
|
|
10
|
+
fileResult: {
|
|
11
|
+
errors: kit.Diagnostic[];
|
|
12
|
+
fileUrl: URL;
|
|
13
|
+
fileContent: string;
|
|
14
|
+
}[];
|
|
7
15
|
}
|
|
8
16
|
export declare class AstroCheck {
|
|
9
17
|
private readonly workspacePath;
|
|
10
18
|
private readonly typescriptPath;
|
|
19
|
+
private readonly tsconfigPath;
|
|
11
20
|
private ts;
|
|
12
|
-
|
|
21
|
+
project: ReturnType<typeof kit.createProject>;
|
|
13
22
|
private linter;
|
|
14
|
-
constructor(workspacePath: string, typescriptPath: string | undefined);
|
|
23
|
+
constructor(workspacePath: string, typescriptPath: string | undefined, tsconfigPath: string | undefined);
|
|
15
24
|
/**
|
|
16
25
|
* Lint a list of files or the entire project and optionally log the errors found
|
|
17
26
|
* @param fileNames List of files to lint, if undefined, all files included in the project will be linted
|
|
18
27
|
* @param logErrors Whether to log errors by itself. This is disabled by default.
|
|
19
28
|
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
20
29
|
*/
|
|
21
|
-
lint(fileNames
|
|
30
|
+
lint({ fileNames, cancel, logErrors, }: {
|
|
31
|
+
fileNames?: string[] | undefined;
|
|
32
|
+
cancel?: () => boolean;
|
|
33
|
+
logErrors?: {
|
|
34
|
+
level: 'error' | 'warning' | 'hint';
|
|
35
|
+
} | undefined;
|
|
36
|
+
}): Promise<CheckResult>;
|
|
22
37
|
private initialize;
|
|
23
38
|
private getTsconfig;
|
|
24
39
|
}
|
package/dist/check.js
CHANGED
|
@@ -26,8 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.AstroCheck = exports.DiagnosticSeverity = void 0;
|
|
29
|
+
exports.AstroCheck = exports.Diagnostic = exports.DiagnosticSeverity = void 0;
|
|
30
30
|
const kit = __importStar(require("@volar/kit"));
|
|
31
|
+
const language_server_1 = require("@volar/language-server");
|
|
32
|
+
Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return language_server_1.Diagnostic; } });
|
|
33
|
+
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return language_server_1.DiagnosticSeverity; } });
|
|
31
34
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
32
35
|
const node_url_1 = require("node:url");
|
|
33
36
|
const index_js_1 = require("./core/index.js");
|
|
@@ -36,13 +39,11 @@ const vue_js_1 = require("./core/vue.js");
|
|
|
36
39
|
const astro_js_1 = __importDefault(require("./plugins/astro.js"));
|
|
37
40
|
const index_js_2 = __importDefault(require("./plugins/typescript/index.js"));
|
|
38
41
|
const utils_js_1 = require("./utils.js");
|
|
39
|
-
// Export those for downstream consumers
|
|
40
|
-
var language_server_1 = require("@volar/language-server");
|
|
41
|
-
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return language_server_1.DiagnosticSeverity; } });
|
|
42
42
|
class AstroCheck {
|
|
43
|
-
constructor(workspacePath, typescriptPath) {
|
|
43
|
+
constructor(workspacePath, typescriptPath, tsconfigPath) {
|
|
44
44
|
this.workspacePath = workspacePath;
|
|
45
45
|
this.typescriptPath = typescriptPath;
|
|
46
|
+
this.tsconfigPath = tsconfigPath;
|
|
46
47
|
this.initialize();
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -51,27 +52,51 @@ class AstroCheck {
|
|
|
51
52
|
* @param logErrors Whether to log errors by itself. This is disabled by default.
|
|
52
53
|
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
53
54
|
*/
|
|
54
|
-
async lint(fileNames = undefined, logErrors =
|
|
55
|
-
const files = fileNames !== undefined
|
|
56
|
-
|
|
57
|
-
:
|
|
58
|
-
|
|
55
|
+
async lint({ fileNames = undefined, cancel = () => false, logErrors = undefined, }) {
|
|
56
|
+
const files = fileNames !== undefined ? fileNames : this.project.languageHost.getScriptFileNames();
|
|
57
|
+
const result = {
|
|
58
|
+
status: undefined,
|
|
59
|
+
fileChecked: 0,
|
|
60
|
+
errors: 0,
|
|
61
|
+
warnings: 0,
|
|
62
|
+
hints: 0,
|
|
63
|
+
fileResult: [],
|
|
64
|
+
};
|
|
59
65
|
for (const file of files) {
|
|
60
|
-
|
|
66
|
+
if (cancel()) {
|
|
67
|
+
result.status = 'cancelled';
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
const fileDiagnostics = (await this.linter.check(file)).filter((diag) => {
|
|
71
|
+
const severity = diag.severity ?? language_server_1.DiagnosticSeverity.Error;
|
|
72
|
+
switch (logErrors?.level ?? 'error') {
|
|
73
|
+
case 'error':
|
|
74
|
+
return true;
|
|
75
|
+
case 'warning':
|
|
76
|
+
return severity <= language_server_1.DiagnosticSeverity.Warning;
|
|
77
|
+
case 'hint':
|
|
78
|
+
return severity <= language_server_1.DiagnosticSeverity.Hint;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
61
81
|
if (logErrors) {
|
|
62
|
-
this.linter.logErrors(file,
|
|
82
|
+
this.linter.logErrors(file, fileDiagnostics);
|
|
63
83
|
}
|
|
64
|
-
if (
|
|
84
|
+
if (fileDiagnostics.length > 0) {
|
|
65
85
|
const fileSnapshot = this.project.languageHost.getScriptSnapshot(file);
|
|
66
86
|
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
|
|
67
|
-
|
|
68
|
-
errors:
|
|
87
|
+
result.fileResult.push({
|
|
88
|
+
errors: fileDiagnostics,
|
|
69
89
|
fileContent: fileContent ?? '',
|
|
70
90
|
fileUrl: (0, node_url_1.pathToFileURL)(file),
|
|
71
91
|
});
|
|
92
|
+
result.errors += fileDiagnostics.filter((diag) => diag.severity === language_server_1.DiagnosticSeverity.Error).length;
|
|
93
|
+
result.warnings += fileDiagnostics.filter((diag) => diag.severity === language_server_1.DiagnosticSeverity.Warning).length;
|
|
94
|
+
result.hints += fileDiagnostics.filter((diag) => diag.severity === language_server_1.DiagnosticSeverity.Hint).length;
|
|
72
95
|
}
|
|
96
|
+
result.fileChecked += 1;
|
|
73
97
|
}
|
|
74
|
-
|
|
98
|
+
result.status = 'completed';
|
|
99
|
+
return result;
|
|
75
100
|
}
|
|
76
101
|
initialize() {
|
|
77
102
|
this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
|
|
@@ -106,8 +131,9 @@ class AstroCheck {
|
|
|
106
131
|
this.linter = kit.createLinter(config, this.project.languageHost);
|
|
107
132
|
}
|
|
108
133
|
getTsconfig() {
|
|
109
|
-
const
|
|
110
|
-
|
|
134
|
+
const searchPath = this.tsconfigPath ?? this.workspacePath;
|
|
135
|
+
const tsconfig = this.ts.findConfigFile(searchPath, this.ts.sys.fileExists) ||
|
|
136
|
+
this.ts.findConfigFile(searchPath, this.ts.sys.fileExists, 'jsconfig.json');
|
|
111
137
|
return tsconfig;
|
|
112
138
|
}
|
|
113
139
|
}
|
package/dist/importPackage.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ 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
4
|
export declare function setIsTrusted(_isTrusted: boolean): void;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 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
|
+
*/
|
|
8
|
+
export declare function getPackagePath(packageName: string, fromPath: string[], root?: boolean): string | undefined;
|
|
6
9
|
export declare function importSvelteIntegration(fromPath: string): typeof svelte | undefined;
|
|
7
10
|
export declare function importVueIntegration(fromPath: string): typeof vue | undefined;
|
|
8
11
|
export declare function importPrettier(fromPath: string): typeof prettier | undefined;
|
package/dist/importPackage.js
CHANGED
|
@@ -7,13 +7,18 @@ function setIsTrusted(_isTrusted) {
|
|
|
7
7
|
isTrusted = _isTrusted;
|
|
8
8
|
}
|
|
9
9
|
exports.setIsTrusted = setIsTrusted;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 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
|
|
12
|
+
*/
|
|
13
|
+
function getPackagePath(packageName, fromPath, root = true) {
|
|
11
14
|
const paths = [];
|
|
12
15
|
if (isTrusted) {
|
|
13
16
|
paths.unshift(...fromPath);
|
|
14
17
|
}
|
|
15
18
|
try {
|
|
16
|
-
return
|
|
19
|
+
return root
|
|
20
|
+
? (0, node_path_1.dirname)(require.resolve(packageName + '/package.json', { paths }))
|
|
21
|
+
: require.resolve(packageName, { paths });
|
|
17
22
|
}
|
|
18
23
|
catch (e) {
|
|
19
24
|
return undefined;
|
|
@@ -51,7 +56,7 @@ function importPrettier(fromPath) {
|
|
|
51
56
|
}
|
|
52
57
|
exports.importPrettier = importPrettier;
|
|
53
58
|
function getPrettierPluginPath(fromPath) {
|
|
54
|
-
const prettierPluginPath = getPackagePath('prettier-plugin-astro', [fromPath, __dirname]);
|
|
59
|
+
const prettierPluginPath = getPackagePath('prettier-plugin-astro', [fromPath, __dirname], false);
|
|
55
60
|
if (!prettierPluginPath) {
|
|
56
61
|
return undefined;
|
|
57
62
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DiagnosticSeverity = exports.AstroCheck = void 0;
|
|
3
|
+
exports.DiagnosticSeverity = exports.Diagnostic = exports.AstroCheck = void 0;
|
|
4
4
|
var check_js_1 = require("./check.js");
|
|
5
5
|
Object.defineProperty(exports, "AstroCheck", { enumerable: true, get: function () { return check_js_1.AstroCheck; } });
|
|
6
|
+
Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return check_js_1.Diagnostic; } });
|
|
6
7
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return check_js_1.DiagnosticSeverity; } });
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -68,8 +68,7 @@ const plugin = (initOptions, modules) => ({
|
|
|
68
68
|
languages: ['astro'],
|
|
69
69
|
ignoreIdeOptions: true,
|
|
70
70
|
resolveConfigOptions: {
|
|
71
|
-
//
|
|
72
|
-
// TODO: Upstream a fix for this
|
|
71
|
+
// This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
|
|
73
72
|
useCache: false,
|
|
74
73
|
},
|
|
75
74
|
additionalOptions: async (resolvedConfig) => {
|
|
@@ -77,7 +76,8 @@ const plugin = (initOptions, modules) => ({
|
|
|
77
76
|
if (!prettier || !prettierPluginPath) {
|
|
78
77
|
return [];
|
|
79
78
|
}
|
|
80
|
-
const hasPluginLoadedAlready = (await prettier.getSupportInfo()).languages.some((l) => l.name === 'astro')
|
|
79
|
+
const hasPluginLoadedAlready = (await prettier.getSupportInfo()).languages.some((l) => l.name === 'astro') ||
|
|
80
|
+
resolvedConfig.plugins?.includes('prettier-plugin-astro'); // getSupportInfo doesn't seems to work very well in Prettier 3 for plugins
|
|
81
81
|
return hasPluginLoadedAlready ? [] : [prettierPluginPath];
|
|
82
82
|
}
|
|
83
83
|
const plugins = [
|