Home / Function/ activate() — astro Function Reference

activate() — astro Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  2f150eb1_412e_c234_e921_947657ea09da["activate()"]
  399ea951_6c03_e083_9630_2d53da33e239["client.ts"]
  2f150eb1_412e_c234_e921_947657ea09da -->|defined in| 399ea951_6c03_e083_9630_2d53da33e239
  a6057a9c_8fad_2f1d_4d76_97b7dba7b010["getConfiguredServerPath()"]
  2f150eb1_412e_c234_e921_947657ea09da -->|calls| a6057a9c_8fad_2f1d_4d76_97b7dba7b010
  style 2f150eb1_412e_c234_e921_947657ea09da fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/vscode/src/client.ts lines 24–104

export async function activate(context: vscode.ExtensionContext): Promise<LabsInfo> {
	const runtimeConfig = vscode.workspace.getConfiguration('astro.language-server');

	const { workspaceFolders } = vscode.workspace;
	const rootPath = workspaceFolders?.[0].uri.fsPath;

	let lsPath = await getConfiguredServerPath(context.workspaceState);
	if (typeof lsPath === 'string' && lsPath.trim() !== '' && typeof rootPath === 'string') {
		lsPath = path.isAbsolute(lsPath) ? lsPath : path.join(rootPath, lsPath);
		console.info(`Using language server at ${lsPath}`);
	} else {
		lsPath = undefined;
	}
	const serverModule = lsPath
		? require.resolve(lsPath)
		: vscode.Uri.joinPath(context.extensionUri, 'dist/node/server.js').fsPath;

	const runOptions = { execArgv: [] };
	const debugOptions = {
		execArgv: ['--nolazy', '--inspect=' + Math.floor(Math.random() * 20000 + 10000)],
	};

	const serverOptions: lsp.ServerOptions = {
		run: {
			module: serverModule,
			transport: lsp.TransportKind.ipc,
			options: runOptions,
		},
		debug: {
			module: serverModule,
			transport: lsp.TransportKind.ipc,
			options: debugOptions,
		},
	};

	const serverRuntime = runtimeConfig.get<string>('runtime');
	if (serverRuntime) {
		serverOptions.run.runtime = serverRuntime;
		serverOptions.debug.runtime = serverRuntime;
		console.info(`Using ${serverRuntime} as runtime`);
	}

	const hasContentIntellisense = vscode.workspace
		.getConfiguration('astro')
		.get('content-intellisense');

	const shouldDisableAutoImportCache =
		vscode.workspace.getConfiguration('astro').get('auto-import-cache.enabled') === false;

	const initializationOptions = {
		typescript: {
			tsdk: (await getTsdk(context))!.tsdk,
		},
		contentIntellisense: hasContentIntellisense,
		disableAutoImportCache: shouldDisableAutoImportCache,
	} satisfies InitOptions;

	const clientOptions = {
		documentSelector: [
			{ language: 'astro' },
			...(hasContentIntellisense
				? [{ language: 'markdown' }, { language: 'mdx' }, { language: 'markdoc' }]
				: []),
		],
		initializationOptions,
	} satisfies lsp.LanguageClientOptions;
	client = new lsp.LanguageClient('astro', 'Astro Language Server', serverOptions, clientOptions);
	await client.start();

	// support for auto close tag
	activateAutoInsertion('astro', client);
	activateFindFileReferences('astro.findFileReferences', client);
	activateReloadProjects('astro.reloadProjects', client);
	activateTsConfigStatusItem('astro', 'astro.openTsConfig', client);
	activateTsVersionStatusItem('astro', 'astro.selectTypescriptVersion', context, (text) => text);

	const volarLabs = createLabsInfo(protocol);
	volarLabs.addLanguageClient(client);

	return volarLabs.extensionExports;
}

Domain

Subdomains

Frequently Asked Questions

What does activate() do?
activate() is a function in the astro codebase, defined in packages/language-tools/vscode/src/client.ts.
Where is activate() defined?
activate() is defined in packages/language-tools/vscode/src/client.ts at line 24.
What does activate() call?
activate() calls 1 function(s): getConfiguredServerPath.

Analyze Your Own Codebase

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

Try Supermodel Free