Editor Integration

The P42 JS Assistant extends the JavaScript and TypeScript editors in Visual Studio Code in several ways.

Refactoring Suggestions

The P42 JS Assistant suggests beneficial refactorings by showing an underline with three dots (for refactorings) or a blue or yellow squiggly underline (For code cleanups). You can invoke them as a quick-fix.

๐Ÿ’กย ย If you want to show some suggestions differently, e.g., as a warning, you can configure them in the Visual Studio Code settings.

Refactoring Hints

Quick-Fixes

The quick-fix context menu contains the most relevant actions for the current cursor position or selection. You will see a lightbulb in your editor when code actions are available. You can click on the lightbulb or use a keyboard shortcut to open the quick-fix context menu.

TypeMac ShortcutWindows/Linux Shortcut
Quick Fixcontext menuโŒ˜ + .Ctrl + .

Quick Fix menu

Refactoring Context Menus

In addition to the quick-fix context menu, there is a more general "Refactor" context menu and several more specific context menus for refactoring types such as "Inline" or "Move".

You can open these menus in three ways:

Command Palette

The P42 JS Assistant adds several commands to Visual Studio Code. You can access them in the command palette by entering >P42:

Command palette

Keyboard Shortcuts

Keyboard shortcuts are essential for effectively editing source code. The JS Assistant adds several shortcuts to help you access and work with refactorings easily.

Context Menus Shortcuts

The following context menus can be opened with keyboard shortcuts in the editor:

TypeMac ShortcutWindows/Linux Shortcut
Quick Fixcontext menuโŒ˜ + .Ctrl + .
Refactorcontext menuโŒƒ + โŒ˜ + RCtrl + Alt + R
Source Actioncontext menuโŒƒ + โŒ˜ + SCtrl + Alt + S
Other Actioncontext menuโŒƒ + โŒ˜ + ACtrl + Alt + A

Action Shortcuts

Several actions can also be executed directly:

TypeMac ShortcutWindows/Linux Shortcut
ExtractdirectโŒƒ + โŒ˜ + XCtrl + Alt + X
InlinedirectโŒƒ + โŒ˜ + ICtrl + Alt + I
Toggle Braces {}directโŒƒ + โŒ˜ + BCtrl + Alt + B
Move UpdirectโŒƒ + โŒฅ + โ†‘Ctrl + Alt + U
Move DowndirectโŒƒ + โŒฅ + โ†“Ctrl + Alt + J

Selection Shortcuts

The smart shrink and expand selection shortcuts are essential for creating semantic selections that provide the right context when triggering refactorings:

ActionTypeMac ShortcutWindows/Linux Shortcut
Smart Expand SelectiondirectโŒƒ + โ‡ง + โŒ˜ + โ†’โ‡ง + Alt + โ†’
Smart Shrink SelectiondirectโŒƒ + โ‡ง + โŒ˜ + โ†โ‡ง + Alt + โ†

Custom Keyboard Shortcuts

You can set up custom keybindings for any code action in Visual Studio Code. This approach also works for the code assists from the P42 JS Assistant. You can find the code action kind for each P42 code assist on its documentation page.

๐Ÿ’กย ย You can find the JSON definition of the keyboard shortcuts by using the >Preferences: Open Keyboard Shortcuts (JSON) command in the Visual Studio Code command palette.

๐Ÿ’กย ย The code action kind is hierarchical. You can combine different code assists that share the same prefix into a single shortcut.

๐Ÿ’กย ย The code action kinds in the P42 JS Assistant might change from time to time to allow for better grouping of different code assists into single shortcuts. The changelog will mention such changes, so you can easily update your custom shortcuts.

Here are a few examples:

Toggle Arrow Function Braces Context Menu

This shortcut combines the "Add {โ€ฆ} to arrow function" and "Remove {โ€ฆ} from arrow function" code assists using their shared code action kind prefix and shows a context menu.

{
    "key": "Ctrl+Cmd+E",
    "command": "editor.action.codeAction",
    "args": { 
        "kind": "refactor.rewrite.toggle.braces.arrow-function",
        "apply": "never"
    }
}

Direct Extract Variable Keyboard Shortcut

This shortcut introduces a direct keybinding for the "Extract variable" code assist.

{
    "key": "Ctrl+Cmd+Shift+X",
    "command": "editor.action.codeAction",
    "args": { 
        "kind": "refactor.extract.p42.extract-variable",
        "apply": "ifSingle"
    }
}

Touch Bar

The P42 JS Assistant adds the following buttons to the MacOS touch bar:

  • โœ๏ธ (Rename): Triggers the rename command on the current symbol.
  • ๐Ÿช„ (Quick Fix): Opens the quick-fix context menu.
  • ๐Ÿ”ง (Refactor): Opens the refactor context menu.
  • ๐Ÿ“„ (Source Action): Opens the source action context menu.

You can change the touch button visibility in the P42 Settings.

๐Ÿ’กย ย  Learn more about configuring the touch bar in Visual Studio Code.