Skip to content

LSP: refactorings (specs/lsp/refactor.t27) #12236

Open

Description

@gHashTag

Refactorings as code actions: extract, inline, rewrite, move, and generate. rust-analyzer ships about 168 assists, sourcekit-lsp 54 refactorings and Gleam about 45 code actions; the first 15 below are the ones users reach for daily. Part of the LSP epic, Refs #12209 (wave 1, standard features). Only .t27: no code in any other language, not even scratch probes or a loader; see skill only-t27.

Depends on specs/lsp/code_actions.t27 (registration), specs/lsp/index.t27 and specs/lsp/rename.t27 (the edits that cross files reuse rename's reference walk).

Prior art:

Boundary

  • specs/lsp/refactor.t27

User Scenarios

  • Given a selection of 3 statements that read 2 locals and produce 1 value, when the client asks for refactor.extract, then an action Extract function is listed; applying it makes a function with 2 parameters returning the value and replaces the selection by a call.
  • Given the cursor on a call to a one-use private function, when the client asks for refactor.inline, then Inline function replaces the call and deletes the function, and t27c check stays green.
  • Given the cursor on a function with no test, when the client asks for refactor.rewrite, then Generate test adds a test block with the function's name and a placeholder assertion in the right place.
  • Given a declaration in spec A used only by spec B, when the client asks for refactor.move, then Move to B moves it, rewrites the use lines and leaves A compiling.
  • Given a selection that is not a refactorable range, when the action is requested, then it is listed as disabled with a reason, or not listed at all, never as an action that fails when applied.

Requirements

  • FR-001: The module MUST register the actions: extract function, extract constant, extract variable, inline function, inline constant, inline variable, add missing enum cases, flip operands, invert condition, wrap in block, unwrap block, generate test, generate doc comment, move declaration, and rename to match file.
  • FR-002: Each action MUST declare its kind, a precondition on the selection, and an edit builder; the table is in the module so the matrix can list it.
  • FR-003: Every edit MUST preserve behaviour: a test per action applies it on a fixture, runs t27c check through the snapshot and asserts 0 new diagnostics, and for extract and inline asserts that the test results are unchanged.
  • FR-004: Actions MUST be lazy (codeAction/resolve), and move MUST use a change annotation that asks the user for confirmation.
  • FR-005: A name introduced by an action MUST NOT clash with a name in scope; the module picks name_2 style names and says so in the title.

Success Criteria

  • At least 40 tests in specs/lsp/refactor.t27 pass, run on the lab with t27c test-report (exit 0), at least 2 per action.
  • A negative control asks each action on a range where its precondition fails and asserts it is absent or disabled.
  • git diff --name-only master lists only specs/lsp/refactor.t27 (0 files in other languages).

Activity

  1. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Spec created: specs/lsp/refactor.t27 (typecheck OK, 1 test pass).

  2. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A .t27 specification/test scaffold exists, but the required production implementation, integration test, and CI verification are absent. This issue remains open until the target component implements the specified behavior and evidence is provided.

  3. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Specs created. M4 milestone complete.

  4. gHashTag commented on Nov 18, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A .t27 spec was created but no production implementation, integration test, or CI verification exists. This issue remains open until the target component implements the specified behavior and evidence is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/specs.t27 spec files and conformanceenhancementNew feature or requestspec

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions