create() — astro Function Reference
Architecture documentation for the create() function in html.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 99d21c83_765d_0419_fff4_2f5427ee75c7["create()"] d6917972_8d96_11d3_06c1_e3a1f8e8d585["html.ts"] 99d21c83_765d_0419_fff4_2f5427ee75c7 -->|defined in| d6917972_8d96_11d3_06c1_e3a1f8e8d585 style 99d21c83_765d_0419_fff4_2f5427ee75c7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/language-tools/language-server/src/plugins/html.ts lines 10–78
export const create = (): LanguageServicePlugin => {
const htmlPlugin = createHtmlService({
getCustomData: async (context) => {
const customData: string[] = (await context.env.getConfiguration?.('html.customData')) ?? [];
const newData: html.IHTMLDataProvider[] = [];
for (const customDataPath of customData) {
for (const workspaceFolder of context.env.workspaceFolders) {
const uri = Utils.resolvePath(workspaceFolder, customDataPath);
const json = await context.env.fs?.readFile?.(uri);
if (json) {
try {
const data = JSON.parse(json);
newData.push(html.newHTMLDataProvider(customDataPath, data));
} catch (error) {
console.error(error);
}
break;
}
}
}
return [...newData, astroAttributes, astroElements, classListAttribute];
},
});
return {
...htmlPlugin,
create(context): LanguageServicePluginInstance {
const htmlPluginInstance = htmlPlugin.create(context);
return {
...htmlPluginInstance,
async provideCompletionItems(document, position, completionContext, token) {
if (document.languageId !== 'html') return;
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
const root = sourceScript?.generated?.root;
if (!(root instanceof AstroVirtualCode)) return;
// Don't return completions if the current node is a component
if (isInComponentStartTag(root.htmlDocument, document.offsetAt(position))) {
return null;
}
const completions = await htmlPluginInstance.provideCompletionItems!(
document,
position,
completionContext,
token,
);
if (!completions) {
return null;
}
// We don't want completions for file references, as they're mostly invalid for Astro
completions.items = completions.items.filter(
(completion) => completion.kind !== CompletionItemKind.File,
);
return completions;
},
// Document links provided by `vscode-html-languageservice` are invalid for Astro
provideDocumentLinks() {
return [];
},
};
},
};
};
Domain
Subdomains
Source
Frequently Asked Questions
What does create() do?
create() is a function in the astro codebase, defined in packages/language-tools/language-server/src/plugins/html.ts.
Where is create() defined?
create() is defined in packages/language-tools/language-server/src/plugins/html.ts at line 10.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free