スキル一覧に戻る

lsp-format-code

blackwell-systems
更新日 5 days ago
1 閲覧
53
2
53
GitHubで表示
メタgeneral

について

このスキルは、コードファイルまたは選択範囲を言語サーバーのフォーマッタを使用して整形し、gofmtやPrettierのような一貫したスタイルを適用します。生成されたコードの整理やコミット前のファイル準備に最適で、ファイル全体と範囲ベースの両方のフォーマットをサポートします。エディタのフォーマットエンジンと連携するには、agent-lsp MCPサーバーが必要です。

クイックインストール

Claude Code

推奨
メイン
npx skills add blackwell-systems/agent-lsp -a claude-code
プラグインコマンド代替
/plugin add https://github.com/blackwell-systems/agent-lsp
Git クローン代替
git clone https://github.com/blackwell-systems/agent-lsp.git ~/.claude/skills/lsp-format-code

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

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):

  1. Call format_document for each file — these can run in parallel.
  2. Collect all TextEdit[] responses.
  3. Apply each file's edits via apply_edit sequentially.
  4. 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

SituationAction
Formatting a whole file before commitformat_documentapply_edit
Formatting only generated code in a functionformat_range with the function's line range
Empty TextEdit[] returnedFile is already formatted — no action needed
Server doesn't support formattingReport and suggest running CLI formatter directly
Formatting introduces diagnosticsDo not commit — report immediately
Formatting a Go file in a workspace repoEnsure GOWORK=off is set if running via shell fallback

Language notes

LanguageFormatterServer
Gogofmt (via gopls)gopls
TypeScript / JavaScriptprettier or built-in (via typescript-language-server)typescript-language-server
Rustrustfmt (via rust-analyzer)rust-analyzer
Pythonblack 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.

GitHub リポジトリ

blackwell-systems/agent-lsp
パス: skills/lsp-format-code
0
agentskillsai-agentsai-toolingclaudeclaude-codecode-intelligence

関連スキル

content-collections

メタ

このスキルは、Content Collections(Markdown/MDXファイルを型安全なデータコレクションに変換するTypeScriptファーストのツール)の本番環境でテストされた設定を提供します。Zodバリデーションによる型安全性を実現し、ブログ、ドキュメントサイト、コンテンツ重視のVite + Reactアプリケーション構築時にご利用ください。Viteプラグインの設定、MDXコンパイルから、デプロイ最適化、スキーマバリデーションまで、すべてを網羅しています。

スキルを見る

polymarket

メタ

このスキルは、開発者がPolymarket予測市場プラットフォームを活用したアプリケーション構築を可能にします。API統合による取引や市場データの取得に加え、WebSocketを介したリアルタイムデータストリーミングにより、ライブ取引や市場活動を監視できます。取引戦略の実装や、ライブ市場更新を処理するツールの作成にご利用ください。

スキルを見る

creating-opencode-plugins

メタ

このスキルは、開発者がコマンド、ファイル、LSP操作など25種類以上のイベントタイプにフックするOpenCodeプラグインを作成することを支援します。JavaScript/TypeScriptモジュール向けに、プラグイン構造、イベントAPI仕様、および実装パターンを提供します。カスタムイベント駆動ロジックでOpenCode AIアシスタントのライフサイクルをインターセプト、監視、または拡張する必要がある場合にご利用ください。

スキルを見る

sglang

メタ

SGLangは、高性能なLLMサービングフレームワークであり、RadixAttentionプレフィックスキャッシュを活用したJSON、正規表現、エージェントワークフロー向けの高速で構造化された生成を特長とします。特にプレフィックスが繰り返されるタスクにおいて、大幅に高速な推論を実現し、複雑な構造化出力やマルチターン対話に最適です。制約付きデコードが必要な場合や、広範なプレフィックス共有を伴うアプリケーションを構築する場合は、vLLMなどの代替案ではなくSGLangを選択してください。

スキルを見る