lsp-extract-function

Extract selected code blocks into named functions via language server code actions.

102|5|Updated Apr 6, 2026
One-click install
npx skills add https://github.com/blackwell-systems/agent-lsp --skill lsp-extract-function
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lsp-extract-function
Source: https://github.com/blackwell-systems/agent-lsp/tree/main/skills/lsp-extract-function
Command: npx skills add https://github.com/blackwell-systems/agent-lsp --skill lsp-extract-function

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Extract a selected code block into a named function using the language server's extract-function code action or a manual fallback.

Core Features & Use Cases

  • Primary path uses the language server's extract-function code action to create a new function from a selected block, preserving variables and scope.
  • Manual fallback extracts the block when code actions are unavailable, validating captured variables, shadowing, and return values to ensure correctness.
  • Supports validating and applying edits via the MCP LSP tools, enabling safe refactoring during code editing workflows.

Quick Start

Provide the file_path, start_line, end_line, and new_function_name to extract the selected block.

Frequently Asked Questions about lsp-extract-function

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract a code block into a named function using LSP?

You can extract a code block into a named function by providing the file path, start line, end line, and new function name. The Skill uses the language server's extract-function code action or a manual fallback to refactor the block while preserving variable scope.

How does extract-function handle captured variables and scope?

Extract-function handles captured variables and scope by validating them during the refactor. Whether using the language server code action or the manual fallback, it ensures variable shadowing and return value propagation are managed correctly.

Do I need a running agent-lsp MCP server to extract functions?

Yes, you need a running agent-lsp MCP server to extract functions via the primary code action path. It requires access to document operations like open_document, get_code_actions, and apply_edit to apply refactoring edits safely.

What happens if code actions are unavailable when refactoring code?

When code actions are unavailable during refactoring, the Skill uses a manual fallback to extract the code block. This fallback validates captured variables, shadowing, and return values to ensure the extracted function maintains correctness.

Can I use extract-function for automated code editing workflows?

Yes, you can use extract-function for automated code editing workflows. It supports validating and applying edits via MCP LSP tools, enabling safe refactoring of selected blocks into named functions during automated code editing sessions.