跳到正文
cccskills
免费在 GitHub 公开

lsp-refactoring

Intelligent code refactoring using IDE-level tools (rename, find-references, go-to-definition), AST-aware pattern matching, and TDD verification. Use for safe, large-scale refactoring with precision.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.2 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

LSP Refactoring

Refactoring workflow that combines language server capabilities with code search and test-driven verification for safe, precise code transformations.

When to Use This Skill

  • Renaming symbols across an entire workspace
  • Extracting functions, classes, or modules
  • Moving code between files with automatic reference updates
  • Large-scale pattern-based code transformations
  • Any refactoring where manual find-replace is error-prone

What This Skill Does

Phase 1: Analysis — Understand Before Changing

  1. Scope assessment: Find all usages of the target symbol using grep or IDE references
  2. Dependency graph: Trace where the symbol is defined and what depends on it
  3. Impact analysis: Identify all files that will be affected
  4. Pattern discovery: Search for similar patterns that should be refactored consistently
# Find all usages of a function
grep -rn "getUserData" src/ --include="*.ts"

# Find pattern across codebase with AST-aware tools (if available)
# e.g., ast-grep, semgrep, or comby
ast-grep --pattern 'console.log($MSG)' --lang typescript

Phase 2: Plan — Design the Transformation

  1. Pre-flight check: Run the type checker / linter to capture baseline errors
  2. Rename validation: Verify the symbol can be safely renamed (no conflicts)
  3. Transformation plan: List each change with file, line, before/after
  4. Test identification: Find tests covering the code being refactored

Phase 3: Execute — Apply Changes Safely

For renames (use IDE/editor capabilities when available):

# Using sed for simple renames
find src/ -name "*.ts" -exec sed -i '' 's/getUserData/fetchUserProfile/g' {} +

# Or use language-specific tools
# TypeScript: ts-morph, jscodeshift
# Python: rope, bowler
# Go: gorename

For pattern-based transformations:

# Using ast-grep (if installed)
ast-grep --pattern 'console.log($MSG)' --rewrite 'logger.info($MSG)' --lang typescript

# Using comby
comby 'console.log(:[msg])' 'logger.info(:[msg])' .ts

For structural changes (extract/move):

  1. Create the new target (file, function, class)
  2. Move the code
  3. Update all references using LSP rename
  4. Remove the old code
  5. Verify no dangling references

Phase 4: Verify — TDD Confirmation

  1. Type check: Run the project type checker — must be clean
    npx tsc --noEmit          # TypeScript
    mypy src/                  # Python
    go vet ./...               # Go
    
  2. Build check: Run project build — must pass
  3. Test check: Run test suite — all previously passing tests must still pass
  4. Diff review: git diff to review the complete changes for unintended modifications

If any check fails:

  • Revert changes: git checkout -- .
  • Analyze the failure
  • Adjust approach and retry

Approach by Language

LanguageRename ToolPattern SearchType Check
TypeScriptts-morph, jscodeshiftast-grep, semgreptsc --noEmit
Pythonrope, bowlerast-grep, semgrepmypy, pyright
Gogorename, goplsast-grep, semgrepgo vet
JavaIntelliJ refactor, openrewritesemgrepjavac
Rustrust-analyzerast-grepcargo check

Anti-Patterns

  • Manual find-replace without verifying all references — misses dynamic usages
  • Skipping type check after rename — may introduce type errors
  • Not running tests after refactoring — behavior may have changed
  • Refactoring while fixing bugs — do one or the other, never both

Example

User: "Rename getUserData to fetchUserProfile across the project"

Output:

  1. grep -rn finds 23 usages across 8 files
  2. Applies rename using sed/jscodeshift across all locations
  3. tsc --noEmit passes with no errors
  4. npm test — 47 tests pass
  5. git diff shows clean, focused changes

Inspired by: oh-my-opencode /refactor command

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

查看 ArabelaTso 的全部技能

报告此技能的问题