Home / Function/ create() — astro Function Reference

create() — astro Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/language-tools/language-server/src/plugins/astro.ts lines 19–76

export const create = (): LanguageServicePlugin => {
	return {
		capabilities: {
			completionProvider: {
				triggerCharacters: ['-'],
			},
			diagnosticProvider: {
				interFileDependencies: false,
				workspaceDiagnostics: false,
			},
		},
		create(context): LanguageServicePluginInstance {
			return {
				provideCompletionItems(document, position, completionContext, token) {
					if (token.isCancellationRequested) return null;
					let items: CompletionItem[] = [];

					const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
					const sourceScript = decoded && context.language.scripts.get(decoded[0]);
					const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
					if (!(virtualCode instanceof AstroVirtualCode)) return;

					if (completionContext.triggerCharacter === '-') {
						const frontmatterCompletion = getFrontmatterCompletion(virtualCode, document, position);
						if (frontmatterCompletion) items.push(frontmatterCompletion);
					}

					return {
						isIncomplete: false,
						items: items,
					};
				},
				provideDiagnostics(document, token) {
					if (token.isCancellationRequested) return [];

					const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
					const sourceScript = decoded && context.language.scripts.get(decoded[0]);
					const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
					if (!(virtualCode instanceof AstroVirtualCode)) return;

					return virtualCode.compilerDiagnostics.map(compilerMessageToDiagnostic);

					function compilerMessageToDiagnostic(message: DiagnosticMessage): Diagnostic {
						const start = Position.create(message.location.line - 1, message.location.column - 1);
						const end = document.positionAt(document.offsetAt(start) + message.location.length);
						return {
							message: message.text + (message.hint ? '\n\n' + message.hint : ''),
							range: Range.create(start, end),
							code: message.code,
							severity: message.severity,
							source: 'astro',
						};
					}
				},
			};
		},
	};
};

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free