Home / Function/ getFrontmatterCompletion() — astro Function Reference

getFrontmatterCompletion() — astro Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  746e530f_7336_ca2c_9b52_af546f60f3ef["getFrontmatterCompletion()"]
  a943f832_bfb7_8516_7216_c38c26db96ff["astro.ts"]
  746e530f_7336_ca2c_9b52_af546f60f3ef -->|defined in| a943f832_bfb7_8516_7216_c38c26db96ff
  99fd114c_3691_a9b4_d799_8c8aac9b799d["create()"]
  99fd114c_3691_a9b4_d799_8c8aac9b799d -->|calls| 746e530f_7336_ca2c_9b52_af546f60f3ef
  style 746e530f_7336_ca2c_9b52_af546f60f3ef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/language-server/src/plugins/astro.ts lines 78–128

function getFrontmatterCompletion(
	file: AstroVirtualCode,
	document: TextDocument,
	position: Position,
) {
	const base: CompletionItem = {
		kind: CompletionItemKind.Snippet,
		label: '---',
		sortText: '\0',
		preselect: true,
		detail: 'Create component script block',
		insertTextFormat: InsertTextFormat.Snippet,
		commitCharacters: [],
	};

	const documentLines = document.getText().split(/\r?\n/);
	const { line, character } = document.positionAt(document.offsetAt(position));
	const prefix = documentLines[line].slice(0, character);

	if (file.astroMeta.frontmatter.status === 'doesnt-exist') {
		return {
			...base,
			insertText: '---\n$0\n---',
			textEdit: /^\s*-+/.test(prefix)
				? TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---\n$0\n---')
				: undefined,
		};
	}

	if (file.astroMeta.frontmatter.status === 'open') {
		let insertText = '---';

		// If the current line is a full component script starter/ender, the user expects a full frontmatter
		// completion and not just a completion for "---"  on the same line (which result in, well, nothing)
		if (prefix === '---') {
			insertText = '---\n$0\n---';
		}

		return {
			...base,
			insertText,
			detail:
				insertText === '---' ? 'Close component script block' : 'Create component script block',
			textEdit: /^\s*-+/.test(prefix)
				? TextEdit.replace({ start: { ...position, character: 0 }, end: position }, insertText)
				: undefined,
		};
	}

	return null;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does getFrontmatterCompletion() do?
getFrontmatterCompletion() is a function in the astro codebase, defined in packages/language-tools/language-server/src/plugins/astro.ts.
Where is getFrontmatterCompletion() defined?
getFrontmatterCompletion() is defined in packages/language-tools/language-server/src/plugins/astro.ts at line 78.
What calls getFrontmatterCompletion()?
getFrontmatterCompletion() is called by 1 function(s): create.

Analyze Your Own Codebase

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

Try Supermodel Free