跳转到内容

Refactor and format code

此内容尚不支持你的语言。

Refactorings change the structure of code without changing what it does: a new name everywhere it is used, a selected expression turned into a variable, a block into a method. Each one, across all the files it touches, is one step to undo. Rename, extract and inline: Works. The other refactorings: Experimental.

Rename a function across files, and undo it in one step
Editor with pricing.py, the caret on the name with_tax on line 11, its hint says 4 usages
  1. Editor with pricing.py, the caret on the name with_tax on line 11, its hint says 4 usages
  2. Popup Rename 'with_tax' and its usages to, with the name in the field, Search in comments and strings checked and Search for text occurrences not checked
  3. The rename popup with add_tax typed into the field
  4. Editor with pricing.py now defining add_tax; the tabs cart.py, pricing.py and test_cart.py are marked as changed, and the status bar says Renamed with_tax to add_tax in 3 file(s)
  5. Editor with cart.py: the import line and the return statement now use add_tax
  6. Editor with cart.py using with_tax again; the status bar says Undone: Rename with_tax to add_tax (3 files)

Real frames of the application · ferris-idea drive, then ferris-idea drive screenshot after each step (docs/site/scripts/record-tour.py) · v1.6.0 release build, 2026-12-04 · throwaway demo project, a small Python shop with Pyright as language server; theme Ferris IDEA Dark

Most refactorings ask the language server of the file’s language for the edit, on the text as it is in the editor. Install the server the page of your language names. Which refactorings exist depends on the language:

Language Rename Extract and inline Also
Rust rust-analyzer rust-analyzer’s extract and inline actions
Python Pyright Ferris IDEA’s own: Extract Variable, Extract Method, Extract Constant, Inline Variable
Java the Eclipse Java server the server’s, including Extract Field and Introduce Parameter Surround With…
JavaScript, TypeScript typescript-language-server the server’s; Ferris IDEA’s own Extract Variable where the server offers none Extract Interface, Extract Superclass, Pull Members Up (Ferris IDEA’s own)
C, C++ clangd clangd’s extract actions, no Inline
other languages the language server, if it renames what the language server offers

Change Signature is Ferris IDEA’s own and works in Rust, Go, Python, Java, Kotlin, JavaScript, TypeScript, PHP, Ruby and the C-like languages. Move updates references through the server and Ferris IDEA’s own rewriting, as described below. Where a refactoring comes from the server, it is as complete as that server’s.

  1. Put the caret on a name and press ⇧F6, or Refactor › Rename….
  2. A popup Rename ‘total’ and its usages to opens with the name selected. Type the new name.
  3. Keep or clear Search in comments and strings (on by default) and Search for text occurrences (off by default).
  4. ↩ renames. The status bar names the old and new name and how many files changed.

Open files change in their editors, unsaved; files that are not open are written to disk. Only the project’s own sources are changed, never dependencies. Renaming a Java class in its own file renames the file too. On a keyword, a literal or a built-in type Ferris IDEA answers Cannot rename this element: the caret should be on an identifier.

  1. Select an expression, or put the caret in one. For Extract Method, select the statements.
  2. Choose Refactor › Extract/Introduce › Introduce Variable… (⌥⌘V, CtrlAltV), Introduce Constant… or Extract Method…. The editor’s context menu calls them Extract Variable… and Extract Constant….
  3. If there is one way to do it, it is done at once; with several (for example, which enclosing expression), the list of context actions opens to choose.
  4. The rename popup opens on the new name the server chose (value, placeholder, …). Type yours and press ↩.

Refactor › Inline… (⌥⌘N, CtrlAltN) does the reverse: it replaces a variable, constant or method by its value or body at every use.

A server has 45 seconds to answer; after that the status bar says which refactoring failed and why. Python’s own extraction refuses with the reason, such as Cannot extract `x +` into a variable: ….

Refactor › Refactor This… (⌃T on macOS, CtrlAltShiftT on Linux) lists every refactoring that can act at the caret, from the server and Ferris IDEA’s own, so you need not remember the keys.

  1. Put the caret on a function’s declaration or a call and press ⌘F6 (CtrlF6), or Refactor › Change Signature….
  2. The parameter list opens as one line of text. Reorder, rename, remove or add parameters. A new parameter needs a value for the existing calls: rate: float = 0.1.
  3. ↩ changes the declaration and every call.

Calls that do not fit the old signature, such as calls with unpacked arguments, are listed and left as they are, rather than changed wrongly. Overriding methods are not followed.

  • Refactor › Move… (F6) moves the active file, or the files selected in the Project tool window, to a folder you type. References are updated: by the language server (Rust modules, Java packages, TypeScript imports) and by Ferris IDEA for relative C and C++ #include lines, JavaScript and TypeScript imports, Rust #[path] attributes, and the package line of Java and Kotlin. Save the file first; an unsaved file is not moved.
  • Refactor › Copy… (F5) copies a file.
  • Refactor › Safe Delete… (⌘⌦, AltDelete) first searches for usages. With none, it deletes the declaration with its comments and annotations; with some, it lists them (Safe Delete name: 3 usages) and you choose Delete anyway or Cancel.

A refactoring is one undo step named after it, such as Rename helper to calc, across every file it changed. Press ⌘Z in any of those files and all of them go back; the status bar says Undone: Rename helper to calc.

If one of the files was changed after the refactoring, undo is refused and says which file, rather than mixing the two changes: undo that later change first, or restore the file from local history, where every refactoring leaves a labelled entry (Before Rename helper to calc). The 20 newest refactorings can be undone.

Command Menu What it does
Reformat Code Code › Reformat Code formats the selection, or the whole file
Reformat File Code › Reformat File… asks first: Selected text only, Only changed lines (Git), Optimize imports
Optimize Imports Code › Optimize Imports removes unused and duplicate imports and sorts them
Reformat with Prettier Code › Reformat with Prettier runs the project’s Prettier
Fix ESLint Problems Code › Fix ESLint Problems applies the project’s ESLint fixes

Ferris IDEA has no code style engine of its own; it runs the formatter that belongs to the language, so the result matches what your build and CI produce:

  • Rust, Go, C and C++, TOML, YAML and others: the language server’s formatter (rustfmt through rust-analyzer, gopls, clang-format through clangd, taplo).
  • JavaScript, TypeScript, CSS and others: Prettier from the project, in a trusted project that has it; otherwise the language server.
  • Python: the project’s ruff or black. Ferris IDEA installs neither; without them, the status bar says so.
  • SQL and Markdown (without Prettier): Ferris IDEA’s own formatter, whole files only.

Indentation, tab width, trailing whitespace and the final newline follow the project’s .editorconfig (Settings). Optimize Imports works in Java and Kotlin (by Ferris IDEA), Python (ruff or the server), and JavaScript, TypeScript, Vue and Svelte (the server). The result is one undo step and says what happened: Already formatted., Removed 1 import.

Keyboard of
ActionShortcut
Code › Optimize Imports⌃⌥OCtrlAltO
Code › Reformat Code⌥⌘LCtrlAltL
Code › Reformat File⌥⇧⌘LCtrlShiftAltL
Edit › Redo⇧⌘Z or ⌥⇧⌫CtrlShiftZ or AltShiftBackspace
Edit › Undo⌘ZCtrlZ or AltBackspace
Refactor › Change Signature⌘F6CtrlF6
Refactor › CopyF5F5
Refactor › Extract/Introduce › Extract Constant⌥⌘CCtrlAltC
Refactor › Extract/Introduce › Extract Field⌥⌘FCtrlAltF
Refactor › Extract/Introduce › Extract Method⌥⌘MCtrlAltM
Refactor › Extract/Introduce › Extract Variable⌥⌘VCtrlAltV
Refactor › Extract/Introduce › Introduce Parameter⌥⌘PCtrlAltP
Refactor › Inline⌥⌘NCtrlAltN
Refactor › MoveF6F6
Refactor › Refactor This⌃Tno shortcut
Refactor › Rename⇧F6ShiftF6
Refactor › Safe Delete⌘⌦AltDelete
  • Nothing happens. The language server offers no such action at this place. Select the exact expression, or check the table above for your language.
  • … failed: …: no answer within 45 s. The server is busy indexing; try again when the status bar shows it ready.
  • No ruff or black found …. Install one of them into the project’s virtual environment or on your PATH.
  • Undo refused. A file of the refactoring changed after it. Undo that change first, or use local history.

Every refactoring is a tool with a dry run that returns the edits per file. Applying needs write; formatting with a project’s own tool also needs a trusted project.

  • apply_code_actionchangesdry run by defaultwriteApply a quick fix or refactoring offered by code_actions, chosen by title.
  • change_signaturechangesdry run by defaultwriteChange Signature of the function at a position of a workspace file: reorder, rename, remove or add parameters, and rewrite its declarations and every call to match.
  • code_actionsreadsdry run by defaultQuick fixes and refactorings the file's language server offers at a position or selection: title, kind, preferred and the problems each fixes.
  • editorconfigreadsEditorConfig properties of a workspace file as the editor applies them: the .editorconfig files read (from the file's folder up to one with root = true), every property with the file and line that set it, the indentation unit, tab width, line break, whether saving trims trailing whitespace and adds or removes the final line break, max_line_length, charset, and values that are not understood.
  • extract_interfacechangesdry run by defaultwriteExtract Interface for the class at (or around) a position of a TypeScript file: creates the interface before the type with the signatures of members and adds it to implements (or extends of an interface).
  • extract_superclasschangesdry run by defaultwriteExtract Superclass for the class at (or around) a position of a JavaScript or TypeScript file: creates class name before it with the chosen members, moves them there and makes the class extend it.
  • format_filechangesdry run by defaultwritetrusted-projectFormat a workspace file (or a range) as Reformat Code does.
  • move_filechangesdry run by defaultwriteMove workspace files or folders into another folder and update references: language-server edits (Rust modules, Java packages, TypeScript imports) plus Ferris IDEA's rewriting of relative C/C++ includes and JS/TS imports, also in the moved file.
  • optimize_importschangesdry run by defaultwritetrusted-projectOptimize Imports.
  • prettier_filechangesdry run by defaultwritetrusted-projectFormat a file with the project's own Prettier (node_modules/.bin/prettier in or above its package, inside the workspace, with the project's configuration; nothing is downloaded).
  • pull_members_upchangesdry run by defaultwritePull Members Up for the class at (or around) a position of a JavaScript or TypeScript file: moves members to the end of the direct supertype named target (may be left out when there is only one), or adds their signature when it is an interface or abstract is true (an abstract class).
  • redo_refactoringchangeswriteRedo the refactoring undo_refactoring took back last, in all files it changed at once, as ⇧⌘Z does in an editor.
  • rename_symbolchangesdry run by defaultwriteRename the symbol at a position of a workspace file in all its usages, through the file's language server.
  • safe_deletechangesdry run by defaultwriteSafe Delete of the symbol at a position of a workspace file: finds usages as find_usages does and removes the declaration's whole lines with the comment, doc and annotation lines above it.
  • undo_refactoringchangeswriteUndo the newest refactoring applied through this server with rename_symbol or apply_code_action (dry_run=false), in all files it changed at once.