Configuration

The P42 JavaScript Assistant can be configured in the Visual Studio Code settings, using a p42.toml configuration file, and using source code annotations.

Visual Studio Code Settings

Refactoring Suggestion Visibility

For each code assist that provides refactoring suggestions, you can configure how the suggestions are displayed inside the editor. The setting is P42 > Refactoring > NAME: Suggestion. The following options are available:

  • Off: Suggestions are not shown
  • Hint: Suggestions are shown using a 3-dotted underline in the editor.
  • Information: Suggestions are shown using a blue squiggly line in the editor and are listed in the problems view as info.
  • Warning: Suggestions are shown using a yellow squiggly line in the editor and are listed in the problems view as warning.
  • Error: Suggestions are shown using a red squiggly line in the editor and are listed in the problems view as error.

When code assists are turned off in the p42.toml configuration (see below), the Visual Studio Configuration is overridden, and the project/team settings from p42.toml take precedence.

P42 Setting "Refactoring Suggestion Visibility"

Overlapping Code Assist Visibility

The P42 JavaScript Assistant provides code assists that mirror and extend the functionality of code assists that come with Visual Studio Code. The replaced Visual Studio Code code assists are by default hidden to provide a smooth experience. The following code assists are replaced:

You can configure the visibility of overlapping code assists using the P42 > Overlapping Code Assist Visibility setting. The following options are available:

  • Show only P42 code assists: The default code assists are hidden when a similar P42 code assist is available.
  • Show only default code assists: The P42 code assists are hidden when a similar default code assist is available.
  • Show all code assists: Both the P42 code assists and the default code assists are shown when there is overlap.

P42 Setting "Overlapping Code Assist Visibility"

Inapplicable Refactoring Visibility

Inapplicable refactorings that are provided by Visual Studio Code are shown as disabled by default. To make the context menus less overwhelming, P42 hides those disabled refactorings by default.

You can configure their visibility with the P42 > Inapplicable Refactoring Visibility setting. The following options are available:

  • Hide inapplicable refactorings: Inapplicable refactorings will not be shown in the refactoring context menus.
  • Show inapplicable refactorings: Inapplicable refactorings will be shown as disabled in the refactoring context menus.

Telemetry

You can activate or disable telemetry data collection with the P42 > Telemetry > Telemetry Level setting. Telemetry data is only collected when this setting and the general Visual Studio Code telemetry level are both set to "all". Telemetry data collection is opt-in and disabled by default.

Telemetry data helps us better understand how the JavaScript Assistant is used and what features to prioritize. Because P42 never sends your source code, we have not enabled any error reporting through telemetry. We only collect the following events:

  • telemetry collection start: records platform information (e.g., operation system version, Visual Studio Code version, web or desktop environment, installation timestamp)
  • code action context menu request: records the code action kind when you open a code action context menu (e.g., refactor.move) and the number of P42 code actions that are shown in the menu.
  • code action execution: records the code action id (e.g., move-statement) and it's source (e.g., quickFix) when you execute a P42 code action.

The Visual Studio Code machine and session ids are also recorded for all events.

Configuration File

The p42.toml file in the workspace root contains P42 configuration that can be shared in a project. Just check it into your repository and share it with other team members.

Currently, individual code assists can be enabled and disabled. By default, all code assists are enabled.

Excluded Path Patterns

You can exclude directories, files and file patterns with the excludedPathPatterns setting. The setting is an array of minimatch (npm) glob pattern.

excludedPathPatterns = [
    "**/node_modules/**",
    "**/dist/**",
    "some/other/directory/**",
    "**/generateConfig.js"
]

The exclusions apply to in-editor refactorings and to mass refactoring. If no exclusions are specified, the default exclusions **/dist/** and **/node_modules/** are used.

Platform Version

In the [platform] configuration section, you can specify the versions you are targeting. Only refactorings that are supported in your platform will be active and recommended. In particular, code modernizations that are not supported by your platform will be disabled. For example, if you set the ECMAScript version to ES2016, then ES2021 modernizations will not be shown.

ECMAScript

You can set the ECMAScript version that you can use in your source code. Possible values are ES5,ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ESNEXT (default).

Ideally, you have transpilation and polyfilling set up to produce production output code for your desired target and use ESNEXT in your source code. However, if your tooling, for example, only supports ES2016 syntax and functions, you can set the value to ES2016 and will be able to use ES5, ES2015, and ES2015 code modernizations.

[platform]
ecmaScriptVersion = "ES2016"

Disabling Refactorings

To disable a refactoring, add a section "refactoring.$refactoring-id" and set enabled to false, for example:

[refactoring.add-numeric-separator]
enabled = false

The refactoring ids are displayed as grayed-out text in parentheses in the hover messages.

Source Code Annotations

You can annotate your source code to ignore statements or files.

Ignoring Statements

You can add a // p42:ignore-next-statement comment in a separate line before a statement to prevent P42 (for VS Code and for GitHub) from analyzing the next statement and anything contained in it.

Example

if (example) {
  // p42:ignore-next-statement
  x = stringify(schema, { space: 2 }) + "\n";
}

In the above snippet, P42 will not analyse the statement x = stringify(schema, { space: 2 }) + "\n";.

Ignoring Files

You can add a // p42:ignore-file comment at the beginning of the file (before the first code line). No suggestions etc. will be shown for ignored files.