EN 中文

# References — Semantic Find-References

# References — 语义找引用

Ask the language server who calls/uses a symbol. Resolves real symbols, follows aliased imports, ignores comments.

通过语言服务器查找符号的所有引用——解析真实符号、跟踪别名导入、跳过注释和字符串。

seek's LSP integration is slim — `references` only. `definition`/`hover`/symbol listing are intentionally omitted (Go: covered by grep + `go build`; dynamic langs: `references` is the high-value win). seek 的 LSP 集成是瘦身版——只做 references。definition/hover/符号列表故意不做。

## Install the Server

## 装语言服务器

You must have the language server on PATH:

需将对应 server 放进 PATH：

Language | 语言 | Server | Server | Install | 安装
--- | --- | --- | --- | --- | ---
Go | `gopls` | `go install golang.org/x/tools/gopls@latest`
Python | `pyright-langserver` | `npm i -g pyright`
TS/JS | `typescript-language-server` | `npm i -g typescript-language-server typescript`

Missing server = graceful error message, not a crash.

没装 server 时返回错误信息，不崩溃。

## Usage: grep → references

## 用法：先 grep 找声明，再 references 找引用

    # 1. grep 找到声明在哪
    grep "func Kill" internal/bgjob/bgjob.go → bgjob.go:230

    # 2. references 拿到所有语义引用
    references(file="internal/bgjob/bgjob.go", line=230, symbol="Kill")
    → 4 reference(s) to Kill:
      internal/tools/monitor/monitor.go:112:9 | if err := t.mgr.Kill(a.Job); err != nil {

- symbol finds the exact column on that line; can also pass character (1-based) directly.
- symbol 用于在那一行定位精确列；也可以直接传 character（1-based）。
- Line numbers are 1-based (matching grep / editor).
- 行号是 1-based（和 grep / 编辑器一致）。
- Result cap: 50 references; more = "… N more …".
- 结果上限 50 条，超出标 … N more …。

## When to Use grep Instead

## 什么时候用 grep

grep is fine for: "where is X defined?", listing symbols, fuzzy search. `references` is for "who uses it?" — the safety net before changing an exported API.

找"X 定义在哪"、列符号、模糊搜索——grep 就够。references 专门回答"谁用了它"。

## Lifecycle

## 生命周期

- Language server starts once per session (session-scoped ctx, not turn-scoped).
- 语言服务器每个会话启动一次（使用会话级 ctx，非回合级）。
- Turn-level ctx cancels the query, not the server — gopls cold-start is not re-done on Esc.
- 回合级 ctx 取消的是查询，不是 server——gopls 冷启动不会因 Esc 而重新开始。
- Dead server (crash / EOF) fails all inflight and future calls.
- server 崩溃时所有进行中和未来的调用都失败。

Design: PRD feature-lsp.md

设计文档：PRD feature-lsp.md