getLanguageServicePlugins() — astro Function Reference
Architecture documentation for the getLanguageServicePlugins() function in languageServerPlugin.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD f16ea619_ee42_4897_ca1e_1d58d1b3c522["getLanguageServicePlugins()"] aa1e3f97_b438_e271_0048_5d1552a8f675["languageServerPlugin.ts"] f16ea619_ee42_4897_ca1e_1d58d1b3c522 -->|defined in| aa1e3f97_b438_e271_0048_5d1552a8f675 style f16ea619_ee42_4897_ca1e_1d58d1b3c522 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/language-tools/language-server/src/languageServerPlugin.ts lines 36–145
export function getLanguageServicePlugins(
connection: Connection,
ts: typeof import('typescript'),
collectionConfig: CollectionConfig,
initializeParams?: InitializeParams,
) {
const LanguageServicePlugins = [
createHtmlService(),
createCssService(),
createEmmetService(),
...createTypeScriptServices(ts, {
disableAutoImportCache: initializeParams?.initializationOptions?.disableAutoImportCache,
}),
createTypeScriptTwoSlashService(ts),
createTypescriptAddonsService(),
createAstroService(),
getPrettierService(),
createYAMLService(collectionConfig),
];
return LanguageServicePlugins;
function getPrettierService() {
let prettier: ReturnType<typeof importPrettier>;
let prettierPluginPath: ReturnType<typeof getPrettierPluginPath>;
let hasShownNotification = false;
return createPrettierService(
(context) => {
for (const workspaceFolder of context.env.workspaceFolders) {
if (workspaceFolder.scheme === 'file') {
prettier = importPrettier(workspaceFolder.fsPath);
prettierPluginPath = getPrettierPluginPath(workspaceFolder.fsPath);
if ((!prettier || !prettierPluginPath) && !hasShownNotification) {
connection.sendNotification(ShowMessageNotification.type, {
message:
"Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project and restart the language server.",
type: MessageType.Warning,
});
hasShownNotification = true;
}
return prettier;
}
}
},
{
documentSelector: ['astro'],
getFormattingOptions: async (prettierInstance, document, formatOptions, context) => {
const uri = URI.parse(document.uri);
const documentUri = context.decodeEmbeddedDocumentUri(uri)?.[0] ?? uri;
const filePath = documentUri.fsPath;
if (!filePath) {
return {};
}
let configOptions = null;
try {
configOptions = await prettierInstance.resolveConfig(filePath, {
// This seems to be broken since Prettier 3, and it'll always use its cumbersome cache. Hopefully it works one day.
useCache: false,
editorconfig: true,
});
} catch (e) {
connection.sendNotification(ShowMessageNotification.type, {
message: `Failed to load Prettier config.\n\nError:\n${e}`,
type: MessageType.Warning,
});
console.error('Failed to load Prettier config.', e);
}
const editorOptions = await context.env.getConfiguration<object>?.(
'prettier',
document.uri,
);
// Return a config with the following cascade:
// - Prettier config file should always win if it exists, if it doesn't:
// - Prettier config from the VS Code extension is used, if it doesn't exist:
// - Use the editor's basic configuration settings
const resolvedConfig = {
Domain
Subdomains
Source
Frequently Asked Questions
What does getLanguageServicePlugins() do?
getLanguageServicePlugins() is a function in the astro codebase, defined in packages/language-tools/language-server/src/languageServerPlugin.ts.
Where is getLanguageServicePlugins() defined?
getLanguageServicePlugins() is defined in packages/language-tools/language-server/src/languageServerPlugin.ts at line 36.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free