@astrojs/language-server

中文文档
2.17.3发布于 2026/10/21MITCommonJS构建来源已验证近 30 天下载 1925.2万
原始使用文档
文档目录3 节
  1. Folder structure
  2. Troubleshooting
  3. Formatting does not work

@astrojs/language-server

The Astro language server, implement the language server protocol

Folder structure

├── bin             # .js file used to start the server
├── dist            # Compiled files, generated by TypeScript
├── src             # Source files
│   ├── core        # Core code such as .astro file parsing, configuration manager, document definition etc
│   └── plugins     # Modules for the different languages supported in .astro files
├── test            # Tests
└── types           # Types injected into Astro files by the language server under certain conditions

Troubleshooting

Formatting does not work

Using VS Code? This section does not apply to you, the VS Code extension includes both Prettier and the Astro plugin by default.

The Astro language server uses Prettier to format Astro files, but does not include prettier or prettier-plugin-astro by itself as dependencies in order to keep the dependency count low and allow users to better control the version of Prettier they want to use.

As such, if you want to use formatting, you'll need to install prettier and prettier-plugin-astro as dependencies in your project.

版本与发布记录

@astrojs/language-server 共发布 185 个版本,首次发布于 2021/06/17;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.17.3latest2026/10/2117 天前
2.17.22026/10/0830 天前
2.17.12026/09/231 个月前
2.17.02026/09/171 个月前
2.16.162026/09/012 个月前
2.16.152026/08/262 个月前

其他发布通道:next → 2.0.0-next.12,alpha → 2.16.1-alpha.0,beta → 2.16.1-beta.1。

关于 @astrojs/language-server 的常见问题

如何安装 @astrojs/language-server?

在项目目录运行 npm install @astrojs/language-server,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 astro-ls,可以用 npx astro-ls 直接运行。

@astrojs/language-server 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/astrojs__language-server 是否存在。

@astrojs/language-server 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@astrojs/language-server 可以商用吗?

@astrojs/language-server 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@astrojs/language-server 的下载量有多少?

根据 npm 官方下载统计,@astrojs/language-server 在 2026/10/07 – 2026/11/05 这 30 天内被下载 19,252,209 次,日均约 641,740 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@astrojs/language-server 还在维护吗?

最新版本 2.17.3 发布于 2026/10/21(17 天前);至今共发布 185 个版本,其中过去 12 个月发布了 22 个;首次发布于 2021/06/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。