Home / Function/ constructor() — astro Function Reference

constructor() — astro Function Reference

Architecture documentation for the constructor() function in frontmatterHolders.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  4008227b_29c1_47f7_5982_789b0b38b1ba["constructor()"]
  e6a43f7b_9c92_14b9_3549_5c4223076591["FrontmatterHolder"]
  4008227b_29c1_47f7_5982_789b0b38b1ba -->|defined in| e6a43f7b_9c92_14b9_3549_5c4223076591
  style 4008227b_29c1_47f7_5982_789b0b38b1ba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/language-server/src/core/frontmatterHolders.ts lines 99–165

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

		this.embeddedCodes = [];
		this.snapshot = snapshot;

		// If the file is not part of a collection, we don't need to do anything
		if (!this.collection) {
			return;
		}

		const frontmatterContent =
			frontmatterRE
				.exec(this.snapshot.getText(0, this.snapshot.getLength()))?.[0]
				.replaceAll('---', '   ') ?? '';

		this.hasFrontmatter = frontmatterContent.length > 0;

		this.embeddedCodes.push({
			id: `yaml_frontmatter_${this.collection}`,
			languageId: 'yaml',
			snapshot: {
				getText: (start, end) => frontmatterContent.substring(start, end),
				getLength: () => frontmatterContent.length,
				getChangeRange: () => undefined,
			},
			mappings: [
				{
					sourceOffsets: [0],
					generatedOffsets: [0],
					lengths: [frontmatterContent.length],
					data: {
						verification: true,
						completion: true,
						semantic: true,
						navigation: true,
						structure: true,
						format: false,
					},
				},
			],
		});

		if (this.hasFrontmatter) {
			const yaml2tsResult = yaml2ts(frontmatterContent, this.collection);
			this.embeddedCodes.push(yaml2tsResult.virtualCode);
		}
	}

Domain

Subdomains

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the astro codebase, defined in packages/language-tools/language-server/src/core/frontmatterHolders.ts.
Where is constructor() defined?
constructor() is defined in packages/language-tools/language-server/src/core/frontmatterHolders.ts at line 99.

Analyze Your Own Codebase

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

Try Supermodel Free