AgentSkillsCN

lsp

当您需要语义化的代码导航——查找定义、引用或调用方时,这一工具能为您提供强大的支持。涵盖LSP、跳转到定义、查找引用、悬停提示以及代码智能。注意:此工具不适用于文本模式搜索(请使用grep),也不适用于文件发现(请使用glob)。

SKILL.md
--- frontmatter
name: lsp
description: Use when needing semantic code navigation - find definitions, references, or callers. Covers LSP, go to definition, find references, hover, code intelligence. NOT for: text pattern searches (use grep), file discovery (use glob).

LSP Code Intelligence Skill

Use this skill when you need guidance on using Claude Code's LSP (Language Server Protocol) tools for code navigation and understanding.

Quick Reference

OperationUse CaseExample
goToDefinitionFind where a symbol is definedJump to function implementation
findReferencesFind all usages of a symbolBefore renaming a function
hoverGet type info and docsQuick understanding of a type
documentSymbolList symbols in a fileUnderstanding file structure
workspaceSymbolSearch symbols globallyFinding a class by name
goToImplementationFind interface implementationsWorking with abstract types
incomingCallsFind callers of a functionImpact analysis
outgoingCallsFind callees of a functionUnderstanding dependencies

Prerequisites

LSP must be configured for the language. Check:

  1. Is there a .lsp.json in the project root?
  2. Are LSP plugins installed via /plugin command?
  3. Is the language server binary installed?

Common Workflows

Safe Symbol Rename

code
1. Position cursor on symbol name
2. Use findReferences to locate ALL usages
3. Review each reference
4. Make the rename changes
5. Run typecheck to verify

Understanding Unfamiliar Code

code
1. Use goToDefinition on the entry point
2. Use hover on types you don't recognize
3. Use outgoingCalls to understand dependencies
4. Use incomingCalls to understand how it's used

Impact Analysis Before Changes

code
1. Use findReferences on the function you're modifying
2. Use incomingCalls to see the call chain
3. Assess which callers might be affected
4. Plan your changes accordingly

Tracing a Bug

code
1. Start at the error location
2. Use goToDefinition to trace back through the call stack
3. Use findReferences on suspicious variables
4. Identify where incorrect values originate

LSP vs Grep/Glob

ScenarioUse LSPUse Grep/Glob
Find function definitionYesFallback only
Find all usages of a symbolYesFallback only
Search for text patternsNoYes
Search comments/stringsNoYes
Search config valuesNoYes
LSP not configuredN/AYes

Common LSP Servers

LanguageServerInstall
TypeScript/JStypescript-language-servernpm i -g typescript-language-server typescript
Pythonpyrightpip install pyright or npm i -g pyright
Rustrust-analyzerVia rustup or standalone
Gogoplsgo install golang.org/x/tools/gopls@latest
C/C++clangdVia LLVM or package manager
JavajdtlsVia Eclipse
Rubysolargraphgem install solargraph
PHPintelephensenpm i -g intelephense

Troubleshooting

LSP not working?

  1. Check if language server is installed: which <server-name>
  2. Check for .lsp.json configuration
  3. Check /plugin Errors tab for issues
  4. Try restarting Claude Code

No results from findReferences?

  • LSP may not be fully initialized yet
  • Try a simpler operation first (like hover)
  • Check if the symbol is exported/public

goToDefinition fails?

  • Symbol may be from external package (not in workspace)
  • Type definitions might be in a .d.ts file
  • Try hover to at least get type info