@astrojs/language-server 2.6.3 → 2.7.1
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 +1 -2
- package/dist/check.js +12 -22
- package/dist/core/astro2tsx.d.ts +17 -9
- package/dist/core/astro2tsx.js +27 -41
- package/dist/core/index.d.ts +11 -13
- package/dist/core/index.js +106 -76
- package/dist/core/parseAstro.js +6 -1
- package/dist/core/parseCSS.d.ts +3 -3
- package/dist/core/parseCSS.js +35 -54
- package/dist/core/parseHTML.d.ts +4 -4
- package/dist/core/parseHTML.js +17 -16
- package/dist/core/parseJS.d.ts +3 -3
- package/dist/core/parseJS.js +34 -61
- package/dist/core/svelte.d.ts +10 -12
- package/dist/core/svelte.js +39 -16
- package/dist/core/utils.d.ts +3 -3
- package/dist/core/utils.js +21 -40
- package/dist/core/vue.d.ts +10 -12
- package/dist/core/vue.js +39 -16
- package/dist/languageServerPlugin.d.ts +3 -2
- package/dist/languageServerPlugin.js +103 -90
- package/dist/nodeServer.js +9 -1
- package/dist/plugins/astro.d.ts +2 -2
- package/dist/plugins/astro.js +64 -61
- package/dist/plugins/html.d.ts +2 -2
- package/dist/plugins/html.js +37 -37
- package/dist/plugins/typescript/codeActions.js +5 -5
- package/dist/plugins/typescript/completions.js +5 -5
- package/dist/plugins/typescript/index.d.ts +2 -2
- package/dist/plugins/typescript/index.js +49 -53
- package/dist/plugins/typescript-addons/index.d.ts +2 -2
- package/dist/plugins/typescript-addons/index.js +32 -28
- package/dist/utils.d.ts +1 -1
- package/package.json +14 -15
- package/types/jsx-runtime-fallback.d.ts +1 -0
package/dist/check.d.ts
CHANGED
|
@@ -19,8 +19,7 @@ export declare class AstroCheck {
|
|
|
19
19
|
private readonly typescriptPath;
|
|
20
20
|
private readonly tsconfigPath;
|
|
21
21
|
private ts;
|
|
22
|
-
|
|
23
|
-
private linter;
|
|
22
|
+
linter: ReturnType<(typeof kit)['createTypeScriptChecker']>;
|
|
24
23
|
constructor(workspacePath: string, typescriptPath: string | undefined, tsconfigPath: string | undefined);
|
|
25
24
|
/**
|
|
26
25
|
* Lint a list of files or the entire project and optionally log the errors found
|
package/dist/check.js
CHANGED
|
@@ -27,13 +27,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.AstroCheck = exports.DiagnosticSeverity = exports.Diagnostic = void 0;
|
|
30
|
+
const node_fs_1 = require("node:fs");
|
|
31
|
+
const node_url_1 = require("node:url");
|
|
30
32
|
const kit = __importStar(require("@volar/kit"));
|
|
31
33
|
const language_server_1 = require("@volar/language-server");
|
|
32
34
|
Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return language_server_1.Diagnostic; } });
|
|
33
35
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return language_server_1.DiagnosticSeverity; } });
|
|
34
36
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
35
|
-
const node_fs_1 = require("node:fs");
|
|
36
|
-
const node_url_1 = require("node:url");
|
|
37
37
|
const index_js_1 = require("./core/index.js");
|
|
38
38
|
const svelte_js_1 = require("./core/svelte.js");
|
|
39
39
|
const vue_js_1 = require("./core/vue.js");
|
|
@@ -54,7 +54,7 @@ class AstroCheck {
|
|
|
54
54
|
* @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
|
|
55
55
|
*/
|
|
56
56
|
async lint({ fileNames = undefined, cancel = () => false, logErrors = undefined, }) {
|
|
57
|
-
let files = fileNames !== undefined ? fileNames : this.
|
|
57
|
+
let files = fileNames !== undefined ? fileNames : this.linter.languageHost.getScriptFileNames();
|
|
58
58
|
const result = {
|
|
59
59
|
status: undefined,
|
|
60
60
|
fileChecked: 0,
|
|
@@ -86,7 +86,7 @@ class AstroCheck {
|
|
|
86
86
|
if (logErrors !== undefined && errorText) {
|
|
87
87
|
console.info(errorText);
|
|
88
88
|
}
|
|
89
|
-
const fileSnapshot = this.
|
|
89
|
+
const fileSnapshot = this.linter.languageHost.getScriptSnapshot(file);
|
|
90
90
|
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
|
|
91
91
|
result.fileResult.push({
|
|
92
92
|
errors: fileDiagnostics,
|
|
@@ -107,26 +107,17 @@ class AstroCheck {
|
|
|
107
107
|
this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
|
|
108
108
|
const tsconfigPath = this.getTsconfig();
|
|
109
109
|
const astroInstall = (0, utils_js_1.getAstroInstall)([this.workspacePath]);
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
services: {
|
|
117
|
-
typescript: (0, index_js_2.create)(),
|
|
118
|
-
astro: (0, astro_js_1.create)(),
|
|
119
|
-
},
|
|
120
|
-
};
|
|
110
|
+
const languages = [
|
|
111
|
+
(0, index_js_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts),
|
|
112
|
+
(0, svelte_js_1.getSvelteLanguageModule)(),
|
|
113
|
+
(0, vue_js_1.getVueLanguageModule)(),
|
|
114
|
+
];
|
|
115
|
+
const services = [(0, index_js_2.create)(this.ts), (0, astro_js_1.create)(this.ts)];
|
|
121
116
|
if (tsconfigPath) {
|
|
122
|
-
this.
|
|
123
|
-
{ extension: 'astro', isMixedContent: true, scriptKind: 7 },
|
|
124
|
-
{ extension: 'vue', isMixedContent: true, scriptKind: 7 },
|
|
125
|
-
{ extension: 'svelte', isMixedContent: true, scriptKind: 7 },
|
|
126
|
-
]);
|
|
117
|
+
this.linter = kit.createTypeScriptChecker(languages, services, tsconfigPath);
|
|
127
118
|
}
|
|
128
119
|
else {
|
|
129
|
-
this.
|
|
120
|
+
this.linter = kit.createTypeScriptInferredChecker(languages, services, () => {
|
|
130
121
|
return fast_glob_1.default.sync('**/*.astro', {
|
|
131
122
|
cwd: this.workspacePath,
|
|
132
123
|
ignore: ['node_modules'],
|
|
@@ -134,7 +125,6 @@ class AstroCheck {
|
|
|
134
125
|
});
|
|
135
126
|
});
|
|
136
127
|
}
|
|
137
|
-
this.linter = kit.createLinter(config, this.project.languageHost);
|
|
138
128
|
}
|
|
139
129
|
getTsconfig() {
|
|
140
130
|
if (this.tsconfigPath) {
|
package/dist/core/astro2tsx.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import type { ConvertToTSXOptions,
|
|
2
|
-
import {
|
|
1
|
+
import type { ConvertToTSXOptions, TSXResult } from '@astrojs/compiler/types';
|
|
2
|
+
import type { VirtualCode } from '@volar/language-core';
|
|
3
3
|
import { Range } from '@volar/language-server';
|
|
4
4
|
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
5
|
export interface LSPTSXRanges {
|
|
6
6
|
frontmatter: Range;
|
|
7
7
|
body: Range;
|
|
8
8
|
}
|
|
9
|
-
interface Astro2TSXResult {
|
|
10
|
-
virtualFile: VirtualFile;
|
|
11
|
-
diagnostics: DiagnosticMessage[];
|
|
12
|
-
ranges: LSPTSXRanges;
|
|
13
|
-
}
|
|
14
9
|
export declare function safeConvertToTSX(content: string, options: ConvertToTSXOptions): TSXResult | {
|
|
15
10
|
code: string;
|
|
16
11
|
map: {
|
|
@@ -44,5 +39,18 @@ export declare function safeConvertToTSX(content: string, options: ConvertToTSXO
|
|
|
44
39
|
};
|
|
45
40
|
};
|
|
46
41
|
export declare function getTSXRangesAsLSPRanges(tsx: TSXResult): LSPTSXRanges;
|
|
47
|
-
export declare function astro2tsx(input: string, fileName: string,
|
|
48
|
-
|
|
42
|
+
export declare function astro2tsx(input: string, fileName: string, htmlDocument: HTMLDocument): {
|
|
43
|
+
virtualCode: VirtualCode<string>;
|
|
44
|
+
diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {
|
|
45
|
+
code: 1000;
|
|
46
|
+
location: {
|
|
47
|
+
file: string;
|
|
48
|
+
line: number;
|
|
49
|
+
column: number;
|
|
50
|
+
length: number;
|
|
51
|
+
};
|
|
52
|
+
severity: 1;
|
|
53
|
+
text: string;
|
|
54
|
+
}[];
|
|
55
|
+
ranges: LSPTSXRanges;
|
|
56
|
+
};
|
package/dist/core/astro2tsx.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.astro2tsx = exports.getTSXRangesAsLSPRanges = exports.safeConvertToTSX = void 0;
|
|
4
4
|
const sync_1 = require("@astrojs/compiler/sync");
|
|
5
5
|
const sourcemap_codec_1 = require("@jridgewell/sourcemap-codec");
|
|
6
|
-
const language_core_1 = require("@volar/language-core");
|
|
7
6
|
const language_server_1 = require("@volar/language-server");
|
|
8
7
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
9
8
|
const utils_js_1 = require("./utils.js");
|
|
@@ -54,20 +53,20 @@ function getTSXRangesAsLSPRanges(tsx) {
|
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
55
|
exports.getTSXRangesAsLSPRanges = getTSXRangesAsLSPRanges;
|
|
57
|
-
function astro2tsx(input, fileName,
|
|
56
|
+
function astro2tsx(input, fileName, htmlDocument) {
|
|
58
57
|
const tsx = safeConvertToTSX(input, { filename: fileName });
|
|
59
58
|
return {
|
|
60
|
-
|
|
59
|
+
virtualCode: getVirtualCodeTSX(input, tsx, fileName, htmlDocument),
|
|
61
60
|
diagnostics: tsx.diagnostics,
|
|
62
61
|
ranges: getTSXRangesAsLSPRanges(tsx),
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
exports.astro2tsx = astro2tsx;
|
|
66
|
-
function
|
|
65
|
+
function getVirtualCodeTSX(input, tsx, fileName, htmlDocument) {
|
|
67
66
|
tsx.code = (0, utils_js_1.patchTSX)(tsx.code, fileName);
|
|
68
67
|
const v3Mappings = (0, sourcemap_codec_1.decode)(tsx.map.mappings);
|
|
69
|
-
const sourcedDoc = vscode_html_languageservice_1.TextDocument.create(
|
|
70
|
-
const genDoc = vscode_html_languageservice_1.TextDocument.create(
|
|
68
|
+
const sourcedDoc = vscode_html_languageservice_1.TextDocument.create('', 'astro', 0, input);
|
|
69
|
+
const genDoc = vscode_html_languageservice_1.TextDocument.create('', 'typescriptreact', 0, tsx.code);
|
|
71
70
|
const mappings = [];
|
|
72
71
|
let current;
|
|
73
72
|
for (let genLine = 0; genLine < v3Mappings.length; genLine++) {
|
|
@@ -92,31 +91,35 @@ function getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument) {
|
|
|
92
91
|
if (length > 0) {
|
|
93
92
|
const lastMapping = mappings.length ? mappings[mappings.length - 1] : undefined;
|
|
94
93
|
if (lastMapping &&
|
|
95
|
-
lastMapping.
|
|
96
|
-
lastMapping.
|
|
97
|
-
lastMapping.
|
|
98
|
-
lastMapping.sourceRange[1] = current.sourceOffset + length;
|
|
94
|
+
lastMapping.generatedOffsets[0] + lastMapping.lengths[0] === current.genOffset &&
|
|
95
|
+
lastMapping.sourceOffsets[0] + lastMapping.lengths[0] === current.sourceOffset) {
|
|
96
|
+
lastMapping.lengths[0] += length;
|
|
99
97
|
}
|
|
100
98
|
else {
|
|
101
99
|
// Disable features inside script tags. This is a bit annoying to do, I wonder if maybe leaving script tags
|
|
102
100
|
// unmapped would be better.
|
|
103
101
|
const node = htmlDocument.findNodeAt(current.sourceOffset);
|
|
104
102
|
const rangeCapabilities = node.tag !== 'script'
|
|
105
|
-
?
|
|
103
|
+
? {
|
|
104
|
+
verification: true,
|
|
105
|
+
completion: true,
|
|
106
|
+
semantic: true,
|
|
107
|
+
navigation: true,
|
|
108
|
+
structure: true,
|
|
109
|
+
format: false,
|
|
110
|
+
}
|
|
106
111
|
: {
|
|
112
|
+
verification: false,
|
|
107
113
|
completion: false,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
references: false,
|
|
113
|
-
referencesCodeLens: false,
|
|
114
|
-
rename: false,
|
|
115
|
-
semanticTokens: false,
|
|
114
|
+
semantic: false,
|
|
115
|
+
navigation: false,
|
|
116
|
+
structure: false,
|
|
117
|
+
format: false,
|
|
116
118
|
};
|
|
117
119
|
mappings.push({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
sourceOffsets: [current.sourceOffset],
|
|
121
|
+
generatedOffsets: [current.genOffset],
|
|
122
|
+
lengths: [length],
|
|
120
123
|
data: rangeCapabilities,
|
|
121
124
|
});
|
|
122
125
|
}
|
|
@@ -132,33 +135,16 @@ function getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument) {
|
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
|
-
const ast = ts.createSourceFile('/a.tsx', tsx.code, ts.ScriptTarget.ESNext);
|
|
136
|
-
if (ast.statements[0]) {
|
|
137
|
-
mappings.push({
|
|
138
|
-
sourceRange: [0, input.length],
|
|
139
|
-
generatedRange: [ast.statements[0].getStart(ast), tsx.code.length],
|
|
140
|
-
data: {},
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
138
|
return {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
capabilities: {
|
|
147
|
-
codeAction: true,
|
|
148
|
-
documentFormatting: false,
|
|
149
|
-
diagnostic: true,
|
|
150
|
-
documentSymbol: true,
|
|
151
|
-
inlayHint: true,
|
|
152
|
-
foldingRange: true,
|
|
153
|
-
},
|
|
154
|
-
codegenStacks: [],
|
|
139
|
+
id: 'tsx',
|
|
140
|
+
languageId: 'typescriptreact',
|
|
155
141
|
snapshot: {
|
|
156
142
|
getText: (start, end) => tsx.code.substring(start, end),
|
|
157
143
|
getLength: () => tsx.code.length,
|
|
158
144
|
getChangeRange: () => undefined,
|
|
159
145
|
},
|
|
160
146
|
mappings: mappings,
|
|
161
|
-
|
|
147
|
+
embeddedCodes: [],
|
|
162
148
|
};
|
|
163
149
|
}
|
|
164
150
|
//# sourceMappingURL=astro2tsx.js.map
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import type { DiagnosticMessage } from '@astrojs/compiler/types';
|
|
2
|
-
import {
|
|
3
|
-
import type ts from 'typescript
|
|
2
|
+
import { type CodeMapping, type LanguagePlugin, type VirtualCode } from '@volar/language-core';
|
|
3
|
+
import type ts from 'typescript';
|
|
4
4
|
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
5
|
import { type AstroInstall } from '../utils.js';
|
|
6
6
|
import { AstroMetadata } from './parseAstro';
|
|
7
|
-
export declare function getLanguageModule(astroInstall: AstroInstall | undefined, ts: typeof import('typescript
|
|
8
|
-
export declare class
|
|
9
|
-
sourceFileName: string;
|
|
10
|
-
snapshot: ts.IScriptSnapshot;
|
|
11
|
-
private readonly ts;
|
|
12
|
-
kind: FileKind;
|
|
13
|
-
capabilities: FileCapabilities;
|
|
7
|
+
export declare function getLanguageModule(astroInstall: AstroInstall | undefined, ts: typeof import('typescript')): LanguagePlugin<AstroVirtualCode>;
|
|
8
|
+
export declare class AstroVirtualCode implements VirtualCode {
|
|
14
9
|
fileName: string;
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
snapshot: ts.IScriptSnapshot;
|
|
11
|
+
id: string;
|
|
12
|
+
languageId: string;
|
|
13
|
+
mappings: CodeMapping[];
|
|
14
|
+
embeddedCodes: VirtualCode[];
|
|
17
15
|
astroMeta: AstroMetadata;
|
|
18
16
|
compilerDiagnostics: DiagnosticMessage[];
|
|
19
17
|
htmlDocument: HTMLDocument;
|
|
20
|
-
|
|
18
|
+
scriptCodeIds: string[];
|
|
21
19
|
codegenStacks: never[];
|
|
22
|
-
constructor(
|
|
20
|
+
constructor(fileName: string, snapshot: ts.IScriptSnapshot);
|
|
23
21
|
get hasCompilationErrors(): boolean;
|
|
24
22
|
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
25
23
|
onSnapshotUpdated(): void;
|
package/dist/core/index.js
CHANGED
|
@@ -23,9 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const language_core_1 = require("@volar/language-core");
|
|
26
|
+
exports.AstroVirtualCode = exports.getLanguageModule = void 0;
|
|
28
27
|
const path = __importStar(require("node:path"));
|
|
28
|
+
const language_core_1 = require("@volar/language-core");
|
|
29
29
|
const utils_js_1 = require("../utils.js");
|
|
30
30
|
const astro2tsx_1 = require("./astro2tsx");
|
|
31
31
|
const parseAstro_1 = require("./parseAstro");
|
|
@@ -34,79 +34,101 @@ const parseHTML_1 = require("./parseHTML");
|
|
|
34
34
|
const parseJS_js_1 = require("./parseJS.js");
|
|
35
35
|
function getLanguageModule(astroInstall, ts) {
|
|
36
36
|
return {
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
37
|
+
createVirtualCode(fileId, languageId, snapshot) {
|
|
38
|
+
if (languageId === 'astro') {
|
|
39
|
+
const fileName = fileId.includes('://') ? fileId.split('://')[1] : fileId;
|
|
40
|
+
return new AstroVirtualCode(fileName, snapshot);
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
updateVirtualCode(_fileId, astroCode, snapshot) {
|
|
44
|
+
astroCode.update(snapshot);
|
|
45
|
+
return astroCode;
|
|
44
46
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
typescript: {
|
|
48
|
+
extraFileExtensions: [{ extension: 'astro', isMixedContent: true, scriptKind: 7 }],
|
|
49
|
+
getScript(astroCode) {
|
|
50
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(astroCode)) {
|
|
51
|
+
if (code.id === 'tsx') {
|
|
52
|
+
return {
|
|
53
|
+
code,
|
|
54
|
+
extension: '.tsx',
|
|
55
|
+
scriptKind: 4,
|
|
56
|
+
};
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// If we don't have an Astro installation, add the fallback types from the language server.
|
|
75
|
-
// See the README in packages/language-server/types for more information.
|
|
76
|
-
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))));
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
},
|
|
61
|
+
getExtraScripts(fileName, astroCode) {
|
|
62
|
+
const result = [];
|
|
63
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(astroCode)) {
|
|
64
|
+
if (code.id.endsWith('.mjs') || code.id.endsWith('.mts')) {
|
|
65
|
+
const fileExtension = code.id.endsWith('.mjs') ? '.mjs' : '.mts';
|
|
66
|
+
result.push({
|
|
67
|
+
fileName: fileName + '.' + code.id,
|
|
68
|
+
code,
|
|
69
|
+
extension: fileExtension,
|
|
70
|
+
scriptKind: fileExtension === '.mjs'
|
|
71
|
+
? (1)
|
|
72
|
+
: (3),
|
|
73
|
+
});
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
},
|
|
78
|
+
resolveLanguageServiceHost(host) {
|
|
79
|
+
return {
|
|
80
|
+
...host,
|
|
81
|
+
getScriptFileNames() {
|
|
82
|
+
const languageServerTypesDirectory = (0, utils_js_1.getLanguageServerTypesDir)(ts);
|
|
83
|
+
const fileNames = host.getScriptFileNames();
|
|
84
|
+
const addedFileNames = [];
|
|
85
|
+
if (astroInstall) {
|
|
86
|
+
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath))));
|
|
87
|
+
// If Astro version is < 4.0.8, add jsx-runtime-augment.d.ts to the files to fake `JSX` being available from "astro/jsx-runtime".
|
|
88
|
+
// TODO: Remove this once a majority of users are on Astro 4.0.8+, erika - 2023-12-28
|
|
89
|
+
if (astroInstall.version.major < 4 ||
|
|
90
|
+
(astroInstall.version.major === 4 &&
|
|
91
|
+
astroInstall.version.minor === 0 &&
|
|
92
|
+
astroInstall.version.patch < 8)) {
|
|
93
|
+
addedFileNames.push(...['./jsx-runtime-augment.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// If we don't have an Astro installation, add the fallback types from the language server.
|
|
98
|
+
// See the README in packages/language-server/types for more information.
|
|
99
|
+
addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))));
|
|
100
|
+
}
|
|
101
|
+
return [...fileNames, ...addedFileNames];
|
|
102
|
+
},
|
|
103
|
+
getCompilationSettings() {
|
|
104
|
+
const baseCompilationSettings = host.getCompilationSettings();
|
|
105
|
+
return {
|
|
106
|
+
...baseCompilationSettings,
|
|
107
|
+
module: ts.ModuleKind.ESNext ?? 99,
|
|
108
|
+
target: ts.ScriptTarget.ESNext ?? 99,
|
|
109
|
+
jsx: ts.JsxEmit.Preserve ?? 1,
|
|
110
|
+
resolveJsonModule: true,
|
|
111
|
+
allowJs: true,
|
|
112
|
+
isolatedModules: true,
|
|
113
|
+
moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
|
|
114
|
+
!baseCompilationSettings.moduleResolution
|
|
115
|
+
? ts.ModuleResolutionKind.Node10
|
|
116
|
+
: baseCompilationSettings.moduleResolution,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
},
|
|
97
121
|
},
|
|
98
122
|
};
|
|
99
123
|
}
|
|
100
124
|
exports.getLanguageModule = getLanguageModule;
|
|
101
|
-
class
|
|
102
|
-
constructor(
|
|
103
|
-
this.
|
|
125
|
+
class AstroVirtualCode {
|
|
126
|
+
constructor(fileName, snapshot) {
|
|
127
|
+
this.fileName = fileName;
|
|
104
128
|
this.snapshot = snapshot;
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.capabilities = language_core_1.FileCapabilities.full;
|
|
129
|
+
this.id = 'root';
|
|
130
|
+
this.languageId = 'astro';
|
|
108
131
|
this.codegenStacks = [];
|
|
109
|
-
this.fileName = sourceFileName;
|
|
110
132
|
this.onSnapshotUpdated();
|
|
111
133
|
}
|
|
112
134
|
get hasCompilationErrors() {
|
|
@@ -119,9 +141,17 @@ class AstroFile {
|
|
|
119
141
|
onSnapshotUpdated() {
|
|
120
142
|
this.mappings = [
|
|
121
143
|
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
sourceOffsets: [0],
|
|
145
|
+
generatedOffsets: [0],
|
|
146
|
+
lengths: [this.snapshot.getLength()],
|
|
147
|
+
data: {
|
|
148
|
+
verification: true,
|
|
149
|
+
completion: true,
|
|
150
|
+
semantic: true,
|
|
151
|
+
navigation: true,
|
|
152
|
+
structure: true,
|
|
153
|
+
format: true,
|
|
154
|
+
},
|
|
125
155
|
},
|
|
126
156
|
];
|
|
127
157
|
this.compilerDiagnostics = [];
|
|
@@ -129,20 +159,20 @@ class AstroFile {
|
|
|
129
159
|
if (astroMetadata.diagnostics.length > 0) {
|
|
130
160
|
this.compilerDiagnostics.push(...astroMetadata.diagnostics);
|
|
131
161
|
}
|
|
132
|
-
const { htmlDocument,
|
|
162
|
+
const { htmlDocument, virtualCode: htmlVirtualCode } = (0, parseHTML_1.parseHTML)(this.snapshot, astroMetadata.frontmatter.status === 'closed'
|
|
133
163
|
? astroMetadata.frontmatter.position.end.offset
|
|
134
164
|
: 0);
|
|
135
165
|
this.htmlDocument = htmlDocument;
|
|
136
|
-
const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
141
|
-
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName,
|
|
166
|
+
const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.snapshot, htmlDocument, astroMetadata.ast);
|
|
167
|
+
this.scriptCodeIds = scriptTags.map((scriptTag) => scriptTag.id);
|
|
168
|
+
htmlVirtualCode.embeddedCodes.push(...(0, parseCSS_1.extractStylesheets)(this.snapshot, htmlDocument, astroMetadata.ast), ...scriptTags);
|
|
169
|
+
this.embeddedCodes = [];
|
|
170
|
+
this.embeddedCodes.push(htmlVirtualCode);
|
|
171
|
+
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, htmlDocument);
|
|
142
172
|
this.astroMeta = { ...astroMetadata, tsxRanges: tsx.ranges };
|
|
143
173
|
this.compilerDiagnostics.push(...tsx.diagnostics);
|
|
144
|
-
this.
|
|
174
|
+
this.embeddedCodes.push(tsx.virtualCode);
|
|
145
175
|
}
|
|
146
176
|
}
|
|
147
|
-
exports.
|
|
177
|
+
exports.AstroVirtualCode = AstroVirtualCode;
|
|
148
178
|
//# sourceMappingURL=index.js.map
|
package/dist/core/parseAstro.js
CHANGED
|
@@ -25,7 +25,12 @@ function safeParseAst(fileName, input, parseOptions) {
|
|
|
25
25
|
diagnostics: [
|
|
26
26
|
{
|
|
27
27
|
code: 1000,
|
|
28
|
-
location: {
|
|
28
|
+
location: {
|
|
29
|
+
file: fileName,
|
|
30
|
+
line: 1,
|
|
31
|
+
column: 1,
|
|
32
|
+
length: input.length,
|
|
33
|
+
},
|
|
29
34
|
severity: 1,
|
|
30
35
|
text: `The Astro compiler encountered an unknown error while parsing this file's AST. Please create an issue with your code and the error shown in the server's logs: https://github.com/withastro/language-tools/issues`,
|
|
31
36
|
},
|
package/dist/core/parseCSS.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ParseResult } from '@astrojs/compiler/types';
|
|
2
|
-
import {
|
|
3
|
-
import type ts from 'typescript
|
|
2
|
+
import { type VirtualCode } from '@volar/language-core';
|
|
3
|
+
import type ts from 'typescript';
|
|
4
4
|
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
-
export declare function extractStylesheets(
|
|
5
|
+
export declare function extractStylesheets(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
|
|
6
6
|
export declare function collectClassesAndIdsFromDocument(ast: ParseResult['ast']): string[];
|