Home / Class/ AstroVirtualCode Class — astro Architecture

AstroVirtualCode Class — astro Architecture

Architecture documentation for the AstroVirtualCode class in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  0f9bebbf_2381_aa6d_9fed_bd6c8978c2c3["AstroVirtualCode"]
  3d0a8903_cb4c_d139_320b_9571e3568661["index.ts"]
  0f9bebbf_2381_aa6d_9fed_bd6c8978c2c3 -->|defined in| 3d0a8903_cb4c_d139_320b_9571e3568661
  daabf67b_260e_4861_5614_7e9d0bac041d["constructor()"]
  0f9bebbf_2381_aa6d_9fed_bd6c8978c2c3 -->|method| daabf67b_260e_4861_5614_7e9d0bac041d
  b54a698d_da0f_0056_cd12_67fd27091b47["hasCompilationErrors()"]
  0f9bebbf_2381_aa6d_9fed_bd6c8978c2c3 -->|method| b54a698d_da0f_0056_cd12_67fd27091b47

Relationship Graph

Source Code

packages/language-tools/language-server/src/core/index.ts lines 143–204

export class AstroVirtualCode implements VirtualCode {
	id = 'root';
	languageId = 'astro';
	mappings!: CodeMapping[];
	embeddedCodes!: VirtualCode[];
	astroMeta!: AstroMetadata;
	compilerDiagnostics!: DiagnosticMessage[];
	htmlDocument!: HTMLDocument;
	codegenStacks = [];

	constructor(
		public fileName: string,
		public snapshot: ts.IScriptSnapshot,
	) {
		this.mappings = [
			{
				sourceOffsets: [0],
				generatedOffsets: [0],
				lengths: [this.snapshot.getLength()],
				data: {
					verification: true,
					completion: true,
					semantic: true,
					navigation: true,
					structure: true,
					format: true,
				},
			},
		];

		const tsx = astro2tsx(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName);
		const astroMetadata = getAstroMetadata(
			this.fileName,
			this.snapshot.getText(0, this.snapshot.getLength()),
		);

		const { htmlDocument, virtualCode: htmlVirtualCode } = parseHTML(
			this.snapshot,
			astroMetadata.frontmatter.status === 'closed'
				? astroMetadata.frontmatter.position.end.offset
				: 0,
		);

		this.htmlDocument = htmlDocument;
		htmlVirtualCode.embeddedCodes = [
			...extractStylesheets(tsx.ranges.styles),
			...extractScriptTags(tsx.ranges.scripts),
		];

		this.astroMeta = { ...astroMetadata, tsxRanges: tsx.ranges };
		this.compilerDiagnostics = [...tsx.diagnostics, ...astroMetadata.diagnostics];
		this.embeddedCodes = [htmlVirtualCode, tsx.virtualCode];
	}

	get hasCompilationErrors(): boolean {
		return (
			// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
			this.compilerDiagnostics.filter((diag) => diag.severity === (1 satisfies DiagnosticSeverity))
				.length > 0
		);
	}
}

Domain

Frequently Asked Questions

What is the AstroVirtualCode class?
AstroVirtualCode is a class in the astro codebase, defined in packages/language-tools/language-server/src/core/index.ts.
Where is AstroVirtualCode defined?
AstroVirtualCode is defined in packages/language-tools/language-server/src/core/index.ts at line 143.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free