@astrojs/language-server 2.5.3 → 2.5.5

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
@@ -21,6 +21,7 @@ export declare class AstroCheck {
21
21
  private ts;
22
22
  project: ReturnType<typeof kit.createProject>;
23
23
  private linter;
24
+ private skipJSX;
24
25
  constructor(workspacePath: string, typescriptPath: string | undefined, tsconfigPath: string | undefined);
25
26
  /**
26
27
  * Lint a list of files or the entire project and optionally log the errors found
package/dist/check.js CHANGED
@@ -45,6 +45,8 @@ class AstroCheck {
45
45
  this.workspacePath = workspacePath;
46
46
  this.typescriptPath = typescriptPath;
47
47
  this.tsconfigPath = tsconfigPath;
48
+ // TODO: Remove this when the JSX typing issue is fixed
49
+ this.skipJSX = false;
48
50
  this.initialize();
49
51
  }
50
52
  /**
@@ -54,7 +56,10 @@ class AstroCheck {
54
56
  * @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
55
57
  */
56
58
  async lint({ fileNames = undefined, cancel = () => false, logErrors = undefined, }) {
57
- const files = fileNames !== undefined ? fileNames : this.project.languageHost.getScriptFileNames();
59
+ let files = fileNames !== undefined ? fileNames : this.project.languageHost.getScriptFileNames();
60
+ if (this.skipJSX) {
61
+ files = files.filter((file) => !file.endsWith('.jsx') && !file.endsWith('.tsx'));
62
+ }
58
63
  const result = {
59
64
  status: undefined,
60
65
  fileChecked: 0,
@@ -134,6 +139,11 @@ class AstroCheck {
134
139
  });
135
140
  });
136
141
  }
142
+ const files = this.project.languageHost.getScriptFileNames();
143
+ if (files.some((file) => file.endsWith('.jsx') || file.endsWith('.tsx'))) {
144
+ console.warn('\x1b[33;1mWARNING:\x1b[0m Checking `.jsx` and `.tsx` files is temporarily disabled due to an issue in the Astro language server and TypeScript. See https://github.com/withastro/language-tools/issues/727 for more details. In the meantime, such files can be checked using `tsc --noEmit`.');
145
+ this.skipJSX = true;
146
+ }
137
147
  this.linter = kit.createLinter(config, this.project.languageHost);
138
148
  }
139
149
  getTsconfig() {
@@ -157,7 +157,10 @@ function findEventAttributes(ast) {
157
157
  const eventAttribute = child.attributes.find((attr) => htmlEventAttributes.includes(attr.name) && attr.kind === 'quoted');
158
158
  if (eventAttribute && eventAttribute.position) {
159
159
  eventAttrs.push({
160
- content: eventAttribute.value,
160
+ // Add a semicolon to the end of the event attribute to attempt to prevent errors from spreading to the rest of the document
161
+ // This is not perfect, but it's better than nothing
162
+ // See: https://github.com/microsoft/vscode/blob/e8e04769ec817a3374c3eaa26a08d3ae491820d5/extensions/html-language-features/server/src/modes/embeddedSupport.ts#L192
163
+ content: eventAttribute.value + ';',
161
164
  startOffset: eventAttribute.position.start.offset + `${eventAttribute.name}="`.length,
162
165
  });
163
166
  }
@@ -9,4 +9,4 @@ export declare enum DiagnosticCodes {
9
9
  JSX_NO_CLOSING_TAG = 17008,
10
10
  JSX_ELEMENT_NO_CALL = 2604
11
11
  }
12
- export declare function enhancedProvideSemanticDiagnostics(originalDiagnostics: Diagnostic[], documentLineCount: number): Diagnostic[];
12
+ export declare function enhancedProvideSemanticDiagnostics(originalDiagnostics: Diagnostic[], astroLineCount?: number | undefined): Diagnostic[];
@@ -14,20 +14,31 @@ var DiagnosticCodes;
14
14
  DiagnosticCodes[DiagnosticCodes["JSX_NO_CLOSING_TAG"] = 17008] = "JSX_NO_CLOSING_TAG";
15
15
  DiagnosticCodes[DiagnosticCodes["JSX_ELEMENT_NO_CALL"] = 2604] = "JSX_ELEMENT_NO_CALL";
16
16
  })(DiagnosticCodes || (exports.DiagnosticCodes = DiagnosticCodes = {}));
17
- function enhancedProvideSemanticDiagnostics(originalDiagnostics, documentLineCount) {
17
+ function enhancedProvideSemanticDiagnostics(originalDiagnostics, astroLineCount) {
18
18
  const diagnostics = originalDiagnostics
19
- .filter((diagnostic) => diagnostic.range.start.line <= documentLineCount &&
19
+ .filter((diagnostic) => (astroLineCount ? diagnostic.range.start.line <= astroLineCount : true) &&
20
20
  isNoCantReturnOutsideFunction(diagnostic) &&
21
21
  isNoIsolatedModuleError(diagnostic) &&
22
22
  isNoJsxCannotHaveMultipleAttrsError(diagnostic))
23
- .map(enhanceIfNecessary);
23
+ .map((diag) => astroLineCount ? generalEnhancements(astroEnhancements(diag)) : generalEnhancements(diag));
24
24
  return diagnostics;
25
25
  }
26
26
  exports.enhancedProvideSemanticDiagnostics = enhancedProvideSemanticDiagnostics;
27
+ // General enhancements that apply to all files
28
+ function generalEnhancements(diagnostic) {
29
+ if (diagnostic.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
30
+ diagnostic.message.includes('astro:content')) {
31
+ diagnostic.message +=
32
+ "\n\nIf you're using content collections, make sure to run `astro dev`, `astro build` or `astro sync` to first generate the types so you can import from them. If you already ran one of those commands, restarting the language server might be necessary in order for the change to take effect.";
33
+ return diagnostic;
34
+ }
35
+ return diagnostic;
36
+ }
27
37
  /**
28
- * Some diagnostics have JSX-specific nomenclature or unclear description. Enhance them for more clarity.
38
+ * Astro-specific enhancements. For instance, when the user tries to import a component from a framework that is not installed
39
+ * or a difference with JSX needing a different error message
29
40
  */
30
- function enhanceIfNecessary(diagnostic) {
41
+ function astroEnhancements(diagnostic) {
31
42
  // When the language integrations are not installed, the content of the imported snapshot is empty
32
43
  // As such, it triggers the "is not a module error", which we can enhance with a more helpful message for the related framework
33
44
  if (diagnostic.code === DiagnosticCodes.IS_NOT_A_MODULE) {
@@ -41,12 +52,6 @@ function enhanceIfNecessary(diagnostic) {
41
52
  }
42
53
  return diagnostic;
43
54
  }
44
- if (diagnostic.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
45
- diagnostic.message.includes('astro:content')) {
46
- diagnostic.message +=
47
- "\n\nIf you're using content collections, make sure to run `astro dev`, `astro build` or `astro sync` to first generate the types so you can import from them. If you already ran one of those commands, restarting the language server might be necessary in order for the change to take effect.";
48
- return diagnostic;
49
- }
50
55
  // JSX element has no closing tag. JSX -> HTML
51
56
  if (diagnostic.code === DiagnosticCodes.JSX_NO_CLOSING_TAG) {
52
57
  return {
@@ -112,16 +112,17 @@ const create = () => (context, modules) => {
112
112
  async provideSemanticDiagnostics(document, token) {
113
113
  const [_, source] = context.documents.getVirtualFileByUri(document.uri);
114
114
  const file = source?.root;
115
- if (!(file instanceof index_js_1.AstroFile))
116
- return null;
117
- // If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
118
- if (file.hasCompilationErrors)
119
- return null;
115
+ let astroDocument = undefined;
116
+ if (file instanceof index_js_1.AstroFile) {
117
+ // If we have compiler errors, our TSX isn't valid so don't bother showing TS errors
118
+ if (file.hasCompilationErrors)
119
+ return null;
120
+ astroDocument = context.documents.getDocumentByFileName(file.snapshot, file.sourceFileName);
121
+ }
120
122
  const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics(document, token);
121
123
  if (!diagnostics)
122
124
  return null;
123
- const astroDocument = context.documents.getDocumentByFileName(file.snapshot, file.sourceFileName);
124
- return (0, diagnostics_js_1.enhancedProvideSemanticDiagnostics)(diagnostics, astroDocument.lineCount);
125
+ return (0, diagnostics_js_1.enhancedProvideSemanticDiagnostics)(diagnostics, astroDocument?.lineCount);
125
126
  },
126
127
  };
127
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {