@astrojs/language-server 2.1.4 → 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 CHANGED
@@ -1,24 +1,39 @@
1
1
  import * as kit from '@volar/kit';
2
- export { DiagnosticSeverity, type Diagnostic } from '@volar/language-server';
2
+ import { Diagnostic, DiagnosticSeverity } from '@volar/language-server';
3
+ export { DiagnosticSeverity, Diagnostic };
3
4
  export interface CheckResult {
4
- errors: kit.Diagnostic[];
5
- fileUrl: URL;
6
- fileContent: string;
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
- private project;
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?: string[] | undefined, logErrors?: boolean): Promise<CheckResult[]>;
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 = false) {
55
- const files = fileNames !== undefined
56
- ? fileNames
57
- : this.project.languageHost.getScriptFileNames().filter((file) => file.endsWith('.astro'));
58
- const errors = [];
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
- const fileErrors = await this.linter.check(file);
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, fileErrors);
82
+ this.linter.logErrors(file, fileDiagnostics);
63
83
  }
64
- if (fileErrors.length > 0) {
84
+ if (fileDiagnostics.length > 0) {
65
85
  const fileSnapshot = this.project.languageHost.getScriptSnapshot(file);
66
86
  const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
67
- errors.push({
68
- errors: fileErrors,
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
- return errors;
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 tsconfig = this.ts.findConfigFile(this.workspacePath, this.ts.sys.fileExists) ||
110
- this.ts.findConfigFile(this.workspacePath, this.ts.sys.fileExists, 'jsconfig.json');
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/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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {