@astrojs/language-server 2.6.2 → 2.7.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
@@ -19,8 +19,7 @@ export declare class AstroCheck {
19
19
  private readonly typescriptPath;
20
20
  private readonly tsconfigPath;
21
21
  private ts;
22
- project: ReturnType<typeof kit.createProject>;
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
@@ -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.project.languageHost.getScriptFileNames();
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.project.languageHost.getScriptSnapshot(file);
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 config = {
111
- languages: {
112
- astro: (0, index_js_1.getLanguageModule)(typeof astroInstall === 'string' ? undefined : astroInstall, this.ts),
113
- svelte: (0, svelte_js_1.getSvelteLanguageModule)(),
114
- vue: (0, vue_js_1.getVueLanguageModule)(),
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.project = kit.createProject(tsconfigPath, [
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.project = kit.createInferredProject(this.workspacePath, () => {
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) {
@@ -1,16 +1,11 @@
1
- import type { ConvertToTSXOptions, DiagnosticMessage, TSXResult } from '@astrojs/compiler/types';
2
- import { VirtualFile } from '@volar/language-core';
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, ts: typeof import('typescript/lib/tsserverlibrary.js'), htmlDocument: HTMLDocument): Astro2TSXResult;
48
- export {};
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
+ };
@@ -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, ts, htmlDocument) {
56
+ function astro2tsx(input, fileName, htmlDocument) {
58
57
  const tsx = safeConvertToTSX(input, { filename: fileName });
59
58
  return {
60
- virtualFile: getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument),
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 getVirtualFileTSX(input, tsx, fileName, ts, htmlDocument) {
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(fileName, 'astro', 0, input);
70
- const genDoc = vscode_html_languageservice_1.TextDocument.create(fileName + '.tsx', 'typescriptreact', 0, tsx.code);
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.generatedRange[1] === current.genOffset &&
96
- lastMapping.sourceRange[1] === current.sourceOffset) {
97
- lastMapping.generatedRange[1] = current.genOffset + length;
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
- ? language_core_1.FileRangeCapabilities.full
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
- definition: false,
109
- diagnostic: false,
110
- displayWithLink: false,
111
- hover: false,
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
- sourceRange: [current.sourceOffset, current.sourceOffset + length],
119
- generatedRange: [current.genOffset, current.genOffset + length],
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
- fileName: fileName + '.tsx',
145
- kind: language_core_1.FileKind.TypeScriptHostFile,
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
- embeddedFiles: [],
147
+ embeddedCodes: [],
162
148
  };
163
149
  }
164
150
  //# sourceMappingURL=astro2tsx.js.map
@@ -1,25 +1,23 @@
1
1
  import type { DiagnosticMessage } from '@astrojs/compiler/types';
2
- import { FileCapabilities, FileKind, type Language, type VirtualFile } from '@volar/language-core';
3
- import type ts from 'typescript/lib/tsserverlibrary';
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/lib/tsserverlibrary.js')): Language<AstroFile>;
8
- export declare class AstroFile implements VirtualFile {
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
- mappings: VirtualFile['mappings'];
16
- embeddedFiles: VirtualFile['embeddedFiles'];
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
- scriptFiles: string[];
18
+ scriptCodeIds: string[];
21
19
  codegenStacks: never[];
22
- constructor(sourceFileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript/lib/tsserverlibrary.js'));
20
+ constructor(fileName: string, snapshot: ts.IScriptSnapshot);
23
21
  get hasCompilationErrors(): boolean;
24
22
  update(newSnapshot: ts.IScriptSnapshot): void;
25
23
  onSnapshotUpdated(): void;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.AstroFile = exports.getLanguageModule = void 0;
26
+ exports.AstroVirtualCode = exports.getLanguageModule = void 0;
27
27
  const language_core_1 = require("@volar/language-core");
28
28
  const path = __importStar(require("node:path"));
29
29
  const utils_js_1 = require("../utils.js");
@@ -34,79 +34,98 @@ const parseHTML_1 = require("./parseHTML");
34
34
  const parseJS_js_1 = require("./parseJS.js");
35
35
  function getLanguageModule(astroInstall, ts) {
36
36
  return {
37
- createVirtualFile(fileName, snapshot) {
38
- if (fileName.endsWith('.astro')) {
39
- return new AstroFile(fileName, snapshot, ts);
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
- updateVirtualFile(astroFile, snapshot) {
43
- astroFile.update(snapshot);
43
+ updateVirtualCode(_fileId, astroCode, snapshot) {
44
+ astroCode.update(snapshot);
45
+ return astroCode;
44
46
  },
45
- resolveHost(host) {
46
- return {
47
- ...host,
48
- resolveModuleName(moduleName, impliedNodeFormat) {
49
- if (impliedNodeFormat === ts.ModuleKind.ESNext &&
50
- (moduleName.endsWith('.astro') ||
51
- moduleName.endsWith('.vue') ||
52
- moduleName.endsWith('.svelte'))) {
53
- return `${moduleName}.js`;
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
- return host.resolveModuleName?.(moduleName, impliedNodeFormat) ?? moduleName;
56
- },
57
- getScriptFileNames() {
58
- const languageServerTypesDirectory = (0, utils_js_1.getLanguageServerTypesDir)(ts);
59
- const fileNames = host.getScriptFileNames();
60
- const addedFileNames = [];
61
- if (astroInstall) {
62
- addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath))));
63
- // 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".
64
- // TODO: Remove this once a majority of users are on Astro 4.0.8+, erika - 2023-12-28
65
- if (astroInstall.version.major < 4 ||
66
- (astroInstall.version.major === 4 &&
67
- astroInstall.version.minor === 0 &&
68
- astroInstall.version.patch < 8)) {
69
- addedFileNames.push(...['./jsx-runtime-augment.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))));
70
- console.log(addedFileNames);
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
+ result.push({
66
+ fileName: fileName + '.' + code.id,
67
+ code,
68
+ extension: '.mjs',
69
+ scriptKind: 1,
70
+ });
77
71
  }
78
- return [...fileNames, ...addedFileNames];
79
- },
80
- getCompilationSettings() {
81
- const baseCompilationSettings = host.getCompilationSettings();
82
- return {
83
- ...baseCompilationSettings,
84
- module: ts.ModuleKind.ESNext ?? 99,
85
- target: ts.ScriptTarget.ESNext ?? 99,
86
- jsx: ts.JsxEmit.Preserve ?? 1,
87
- resolveJsonModule: true,
88
- allowJs: true,
89
- isolatedModules: true,
90
- moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
91
- !baseCompilationSettings.moduleResolution
92
- ? ts.ModuleResolutionKind.Node10
93
- : baseCompilationSettings.moduleResolution,
94
- };
95
- },
96
- };
72
+ }
73
+ return result;
74
+ },
75
+ resolveLanguageServiceHost(host) {
76
+ return {
77
+ ...host,
78
+ getScriptFileNames() {
79
+ const languageServerTypesDirectory = (0, utils_js_1.getLanguageServerTypesDir)(ts);
80
+ const fileNames = host.getScriptFileNames();
81
+ const addedFileNames = [];
82
+ if (astroInstall) {
83
+ addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(astroInstall.path, filePath))));
84
+ // 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".
85
+ // TODO: Remove this once a majority of users are on Astro 4.0.8+, erika - 2023-12-28
86
+ if (astroInstall.version.major < 4 ||
87
+ (astroInstall.version.major === 4 &&
88
+ astroInstall.version.minor === 0 &&
89
+ astroInstall.version.patch < 8)) {
90
+ addedFileNames.push(...['./jsx-runtime-augment.d.ts'].map((filePath) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))));
91
+ }
92
+ }
93
+ else {
94
+ // If we don't have an Astro installation, add the fallback types from the language server.
95
+ // See the README in packages/language-server/types for more information.
96
+ addedFileNames.push(...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) => ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))));
97
+ }
98
+ return [...fileNames, ...addedFileNames];
99
+ },
100
+ getCompilationSettings() {
101
+ const baseCompilationSettings = host.getCompilationSettings();
102
+ return {
103
+ ...baseCompilationSettings,
104
+ module: ts.ModuleKind.ESNext ?? 99,
105
+ target: ts.ScriptTarget.ESNext ?? 99,
106
+ jsx: ts.JsxEmit.Preserve ?? 1,
107
+ resolveJsonModule: true,
108
+ allowJs: true,
109
+ isolatedModules: true,
110
+ moduleResolution: baseCompilationSettings.moduleResolution === ts.ModuleResolutionKind.Classic ||
111
+ !baseCompilationSettings.moduleResolution
112
+ ? ts.ModuleResolutionKind.Node10
113
+ : baseCompilationSettings.moduleResolution,
114
+ };
115
+ },
116
+ };
117
+ },
97
118
  },
98
119
  };
99
120
  }
100
121
  exports.getLanguageModule = getLanguageModule;
101
- class AstroFile {
102
- constructor(sourceFileName, snapshot, ts) {
103
- this.sourceFileName = sourceFileName;
122
+ class AstroVirtualCode {
123
+ constructor(fileName, snapshot) {
124
+ this.fileName = fileName;
104
125
  this.snapshot = snapshot;
105
- this.ts = ts;
106
- this.kind = language_core_1.FileKind.TextFile;
107
- this.capabilities = language_core_1.FileCapabilities.full;
126
+ this.id = 'root';
127
+ this.languageId = 'astro';
108
128
  this.codegenStacks = [];
109
- this.fileName = sourceFileName;
110
129
  this.onSnapshotUpdated();
111
130
  }
112
131
  get hasCompilationErrors() {
@@ -119,9 +138,17 @@ class AstroFile {
119
138
  onSnapshotUpdated() {
120
139
  this.mappings = [
121
140
  {
122
- sourceRange: [0, this.snapshot.getLength()],
123
- generatedRange: [0, this.snapshot.getLength()],
124
- data: language_core_1.FileRangeCapabilities.full,
141
+ sourceOffsets: [0],
142
+ generatedOffsets: [0],
143
+ lengths: [this.snapshot.getLength()],
144
+ data: {
145
+ verification: true,
146
+ completion: true,
147
+ semantic: true,
148
+ navigation: true,
149
+ structure: true,
150
+ format: true,
151
+ },
125
152
  },
126
153
  ];
127
154
  this.compilerDiagnostics = [];
@@ -129,20 +156,20 @@ class AstroFile {
129
156
  if (astroMetadata.diagnostics.length > 0) {
130
157
  this.compilerDiagnostics.push(...astroMetadata.diagnostics);
131
158
  }
132
- const { htmlDocument, virtualFile: htmlVirtualFile } = (0, parseHTML_1.parseHTML)(this.fileName, this.snapshot, astroMetadata.frontmatter.status === 'closed'
159
+ const { htmlDocument, virtualCode: htmlVirtualCode } = (0, parseHTML_1.parseHTML)(this.snapshot, astroMetadata.frontmatter.status === 'closed'
133
160
  ? astroMetadata.frontmatter.position.end.offset
134
161
  : 0);
135
162
  this.htmlDocument = htmlDocument;
136
- const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.fileName, this.snapshot, htmlDocument, astroMetadata.ast);
137
- this.scriptFiles = scriptTags.map((scriptTag) => scriptTag.fileName);
138
- htmlVirtualFile.embeddedFiles.push(...(0, parseCSS_1.extractStylesheets)(this.fileName, this.snapshot, htmlDocument, astroMetadata.ast), ...scriptTags);
139
- this.embeddedFiles = [];
140
- this.embeddedFiles.push(htmlVirtualFile);
141
- const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, this.ts, htmlDocument);
163
+ const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.snapshot, htmlDocument, astroMetadata.ast);
164
+ this.scriptCodeIds = scriptTags.map((scriptTag) => scriptTag.id);
165
+ htmlVirtualCode.embeddedCodes.push(...(0, parseCSS_1.extractStylesheets)(this.snapshot, htmlDocument, astroMetadata.ast), ...scriptTags);
166
+ this.embeddedCodes = [];
167
+ this.embeddedCodes.push(htmlVirtualCode);
168
+ const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, htmlDocument);
142
169
  this.astroMeta = { ...astroMetadata, tsxRanges: tsx.ranges };
143
170
  this.compilerDiagnostics.push(...tsx.diagnostics);
144
- this.embeddedFiles.push(tsx.virtualFile);
171
+ this.embeddedCodes.push(tsx.virtualCode);
145
172
  }
146
173
  }
147
- exports.AstroFile = AstroFile;
174
+ exports.AstroVirtualCode = AstroVirtualCode;
148
175
  //# sourceMappingURL=index.js.map
@@ -25,7 +25,12 @@ function safeParseAst(fileName, input, parseOptions) {
25
25
  diagnostics: [
26
26
  {
27
27
  code: 1000,
28
- location: { file: fileName, line: 1, column: 1, length: input.length },
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
  },
@@ -1,6 +1,6 @@
1
1
  import type { ParseResult } from '@astrojs/compiler/types';
2
- import { VirtualFile } from '@volar/language-core';
3
- import type ts from 'typescript/lib/tsserverlibrary';
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(fileName: string, snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualFile[];
5
+ export declare function extractStylesheets(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
6
6
  export declare function collectClassesAndIdsFromDocument(ast: ParseResult['ast']): string[];