lsp-format-code
Acerca de
Esta habilidad formatea archivos de código o selecciones utilizando el formateador de tu servidor de lenguaje, aplicando un estilo consistente como gofmt o Prettier. Es ideal para limpiar código generado o preparar archivos para commit, admitiendo tanto el formateo de archivos completos como por rangos. Requiere el servidor MCP agent-lsp para interactuar con el motor de formateo de tu editor.
Instalación rápida
Claude Code
Recomendadonpx skills add blackwell-systems/agent-lsp -a claude-code/plugin add https://github.com/blackwell-systems/agent-lspgit clone https://github.com/blackwell-systems/agent-lsp.git ~/.claude/skills/lsp-format-codeCopia y pega este comando en Claude Code para instalar esta habilidad
Documentación
Requires the agent-lsp MCP server.
lsp-format-code
Format a file or selection using the language server's formatter — the same formatting engine your IDE uses. Applies language-specific rules (gofmt, prettier, rustfmt, black) without requiring those tools to be on PATH separately.
When to use
- Before committing: ensure consistent style across edited files
- After generating code: clean up AI-generated indentation and spacing
- After a refactor that shifted indentation levels
- When a linter flags style violations fixable by the formatter
Use /lsp-safe-edit instead when you are making a logic change and want
before/after diagnostic comparison alongside the edit.
Workflow
Step 1 — Check formatting is supported (optional)
If unsure whether the language server supports formatting for this file, check capabilities first:
mcp__lsp__get_server_capabilities({ "file_path": "<file>" })
Look for documentFormattingProvider (full-file) and
documentRangeFormattingProvider (range). If neither is present, the server
does not support formatting — stop and report.
Skip this step if you know the language supports formatting (Go, TypeScript, Rust, Python all do via their standard servers).
Step 2 — Open the file
mcp__lsp__open_document({ "file_path": "/abs/path/to/file.go", "language_id": "go" })
Step 3 — Request formatting edits
Full file:
mcp__lsp__format_document({ "file_path": "/abs/path/to/file.go" })
Selection only:
mcp__lsp__format_range({
"file_path": "/abs/path/to/file.go",
"start_line": <N>,
"end_line": <M>
})
Both return TextEdit[] — a list of replacements to apply. They do not
write to disk. If the list is empty, the file is already correctly formatted.
Step 4 — Apply the edits
Pass the TextEdit[] from Step 3 to apply_edit:
mcp__lsp__apply_edit({ "workspace_edit": <TextEdit[] from Step 3> })
This writes the formatting changes to disk.
Step 5 — Verify (optional but recommended)
Call get_diagnostics to confirm formatting did not introduce any errors:
mcp__lsp__get_diagnostics({ "file_path": "/abs/path/to/file.go" })
Formatting should never introduce errors — if it does, report immediately without committing.
Output format
## Format result: <filename>
Changes applied: N edits
Lines affected: <range or "whole file">
Formatter: <gopls | typescript-language-server | rust-analyzer | ...>
Status: FORMATTED ✓
If no edits were returned:
Status: ALREADY FORMATTED — no changes needed
If formatting is not supported:
Status: NOT SUPPORTED — <server> does not expose documentFormattingProvider
Fallback: run the formatter directly (gofmt, prettier, rustfmt, etc.)
Multi-file formatting
For formatting multiple files (e.g. all files changed in a PR):
- Call
format_documentfor each file — these can run in parallel. - Collect all
TextEdit[]responses. - Apply each file's edits via
apply_editsequentially. - Report total edits across all files.
Do not apply edits from multiple files in a single apply_edit call —
apply per-file to keep changes scoped and reversible.
Decision guide
| Situation | Action |
|---|---|
| Formatting a whole file before commit | format_document → apply_edit |
| Formatting only generated code in a function | format_range with the function's line range |
Empty TextEdit[] returned | File is already formatted — no action needed |
| Server doesn't support formatting | Report and suggest running CLI formatter directly |
| Formatting introduces diagnostics | Do not commit — report immediately |
| Formatting a Go file in a workspace repo | Ensure GOWORK=off is set if running via shell fallback |
Language notes
| Language | Formatter | Server |
|---|---|---|
| Go | gofmt (via gopls) | gopls |
| TypeScript / JavaScript | prettier or built-in (via typescript-language-server) | typescript-language-server |
| Rust | rustfmt (via rust-analyzer) | rust-analyzer |
| Python | black or autopep8 (via pyright/pylsp) | pyright-langserver or pylsp |
| C / C++ | clang-format (via clangd) | clangd |
The language server delegates to the language's standard formatter — results match what your IDE would produce.
Repositorio GitHub
Habilidades relacionadas
content-collections
MetaEsta habilidad proporciona una configuración probada en producción para Content Collections, una herramienta centrada en TypeScript que transforma archivos Markdown/MDX en colecciones de datos con tipado seguro mediante validación Zod. Úsala al construir blogs, sitios de documentación o aplicaciones Vite + React con mucho contenido para garantizar seguridad de tipos y validación automática de contenido. Abarca todo, desde la configuración del plugin de Vite y compilación MDX hasta la optimización de despliegue y validación de esquemas.
polymarket
MetaEsta habilidad permite a los desarrolladores crear aplicaciones con la plataforma de mercados de predicción Polymarket, incluyendo la integración de API para operaciones y datos de mercado. También proporciona transmisión de datos en tiempo real a través de WebSocket para monitorear operaciones en vivo y actividad del mercado. Úsela para implementar estrategias de trading o crear herramientas que procesen actualizaciones de mercado en tiempo real.
creating-opencode-plugins
MetaEsta habilidad ayuda a los desarrolladores a crear complementos de OpenCode que se conectan a más de 25 tipos de eventos, como comandos, archivos y operaciones LSP. Proporciona la estructura del complemento, las especificaciones de la API de eventos y los patrones de implementación para módulos en JavaScript/TypeScript. Úsala cuando necesites interceptar, monitorear o extender el ciclo de vida del asistente de IA de OpenCode con lógica personalizada basada en eventos.
sglang
MetaSGLang es un framework de alto rendimiento para el servicio de LLM que se especializa en generación rápida y estructurada para JSON, expresiones regulares y flujos de trabajo de agentes utilizando su caché de prefijos RadixAttention. Ofrece una inferencia significativamente más rápida, especialmente para tareas con prefijos repetidos, lo que lo hace ideal para salidas complejas y estructuradas, y conversaciones multiturno. Elige SGLang sobre alternativas como vLLM cuando necesites decodificación restringida o estés construyendo aplicaciones con uso extensivo de prefijos compartidos.
