lsp-extract-function
Extract a selected code block into a named function.
Skill by blackwell-systems
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/blackwell-systems-lsp-extract-function
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/lsp-extract-function
Tools it pre-approves 8
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
mcp__lsp__list_symbolsmcp__lsp__suggest_fixesmcp__lsp__execute_commandmcp__lsp__apply_editmcp__lsp__get_diagnosticsmcp__lsp__open_documentmcp__lsp__format_documentmcp__lsp__get_server_capabilities
What's inside
- Skill name
lsp-extract-function- Description
- Extract a selected code block into a named function. Primary path uses the language server's extract-function code action; falls back to manual extraction when no code action is available. Validates captured variables, scope shadowing, and compilation after extraction.
- License
- MIT
- Compatibility
- Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp)
- Allowed tools
- mcp__lsp__list_symbols, mcp__lsp__suggest_fixes, mcp__lsp__execute_command, mcp__lsp__apply_edit, mcp__lsp__get_diagnostics, mcp__lsp__open_document, mcp__lsp__format_document, mcp__lsp__get_server_capabilities
- Metadata
- optional-capabilities: documentFormattingProvider documentSymbolProvider · required-capabilities: codeActionProvider
- Instructions
- 230 lines in SKILL.md · view on GitHub
Files (2)
- SKILL.md
- patterns.md · references/
SKILL.md (first lines)
> Requires the agent-lsp MCP server.
# lsp-extract-function: Extract Code Block into a Named Function
**This skill RESTRUCTURES existing code** — it takes code that already exists
and moves it into a new function. This is distinct from `/lsp-generate`, which
creates NEW code that does not yet exist (stubs, mocks, interface implementations).
Use this skill when the code is already written; use `/lsp-generate` when you
need to generate code from scratch.
**Invocation:** User provides `file_path` (absolute path), `start_line` and
`end_line` (1-indexed range), and `new_function_name` (desired name for the
extracted function).
---
## Prerequisites
If LSP is not yet initialized, call `mcp__lsp__start_lsp` with the workspace
root first. Auto-inference applies when file paths are provided, but an explicit
start is required when switching workspaces.
---
## Step 1 — Get context (document symbols)
Call `mcp__lsp__open_document` to open the file, then call
`mcp__lsp__list_symbols` to understand the containing function and scope:
```
mcp__lsp__open_document({ "file_path": "<file_path>" })
mcp__lsp__list_symbols({ "file_path": "<file_path>" })
```
This establishes:
- Which function contains the selection
- Whether `new_function_name` already exists in the file (name collision check)
**Mandatory name collision check:** If `new_function_name` already exists as a
symbol in the document symbols list, report the conflict and stop immediately:
> Cannot extract: function `new_function_name` already exists in this file.
> Choose a different name and retry.
---
## Step 2 — Check server capabilities
Call `mcp__lsp__get_server_capabilities` to understand what the language server
supports:
```
mcp__lsp__get_server_capabilities({})
```
Check for `codeActionProvider` in the response. Note whether `execute_command`
is listed in `executeCommandProvider.commands`. This determines whether the
primary path (Step 3) is available.
---
## Step 3 — Primary path: LSP code action
Call `mcp__lsp__suggest_fixes` with the selection range:
```
mcp__lsp__suggest_fixes({
"file_path": "<file_path>",
"start_line": N,
"start_column": 1,
"end_line": M,
"end_column": 999
})
```
Filter the returned actions for extract-function actions: include any action
whose `kind` contains `"refactor.extract"` OR whose `title` contains both
"Extract" and "function" (case-insensitive).
**If an extract-function action is found:**
- Display the action title to the user
- If the action proposes a different name than `new_function_name`, ask for
confirmation before proceeding
- Execute via `mcp__lsp__execute_command` if the action has a `command` field:
```
mcp__lsp__execute_command({
"command": "<action.command.command>",
"arguments": <action.command.arguments>
})
```
- OR apply directly via `mcp__lsp__apply_edit` if the action has an `edit` field:
```
mcp__lsp__apply_edit({ "workspace_edit": <action.edit> })
```
- Skip to Step 5 after applying.
**If no extract-function action is found:** fall through to Step 4 (manual fallback).
---
## Step 4 — Manual fallback
When no code action is available, perform manual extraction:
### a) Analyze the selection
Read the selected lines (`start_line` through `end_line`) and identify:
- **Parameters:** Variables used inside the selection that are declared outside
(captured from outer scope — must become function parameters)
- **Return values:** Variables declared inside the selection that are used outside
(must be returned from the extracted function)
- **Early returns:** Return statements inside the selection (the extracted function
must wrap these)
### b) Construct and confirm the proposed signature
Build the extracted function signature based on the captured variables analysis.
Display the proposed signature to the user before writing:From blackwell-systems/agent-lsp, MIT.
More from blackwell-systems/agent-lsp
- 0.791score
lsp-edit-export
blackwell-systems
Safe workflow for editing exported symbols or public APIs.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-understand
blackwell-systems
Deep-dive exploration of unfamiliar code — given a symbol or file, builds a complete Code Map showing type info, implementations, call hierarchy (2-level…
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-simulate
blackwell-systems
Speculative code editing session — simulate changes in memory before touching disk.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-rename
blackwell-systems
Two-phase safe rename across the entire workspace.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-impact
blackwell-systems
Blast-radius analysis for a symbol or file — shows all callers, type supertypes/subtypes, and reference count before you change it.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-dead-code
blackwell-systems
Enumerate exported symbols in a file and surface those with zero references across the workspace.
SkillAFreshness: A★ 164Claude Code +9 - 0.787score
lsp-safe-edit
blackwell-systems
Wrap any code edit with before/after diagnostic comparison.
SkillAFreshness: A★ 164Claude Code +9 - 0.787score
lsp-explore
blackwell-systems
"Tell me about this symbol": hover + implementations + call hierarchy + references in one pass — for navigating unfamiliar code.
SkillAFreshness: A★ 164Claude Code +9 - 0.787score
lsp-fix-all
blackwell-systems
Apply available quick-fix code actions for all current diagnostics in a file, one at a time with re-collection between each fix.
SkillAFreshness: A★ 164Claude Code +9 - 0.787score
lsp-generate
blackwell-systems
Trigger language server code generation — implement interface stubs, generate test skeletons, add missing methods, generate mock types.
SkillAFreshness: A★ 164Claude Code +9 - 0.787score
lsp-refactor
blackwell-systems
End-to-end safe refactor workflow — blast-radius analysis, speculative preview, apply to disk, verify build, run affected tests.
SkillAFreshness: A★ 164Claude Code +9 - 0.785score
lsp-inspect
blackwell-systems
Full code quality audit for a file, package, or directory.
SkillAFreshness: A★ 164Claude Code +9
Signals
- Stars
- 164
- Forks
- 20
- Open issues
- 5
- Contributors
- 9
- Last commit (this folder)
- May 10, 2026 (5 months ago)
- Last release
- Oct 24, 2026 (4 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/blackwell-systems/agent-lsp
- Website
- www.agent-lsp.com/
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from blackwell-systems
- 0.791score
lsp-impact
blackwell-systems
Blast-radius analysis for a symbol or file — shows all callers, type supertypes/subtypes, and reference count before you change it.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-simulate
blackwell-systems
Speculative code editing session — simulate changes in memory before touching disk.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-edit-export
blackwell-systems
Safe workflow for editing exported symbols or public APIs.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-dead-code
blackwell-systems
Enumerate exported symbols in a file and surface those with zero references across the workspace.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-rename
blackwell-systems
Two-phase safe rename across the entire workspace.
SkillAFreshness: A★ 164Claude Code +9 - 0.791score
lsp-understand
blackwell-systems
Deep-dive exploration of unfamiliar code — given a symbol or file, builds a complete Code Map showing type info, implementations, call hierarchy (2-level…
SkillAFreshness: A★ 164Claude Code +9
Cite this page
lsp-extract-function skill. Agent Mart. https://agentmart.dev/skills/blackwell-systems-lsp-extract-function (last updated 2026-10-24)