编程语言研究书库

搭建你的游乐场 — 安装 Zig 与配置 ZLS

搭建你的游乐场 — 安装 Zig 与配置 ZLS

这一章讲两件事: 把 Zig 装进你的电脑,以及把 ZLS(Zig 语言服务器)配好。 看起来是「环境配置章」,实际藏着两个教学意图:一是 Zig 的版本哲学 (稳定版和每夜版怎么选、为什么选);二是让你第一次亲手用 zig build 编译一个真实项目 ——这个项目就是 ZLS 自己——并在构建脚本里写下第一个自定义步骤。 读完你会有一条能立刻照做的装机路线,和一份对「构建系统」的初体验。

1. 这一章讲什么

第一章给了你「为什么学 Zig」的理由,这一章给你「动手学 Zig」的台面。 全书此后的每一章都假定两样东西就位:zig 命令能在终端里跑,编辑器能实时报 Zig 的错。

作者在开头把话说得很直:不学 Zig 可以,但没有 LSP(Language Server Protocol, 语言服务器协议——编辑器和后端语言服务之间的通用通信标准)就写代码, 「不如捡根棍子去洞壁上画画」1。这不是修辞:Zig 的类型信息和报错严重依赖工具链, 没有语言服务器,你等于在半盲写字。

2. 顶层全景:一条装机流水线

  ① 选版本:稳定版(tagged release)还是每夜版(nightly)?
        │
  ② 装 Zig:三个操作系统各有三条路(包管理器 / 手动下载 / 特殊渠道)
        │
  ③ 验证:zig version 打出版本号 = 装好
        │
  ④ 装 ZLS:从源码 git clone,然后一条 zig build 命令编出来
        │
  ⑤ 接编辑器:VS Code 装扩展;Neovim 配 nvim-lspconfig
        │
  ⑥ 调优:写 zls.json,加 build-on-save + 自定义 check 步骤
        │  → 从此每次保存文件,编译错误直接浮现在编辑器里

  图说:① 是一次性决策;②–③ 是十分钟的事;④–⑥ 是本章真正的课。

本章主线例子就是这条流水线本身:下面每一节都在它上面走一步, 并且给出具体命令和预期输出(原书给的命令照抄,版本号按原书写作时的现状标注)。

3. 第一步:稳定版还是每夜版——Zig 特有的选择题

3.1 为什么会有这道题

大多数语言的答案是「装最新稳定版」。Zig 不同,因为它还没到 1.0, 而且官方发布节奏跟着 LLVM 的半年节奏走——等一个稳定版发布,master 分支上又攒了半年的新东西2。 社区的资源(zig.guide、教程、讨论)全都跟着 master 走,不跟化石般的旧稳定版3。 所以「哪个版本」是个真问题,书里给了一份八问决策清单4,收拢成两条:

你的情况选哪个为什么
项目在生产环境 / 要稳定 / 不想常更新 / 依赖外部工具链稳定版经过完整测试,兼容性好
想跟进社区和教程 / 想要最新特性 / 要给 Zig 做贡献每夜版(nightly)社区全部对齐 master 分支

原书的态度也点明了:先用稳定版试水可以,但「认真学就换每夜版」5。

解释词:master 分支。 一个软件项目的开发主线,新代码每天合进去的地方。 每夜版(nightly build) 就是每天从 master 自动打包出来的版本—— 新鲜、可能有毛边。这本书自己假设你装的是较新的 Zig(写作时最新稳定版 0.15.26)。

这道题的保险栓: Zig 的版本切换成本低到「ridiculously easy」—— 每个版本是一个自包含的压缩包,想在系统里放几个就放几个,互不干扰7。 所以选错版本的代价只是换个目录,这也是作者敢让你大胆选 nightly 的底气。

3.2 第二步的三种装法

Linux:发行版包管理器优先。 大多数主流发行版的软件源里都有 Zig, 一条命令装完;完整列表在 Zig 官方 wiki8。想手动控制的话:先去下载页认清自己 CPU 架构 (uname -m 一条命令查),wget 下载对应压缩包,tar xf 解开,最后把解压目录加进 PATH(shell 的搜索路径:你敲命令时系统去哪些目录找可执行文件)—— 不加 PATH,每次编译都要敲完整路径,书里的原话是「你会诅咒你的机器」9。

Windows:Chocolatey / WinGet / Scoop 三选一,命令各一行(choco install zig、 winget install zig.zig、scoop install zig)10;手动安装的话, 架构检查用 $Env:PROCESSOR_ARCHITECTURE(x86_64 在 Windows 上又叫 AMD64), 然后解压、改 PATH——注意书里的 PATH 改法分「系统级」和「用户级」两种, 替换成自己的解压路径11。

macOS:brew install zig,一行12。

Nix 用户的专属通道: nix-env -iA nixpkgs.zig 拉稳定版; Nix 的绝活是一个系统里并行管理多个版本、互不污染,作者专门花一段夸它13。

装完必做:验证。 终端里敲 zig version,打出版本号(书里示例打出 0.12.0) 就是装好了14。注意这个示例数字比书中他处说的 0.15.2 还旧—— 原书的命令示例和它声明的写作版本本身就不同步,这恰好是 3.1 节「版本飘移」的活例证, 我们留在 §8 边界里再说。

4. ZLS:Zig 语言服务器

4.1 它是什么、为什么必须有

ZLS(Zig Language Server)是 Zig 的语言服务器:一个在你写代码时在后台跑的程序, 给编辑器提供自动补全、跳转到定义、实时报错、自动格式化15。 它和编辑器之间说 LSP 这套通用协议——所以理论上任何支持 LSP 的编辑器都能接它。

书里有段话值得单独记住:Zig 让「从零造东西」这件事变得容易, 「这不只是你自己项目的优点——它直接 baked 进(烙进)了 Zig 生态的工具里」16。 下面这个「从源码编译 ZLS」的过程就是演示:别的语言的语言服务器往往是装好的二进制, Zig 让你十分钟内从源码自己编一个。

4.2 主线例子(上):四条命令编出 ZLS

走一遍原书给的全过程,每一步旁边是实际发生的事:

步骤你敲的命令实际发生的事
① 拿源码git clone https://github.com/zigtools/zls.git(该地址查阅于 2026-10-19)把 ZLS 的源码仓库复制到本地
② 进目录cd zls—
③ 编译zig build -Doptimize=ReleaseSafeZig 读它的 build.zig,下载依赖、编译,产出一个 ZLS 可执行文件17
④ 得到(ZLS 二进制躺在项目目录里)一个能接进任何编辑器的语言服务器

第 ③ 步是全章第一个真正的「啊哈」时刻:一条命令编译一个你从没读过的真实项目。 -Doptimize=ReleaseSafe 就是第 1 章那张四档安全表里的一档—— 优化开、安全检查保留,适合「发布但仍要稳」的程序18。 此时你还没学任何 Zig 语法,却已经用过了 Zig 工具链的心脏;第 11 章会拆开这条命令背后的一切。

4.3 接进编辑器:VS Code 与 Neovim 两条路

VS Code:装扩展即完事。 在扩展市场搜「Zig Language」,装官方扩展 (ziglang.vscode-zig),重启,收工——扩展自己找到 ZLS、接管补全和跳转19。

Neovim:自己配。 用 vim-plug 装两个插件:nvim-lspconfig(LSP 接线插件) 和 ziglang/zig.vim(Zig 语法支持),然后在 init.lua 里写一段配置: 声明 ZLS 可执行文件路径、Zig 可执行文件路径,以及「保存时自动格式化」20。 配置里有个细节:默认 zig.vim 自带的保存时格式化要被关掉,换成让 ZLS 来做, 「确保和 Zig 社区的最佳实践一致」21。

书里夹带的私货(可核的小事实): zig.vim 这个插件有 Andrew Kelley 本人的贡献—— 他不全职维护,但时不时提交代码,保证插件跟得上语言的演进22。 作者拿它当「这个插件靠谱」的论据:语言的设计者亲手碰过的插件,差不到哪去。

一个版本兼容警告: 如果你用 Zig master 分支,不要通过 Mason (Neovim 社区常用的 LSP 安装器)装 ZLS——Mason 只装 ZLS 的最新「打过 tag 的稳定版」, 和 master 的 Zig 可能不兼容,要手动装23。这正是 3.1 节那个选择题的回声: Zig 生态的一切兼容性都跟着「Zig 版本 × 工具版本」这张表走。

5. 调优:zls.json 与「保存即编译」

5.1 zls.json:ZLS 的配置文件

ZLS 的配置放在一个 JSON 文件里,管所有编辑器共用的行为:用哪个 Zig 可执行文件、 语义着色(给不同类别的代码元素上不同颜色)开多少、要不要保存时构建。最小例子(照原书)24:

  {
    "zig_exe_path": "/path/to/zig_executable",
    "semantic_tokens": "partial",
    "enable_build_on_save": true
  }

格式的三条纪律书里专门叮嘱:不能有注释、不能有尾逗号、不能搞花样25。

配置文件放哪?0.14.0 起的 ZLS 给了自查命令 zls env:它打印 ZLS 会去找配置的目录 (先是 local_config_dir,一般是 ~/.config;找不到再退到 global_config_dir, 常见为 /etc/xdg)26。更早的版本用 zls --show-config-path 问出路径27。

5.2 主线例子(下):给 build.zig 加一个 check 步骤

这是全章技术含量最高的一段,也是第 11 章的正式预告片。目标: 每次保存文件,ZLS 自动编译一遍你的项目,把错误直接显示在编辑器里。

分两半配。先在 zls.json 里加两行28:

  "enable_build_on_save": true,
  "build_on_save_step": "check"

再在项目的 build.zig 里定义这个名叫 check 的自定义步骤。原书的做法: 把已有的可执行文件定义复制一份(改名 exe_check),但不写 b.installArtifact (不生成最终二进制),然后注册一个叫 check 的步骤、让它依赖这份复制的编译29:

  const exe_check = b.addExecutable(.{ ... 同上的定义 ... });
  const check = b.step("check", "Check if your_executable compiles");
  check.dependOn(&exe_check.step);

逐行说清这三行在干什么:

行它做的事为什么
exe_check = b.addExecutable(...)再声明一次「要编译这个程序」编译检查需要一份编译动作;复制而不改名,避免和正式产物抢名字
没有 b.installArtifact(exe_check)声明了编译,但不安装产物只查编译错误、不链接不打包,省掉整个生成二进制的开销30
b.step("check", ...) + dependOn注册一个叫 check 的步骤,挂到那份编译上zig build check 这个词从此存在;ZLS 保存时调的就是它

配好后重启编辑器。从此工作流变成:

  你保存 main.zig
      → ZLS 悄悄执行 zig build check
      → 只编译、不链接,秒回
      → 编译错误以红波浪线直接标在编辑器里

  图说:错误从「命令行里的一堵墙」变成「写在出错那一行旁边的一行小字」。

为什么要费这个事? 书里给了实话:ZLS 本身很强,但不是完美的—— 遇到复杂的编译期表达式(comptime),它可能漏报错31。 build-on-save 是一条独立的真实编译,等于给 ZLS 的静态分析加一道 「编译器本尊」的保险;漏掉的错在保存那一刻现形。

判断(我们的,不是书里的): 这个「check 步骤」是原书教学上很妙的一笔—— 它在读者还没学语言语法时,先让「构建脚本是程序」这件事落了地: 你刚写完(复制改)七行 Zig 代码,就立刻尝到了「给构建系统加新动词」的滋味。 妙处也是险处:初学者此时完全不知道 b.addExecutable、.step、.dependOn 是什么, 只能照抄。照抄没问题,但要在心里挂一笔账——这些词每一个第 11 章都要还。 如果错,会错在: 对完全没接触过构建系统的读者,这一段可能产生「Zig 的构建好麻烦」 的第一印象,而它和「zig build 一条命令就能干活」的爽感是矛盾的。 真相是两者都对:简单用法极简,定制用法显式——这正是第 1 章「透明」处方的工具版。

5.3 本章测验

章末附了六道测验题(加一道加分题),自查要点:版本选择题的先后次序、 Linux 最快装法是包管理器、稳定版不给你最新特性、Windows 手动装必须配 PATH、 ZLS 和 Zig 版本要匹配、nightly 的两个风险(可能有 bug、教程可能过时)32。 答案都在上文;原书按对题数给称号,从「Zig Master」到「回去重读」三档33。 我们把它看作学习闭环的一部分,不单独展开。

6. 作者的判断与证据

分开标两类声音。

可核的事实与操作(照做即可,风险低):

  • 三种操作系统各有包管理器装法,命令在 §3.2 原样照抄1012;
  • zig version 验证安装、uname -m / $Env:PROCESSOR_ARCHITECTURE 查架构、 解压后必须加 PATH,这些是通用装机纪律,与 Zig 无关也成立911;
  • ZLS 可以从源码用 zig build -Doptimize=ReleaseSafe 编出来17;
  • VS Code 装官方扩展即可用 ZLS19;Neovim 需要手写 init.lua 配置20;
  • zls env(0.14.0 起)能查出配置目录,旧版用 zls --show-config-path2627;
  • Mason 装的 ZLS 与 Zig master 可能不兼容,要手动装23。

作者的立场(判断,请带着自己的情况重判):

  • 「认真学 Zig 就该用 nightly」——这是基于「社区资源全对齐 master」的推理5, 对跟书学习成立;对「给客户交付」不成立。决策树本身才是可带走的东西,结论随场景换;
  • 「没有 LSP 等于史前」——作者的修辞,但方向属实:Zig 的错误信息质量高度依赖工具链, 裸编辑器写 Zig 的体验确实显著差于有 ZLS;
  • 「Nix 是管理 Zig 版本的好工具」——作者明显偏爱 Nix13,这是一家之言; 对不用 Nix 的读者,3.1 节的「多版本自包含压缩包」机制已经够用了;
  • 「build-on-save 的配置值得做」——书里承认 ZLS 本身已经很强31, 这道额外配置买的是「编译器本尊兜底」。对 Hello World 级的小项目是过度配置, 对真实项目(尤其重度 comptime 的项目)是划算的保险。

7. 边界与局限

照实列出这一章的坑:

缺什么 / 哪里会过时说明
所有具体版本号和 URL 都是消耗品写作时的现实:稳定版 0.15.26、示例输出却是 0.12.014、ZLS 配置命令以「0.14.0-dev.50+3354fdcb」这种精度提到27。照做之前先去 ziglang.org 核对现状,这是 1.0 之前语言的常态,不是书印错了
Windows 手动配 PATH 一段最脆弱书里的 PowerShell 片段要替换成自己的路径,新手最容易在这里卡死;优先用包管理器装,能绕开整段
Neovim 配置假定你已会配 Neovim原文明说「假定你已经会配键位和自动补全」20;这章对 Vim 新用户不是入门材料
quiz 的答案不等于理解六道题考的是「记没记住步骤」,装机能力只能装机验证,做题替代不了
LSP 本身没讲透什么是语言服务器、它和编译器什么分工,全章没有正式解释——我们从常识补了(§4.1),但深度只够支撑使用
macOS 只给了 brew 一条路手动安装、多版本并存这些 Linux/Windows 上展开讲的,macOS 上一笔带过
安全性话题缺席从官网下载二进制、校验哈希、PATH 被滥用的风险,全章未提;装机照做时值得自己留一个心眼

8. 可带走的

本章主线例子,一行走完: git clone zls → zig build -Doptimize=ReleaseSafe → 得到一个语言服务器 → 接进编辑器 → 在 build.zig 里注册 check 步骤、 在 zls.json 里打开 build-on-save → 从此保存即编译、错误写在出错行旁边。 命令和版本号是 2025 年中的快照,机制(版本哲学、PATH、构建脚本即代码)长期有效。

  1. Zig 的版本选择题是真实的:没到 1.0、发布慢半拍、社区全对齐 master——学习用 nightly,交付用稳定版,选错的代价很低(版本是自包含压缩包,可并存7);
  2. 装 Zig 的最短路径:Linux 用发行版包管理器,Windows 用 winget/choco/scoop,macOS 用 brew;手动安装的三步纪律是认架构、解压、加 PATH;
  3. zig version 是装机的唯一验收标准:打出版本号才算完;
  4. ZLS 是必需品不是奢侈品:补全、跳转、实时报错都来自它;它从源码一条命令就能编出来,这是 Zig 工具链「从零造东西容易」的活广告;
  5. 编辑器两条路:VS Code 装官方扩展即完事;Neovim 要自己接 nvim-lspconfig + zig.vim,顺带知道 zig.vim 有 Zig 作者本人的贡献22;
  6. Zig 版本和 ZLS 版本要配对:Mason 只管 ZLS 稳定版,用 Zig master 就别走 Mason23;
  7. zls env 查配置目录,zls.json 是 JSON 纪律(无注释、无尾逗号)2526;
  8. build-on-save + 自定义 check 步骤 = 给 ZLS 上保险:ZLS 对复杂 comptime 会漏报错,而 check 步骤只编译不链接、成本低,是「编译器本尊」级的兜底31;
  9. 你已经在没学语法的情况下用过了 build.zig:第 11 章会把 b.step、dependOn 这些词逐一讲透;
  10. 一切版本号、URL、命令输出都可能已过期:动手前核对官网,是 1.0 之前语言的生存技能。

9. 原文地图

主题原书章原文位置
没有 LSP 就是洞壁画画Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:7(搜「grab a club」)
写作时版本 0.15.2Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:39(搜「0.15.2」)
发布跟 LLVM 半年节奏Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:46(搜「tied to LLVM」)
社区资源对齐 masterChapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:55(搜「zig.guide」)
八问决策清单与总结论Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:60(搜「Stable or Bold」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:116(搜「final decision」)
版本切换极容易、可并存Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:123(搜「ridiculously easy to switch」)
Linux 包管理器列表Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:129(搜「easy option: your distribution」)
查架构 uname -m / 手动安装Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:149(搜「uname -m」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:160(搜「add Zig to your PATH」)
Windows 三种包管理器Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:174(搜「choco install zig」)
Windows 查架构与 PATHChapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:186(搜「PROCESSOR_ARCHITECTURE」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:204(搜「replace C:_\zig-windows-_」)
macOS brew 安装Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:210(搜「brew install zig」)
zig version 验证Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:217(搜「zig version」)
Nix 安装与多版本管理Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:229(搜「nix-env -iA nixpkgs.zig」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:235(搜「manage multiple versions」)
「从零造东西容易烙进工具」Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:248(搜「baked right into the tools」)
从源码编译 ZLSChapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:264(搜「git clone https://github.com/zigtools/zls」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:268(搜「ReleaseSafe」)
VS Code 扩展Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:293(搜「ziglang.vscode-zig」)
Neovim 配置与两个插件Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:344(搜「nvim-lspconfig」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:353(搜「lspconfig.zls.setup」)
Mason 版本警告Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:325(搜「do not install the ZLS via the Mason」)
zig.vim 有 Kelley 贡献Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:394(搜「Andrew Kelley」)
zls.json 最小配置与 JSON 纪律Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:411(搜「semantic_tokens」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:415(搜「no comments, no trailing commas」)
zls env 查配置目录Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:422(搜「zls env」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:424(搜「local_config_dir」)
旧版 --show-config-pathChapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:439(搜「show-config-path」)
build-on-save 两行配置Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:458(搜「build_on_save_step」)
build.zig 里的 check 步骤Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:481(搜「exe_check」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:488(搜「Check if your_executable compiles」)
故意不 installArtifactChapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:503(搜「verifying that your code compiles」)
ZLS 对复杂 comptime 会漏Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:513(搜「complex compile-time」)
章末测验Chapter 2: Setting Up Your Playgroundtext/08-ch02-chapter-2-setting-up-your-playground.txt:534(搜「Question 1」) · text/08-ch02-chapter-2-setting-up-your-playground.txt:590(搜「Let’s check the results」)

Footnotes

  1. 出处:「Chapter 2: Setting Up Your Playground」第 6–10 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:7,搜「grab a club」)。原文:不设 Language Server Protocol 就 embark 这趟旅程,「might as well grab a club and start drawing on cave walls」。LSP 是编辑器和语言服务之间的通用协议,这是通用知识(补充,不在书里)。 ↩

  2. 出处:「Chapter 2: Setting Up Your Playground」第 45–49 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:46,搜「tied to LLVM」)。原文:Zig 未到 v1.0,发布节奏绑在 LLVM「相当悠闲的半年节奏」上,等稳定版发布时它可能已经比每天的边缘改动陈旧。 ↩

  3. 出处:「Chapter 2: Setting Up Your Playground」第 53–56 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:55,搜「zig.guide」)。原文:Zig 社区和 zig.guide 等资源都跟 master 分支走,「not the fossilized versions」。 ↩

  4. 出处:「Chapter 2: Setting Up Your Playground」第 58–121 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:60,搜「Stable or Bold」)。八问清单从第 60 段起,总结论在第 116–121 段(稳定三答选稳定版,新鲜三答选 nightly)。 ↩

  5. 出处:「Chapter 2: Setting Up Your Playground」第 51–56 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:53,搜「switch to a nightly build」)。原文:认定 Zig 是新挚友、想认真深入,「do yourself a favor and switch to a nightly build」。 ↩ ↩2

  6. 出处:「Chapter 2: Setting Up Your Playground」第 36–43 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:39,搜「0.15.2」)。 ↩ ↩2

  7. 出处:「Chapter 2: Setting Up Your Playground」第 123–126 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:123,搜「ridiculously easy to switch」)。原文:每个 release 是自包含的 bundle,放哪都行,「No mess, no fuss」。 ↩ ↩2

  8. 出处:「Chapter 2: Setting Up Your Playground」第 127–134 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:129,搜「easy option: your distribution」)。完整包管理器列表的链接见第 133 段。 ↩

  9. 出处:「Chapter 2: Setting Up Your Playground」第 159–162 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:160,搜「add Zig to your PATH」)。「你会诅咒你的机器」对应原文第 205 段「you'll be cursing your machine (with the full path to the Zig binary)」。 ↩ ↩2

  10. 出处:「Chapter 2: Setting Up Your Playground」第 171–180 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:174,搜「choco install zig」)。三条命令分别见第 174、177、180 段。 ↩ ↩2

  11. 出处:「Chapter 2: Setting Up Your Playground」第 182–206 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:186,搜「PROCESSOR_ARCHITECTURE」)。系统级与用户级两种 PATH 改法见第 189–202 段,「记得替换成实际路径」见第 204 段。 ↩ ↩2

  12. 出处:「Chapter 2: Setting Up Your Playground」第 208–212 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:210,搜「brew install zig」)。 ↩ ↩2

  13. 出处:「Chapter 2: Setting Up Your Playground」第 222–240 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:229,搜「nix-env -iA nixpkgs.zig」;text/08-ch02-chapter-2-setting-up-your-playground.txt:235,搜「manage multiple versions」)。 ↩ ↩2

  14. 出处:「Chapter 2: Setting Up Your Playground」第 214–220 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:217,搜「zig version」;text/08-ch02-chapter-2-setting-up-your-playground.txt:220,搜「0.12.0」)。 ↩ ↩2

  15. 出处:「Chapter 2: Setting Up Your Playground」第 242–255 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:252,搜「keep it simple」)。语言服务器提供的能力清单(补全、跳转等)见第 294–295 段,属 LSP 通行功能。 ↩

  16. 出处:「Chapter 2: Setting Up Your Playground」第 246–250 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:248,搜「baked right into the tools」)。 ↩

  17. 出处:「Chapter 2: Setting Up Your Playground」第 257–272 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:264,搜「git clone」——该仓库地址 https://github.com/zigtools/zls.git(查阅于 2026-10-19);text/08-ch02-chapter-2-setting-up-your-playground.txt:268,搜「ReleaseSafe」)。 ↩ ↩2

  18. 出处:「Chapter 2: Setting Up Your Playground」第 268–271 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:270,搜「optimized for safety and efficiency」)。四种构建模式的完整解释见第 1 章「Chapter 1: Safety First」第 543–552 段(text/07-ch01-chapter-1-safety-first.txt:545,搜「Debug: Perfect for development」)。 ↩

  19. 出处:「Chapter 2: Setting Up Your Playground」第 290–315 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:293,搜「ziglang.vscode-zig」)。 ↩ ↩2

  20. 出处:「Chapter 2: Setting Up Your Playground」第 317–334 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:331,搜「assumes you’re already familiar」)。配置代码块见第 339–360 段。 ↩ ↩2 ↩3

  21. 出处:「Chapter 2: Setting Up Your Playground」第 385–386 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:386,搜「best practices」)。 ↩

  22. 出处:「Chapter 2: Setting Up Your Playground」第 393–400 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:394,搜「Andrew Kelley」)。 ↩ ↩2

  23. 出处:「Chapter 2: Setting Up Your Playground」第 323–328 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:325,搜「do not install the ZLS via the Mason」)。 ↩ ↩2 ↩3

  24. 出处:「Chapter 2: Setting Up Your Playground」第 408–416 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:411,搜「semantic_tokens」)。 ↩

  25. 出处:「Chapter 2: Setting Up Your Playground」第 415–416 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:415,搜「no comments, no trailing commas」)。 ↩ ↩2

  26. 出处:「Chapter 2: Setting Up Your Playground」第 418–427 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:422,搜「zls env」;text/08-ch02-chapter-2-setting-up-your-playground.txt:424,搜「local_config_dir」)。 ↩ ↩2 ↩3

  27. 出处:「Chapter 2: Setting Up Your Playground」第 437–442 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:439,搜「show-config-path」)。「0.14.0-dev.50+3354fdcb」这个精确版本号见第 437 段。 ↩ ↩2 ↩3

  28. 出处:「Chapter 2: Setting Up Your Playground」第 455–459 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:458,搜「build_on_save_step」)。 ↩

  29. 出处:「Chapter 2: Setting Up Your Playground」第 466–489 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:481,搜「exe_check」;text/08-ch02-chapter-2-setting-up-your-playground.txt:488,搜「Check if your_executable compiles」)。 ↩

  30. 出处:「Chapter 2: Setting Up Your Playground」第 502–504 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:503,搜「verifying that your code compiles」)。 ↩

  31. 出处:「Chapter 2: Setting Up Your Playground」第 512–515 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:513,搜「complex compile-time」)。 ↩ ↩2 ↩3

  32. 出处:「Chapter 2: Setting Up Your Playground」第 528–588 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:534,搜「Question 1」;text/08-ch02-chapter-2-setting-up-your-playground.txt:580,搜「Bonus question」)。 ↩

  33. 出处:「Chapter 2: Setting Up Your Playground」第 590–597 段(text/08-ch02-chapter-2-setting-up-your-playground.txt:592,搜「Zig Master」)。 ↩

On this page