@astrojs/language-server 2.0.16 → 2.0.17
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/core/astro2tsx.d.ts +11 -1
- package/dist/core/astro2tsx.js +36 -6
- package/dist/plugins/astro.js +1 -1
- package/package.json +1 -1
package/dist/core/astro2tsx.d.ts
CHANGED
|
@@ -2,5 +2,15 @@ import { VirtualFile } from '@volar/language-core';
|
|
|
2
2
|
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
3
3
|
export declare function astro2tsx(input: string, fileName: string, ts: typeof import('typescript/lib/tsserverlibrary.js'), htmlDocument: HTMLDocument): {
|
|
4
4
|
virtualFile: VirtualFile;
|
|
5
|
-
diagnostics: import("@astrojs/compiler").DiagnosticMessage[]
|
|
5
|
+
diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {
|
|
6
|
+
code: 1000;
|
|
7
|
+
location: {
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
column: number;
|
|
11
|
+
length: number;
|
|
12
|
+
};
|
|
13
|
+
severity: 1;
|
|
14
|
+
text: string;
|
|
15
|
+
}[];
|
|
6
16
|
};
|
package/dist/core/astro2tsx.js
CHANGED
|
@@ -6,8 +6,36 @@ const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
|
|
|
6
6
|
const language_core_1 = require("@volar/language-core");
|
|
7
7
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
|
+
function safeConvertToTSX(content, options) {
|
|
10
|
+
try {
|
|
11
|
+
const tsx = (0, sync_1.convertToTSX)(content, { filename: options.filename });
|
|
12
|
+
return tsx;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
console.error(`There was an error transforming ${options.filename} to TSX. An empty file will be returned instead. Please create an issue: https://github.com/withastro/language-tools/issues\nError: ${e}.`);
|
|
16
|
+
return {
|
|
17
|
+
code: '',
|
|
18
|
+
map: {
|
|
19
|
+
file: options.filename ?? '',
|
|
20
|
+
sources: [],
|
|
21
|
+
sourcesContent: [],
|
|
22
|
+
names: [],
|
|
23
|
+
mappings: '',
|
|
24
|
+
version: 0,
|
|
25
|
+
},
|
|
26
|
+
diagnostics: [
|
|
27
|
+
{
|
|
28
|
+
code: 1000,
|
|
29
|
+
location: { file: options.filename, line: 1, column: 1, length: content.length },
|
|
30
|
+
severity: 1,
|
|
31
|
+
text: `The Astro compiler encountered an unknown error while parsing this file. Please create an issue with your code and the error shown in the server's logs: https://github.com/withastro/language-tools/issues`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
9
37
|
function astro2tsx(input, fileName, ts, htmlDocument) {
|
|
10
|
-
const tsx = (
|
|
38
|
+
const tsx = safeConvertToTSX(input, { filename: fileName });
|
|
11
39
|
return {
|
|
12
40
|
virtualFile: getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument),
|
|
13
41
|
diagnostics: tsx.diagnostics,
|
|
@@ -90,11 +118,13 @@ function getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument) {
|
|
|
90
118
|
data: {},
|
|
91
119
|
});
|
|
92
120
|
const ast = ts.createSourceFile('/a.tsx', tsx.code, ts.ScriptTarget.ESNext);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
121
|
+
if (ast.statements[0]) {
|
|
122
|
+
mappings.push({
|
|
123
|
+
sourceRange: [0, input.length],
|
|
124
|
+
generatedRange: [ast.statements[0].getStart(ast), tsx.code.length],
|
|
125
|
+
data: {},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
98
128
|
return {
|
|
99
129
|
fileName: fileName + '.tsx',
|
|
100
130
|
kind: language_core_1.FileKind.TypeScriptHostFile,
|
package/dist/plugins/astro.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.default = () => (context, modules) => {
|
|
|
37
37
|
return file.compilerDiagnostics.map(compilerMessageToDiagnostic);
|
|
38
38
|
function compilerMessageToDiagnostic(message) {
|
|
39
39
|
return {
|
|
40
|
-
message: message.text + '\n\n' + message.hint,
|
|
40
|
+
message: message.text + (message.hint ? '\n\n' + message.hint : ''),
|
|
41
41
|
range: language_server_1.Range.create(message.location.line - 1, message.location.column - 1, message.location.line, message.location.length),
|
|
42
42
|
code: message.code,
|
|
43
43
|
severity: message.severity,
|