lsp-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LSP Setup for GitHub Copilot CLI

适用于GitHub Copilot CLI的LSP设置

UTILITY SKILL — installs and configures Language Server Protocol servers for Copilot CLI. USE FOR: "setup LSP", "install language server", "configure LSP for Java", "add TypeScript LSP", "enable code intelligence", "I need go-to-definition", "find references not working", "need better code understanding" DO NOT USE FOR: general coding tasks, IDE/editor LSP configuration, non-Copilot-CLI setups
实用技能 — 为Copilot CLI安装并配置Language Server Protocol服务端。 适用场景:"setup LSP"、"install language server"、"configure LSP for Java"、"add TypeScript LSP"、"enable code intelligence"、"I need go-to-definition"、"find references not working"、"need better code understanding" 不适用场景:通用编码任务、IDE/编辑器的LSP配置、非Copilot CLI相关的设置

Workflow

工作流程

  1. Ask the language — use
    ask_user
    to ask which programming language(s) the user wants LSP support for
  2. Detect the OS — run
    uname -s
    (or check for Windows via
    $env:OS
    /
    %OS%
    ) to determine macOS, Linux, or Windows
  3. Look up the LSP server — read
    references/lsp-servers.md
    for known servers, install commands, and config snippets
  4. Ask scope — use
    ask_user
    to ask whether the config should be user-level (
    ~/.copilot/lsp-config.json
    ) or repo-level (
    lsp.json
    at the repo root or
    .github/lsp.json
    )
  5. Install the server — run the appropriate install command for the detected OS
  6. Write the config — merge the new server entry into the chosen config file (
    ~/.copilot/lsp-config.json
    for user-level;
    lsp.json
    or
    .github/lsp.json
    for repo-level). If a repo-level config already exists, keep using that location; otherwise ask the user which repo-level location they prefer. Create the file if missing and preserve existing entries.
  7. Verify — confirm the LSP binary is on
    $PATH
    and the config file is valid JSON
  1. 询问编程语言 — 使用
    ask_user
    询问用户需要为哪些编程语言提供LSP支持
  2. 检测操作系统 — 运行
    uname -s
    (Windows环境下可通过
    $env:OS
    /
    %OS%
    检查)判断是macOS、Linux还是Windows
  3. 查找对应LSP服务端 — 读取
    references/lsp-servers.md
    获取已知服务端、安装命令和配置片段
  4. 询问配置作用范围 — 使用
    ask_user
    询问配置应该为用户级(
    ~/.copilot/lsp-config.json
    )还是仓库级(仓库根目录的
    lsp.json
    .github/lsp.json
  5. 安装服务端 — 运行适配检测到的操作系统的对应安装命令
  6. 写入配置 — 将新的服务端条目合并到选定的配置文件中(用户级对应
    ~/.copilot/lsp-config.json
    ;仓库级对应
    lsp.json
    .github/lsp.json
    )。如果已有仓库级配置,继续使用原有位置;否则询问用户偏好的仓库级存储位置。文件不存在则创建,同时保留所有已有条目。
  7. 验证配置 — 确认LSP二进制文件在
    $PATH
    中,且配置文件为合法JSON格式

Configuration Format

配置格式

Copilot CLI reads LSP configuration from user-level or repo-level locations, and repo-level config takes precedence over user-level config:
  • User-level:
    ~/.copilot/lsp-config.json
  • Repo-level:
    lsp.json
    (repo root) or
    .github/lsp.json
The JSON structure:
json
{
  "lspServers": {
    "<server-key>": {
      "command": "<binary>",
      "args": ["--stdio"],
      "fileExtensions": {
        ".<ext>": "<languageId>",
        ".<ext2>": "<languageId>"
      }
    }
  }
}
Copilot CLI会从用户级或仓库级位置读取LSP配置,仓库级配置优先级高于用户级配置:
  • 用户级
    ~/.copilot/lsp-config.json
  • 仓库级
    lsp.json
    (仓库根目录)或
    .github/lsp.json
JSON结构如下:
json
{
  "lspServers": {
    "<server-key>": {
      "command": "<binary>",
      "args": ["--stdio"],
      "fileExtensions": {
        ".<ext>": "<languageId>",
        ".<ext2>": "<languageId>"
      }
    }
  }
}

Key rules

关键规则

  • command
    is the binary name (must be on
    $PATH
    ) or an absolute path.
  • args
    almost always includes
    "--stdio"
    to use standard I/O transport.
  • fileExtensions
    maps each file extension (with leading dot) to a Language ID.
  • Multiple servers can coexist in
    lspServers
    .
  • When merging into an existing file, never overwrite other server entries — only add or update the target language key.
  • command
    是二进制文件名称(必须在
    $PATH
    中)或绝对路径。
  • args
    几乎总是包含
    "--stdio"
    ,用于使用标准I/O传输。
  • fileExtensions
    将每个文件扩展名(带开头的点)映射到语言ID
  • lspServers
    中可同时存在多个服务端配置。
  • 合并到已有文件时,绝对不要覆盖其他服务端条目——仅添加或更新目标语言对应的键。

Behavior

行为规范

  • Always use
    ask_user
    with
    choices
    when asking the user to pick a language or scope.
  • If the language is not listed in
    references/lsp-servers.md
    , search the web for "<language> LSP server" and guide the user through manual configuration.
  • If a package manager is not available (e.g. no Homebrew on macOS), suggest alternative install methods from the reference file.
  • After installation, run
    which <binary>
    (or
    where.exe
    on Windows) to confirm the binary is accessible.
  • Show the user the final config JSON before writing it.
  • If the config file already exists, read it first and merge — do not clobber.
  • 要求用户选择语言或作用范围时,始终使用带
    choices
    参数的
    ask_user
  • 如果语言未在
    references/lsp-servers.md
    中列出,搜索网络查找"<language> LSP server",引导用户完成手动配置。
  • 如果缺少对应的包管理器(例如macOS上没有Homebrew),从参考文件中推荐其他安装方式。
  • 安装完成后,运行
    which <binary>
    (Windows下为
    where.exe
    )确认二进制文件可访问。
  • 写入配置前向用户展示最终的配置JSON。
  • 如果配置文件已存在,先读取内容再合并——不要直接覆盖原有内容。

Verification

验证步骤

After setup, tell the user:
  1. Type
    /exit
    to quit Copilot CLI — this is required so the new LSP configuration is loaded on next launch
  2. Re-launch
    copilot
    in a project with files of the configured language
  3. Run
    /lsp
    to check the server status
  4. Try code intelligence features like go-to-definition or hover
设置完成后,告知用户以下操作:
  1. 输入
    /exit
    退出Copilot CLI——这一步是必须的,这样下次启动时才会加载新的LSP配置
  2. 在包含对应配置语言文件的项目中重新启动
    copilot
  3. 运行
    /lsp
    检查服务端状态
  4. 测试代码智能功能,例如跳转到定义、悬停提示等