Skip to content

About

Visual Studio Code extension for formatting code with dprint.

Resources

Stars

82 stars

Watchers

4 watching

Forks

Repository files navigation

dprint - Visual Studio Code Extension

Visual Studio Code formatting extension for dprint—a pluggable and configurable code formatting platform.

Install

  1. Install dprint's CLI
  2. Install extension via Visual Studio Marketplace

Setup

  1. Run dprint init in the root directory of your repository to create a dprint configuration file.
  2. Set the default formatter in your vscode settings and consider turning on "format on save":
    {
      "editor.defaultFormatter": "dprint.dprint",
      "editor.formatOnSave": true,
      // or specify per language, for example
      "[javascript]": {
        "editor.defaultFormatter": "dprint.dprint",
        "editor.formatOnSave": true
      }
    }

Features

Formats code in the editor using dprint.

Plugins are currently resolved based on the dprint configuration file in the current workspace folder.

Requirements

You must have dprint installed globally on the path.

Follow the instructions here: Install

Extension Settings

{
  // By default it will use `dprint` found on the path,
  // but use this when you want to specify a custom location.
  // Include the executable name (ex. on windows "C:\\some-dir\\dprint.exe")
  "dprint.path": "/home/david/otherPath/dprint",
  // Change this to `true` to get verbose logging
  "dprint.verbose": false,
  // Change this to `true` to format a file again until the output stops changing,
  // the same as `dprint fmt`. This may double the time it takes to format a file.
  // (requires dprint 0.59+)
  "dprint.ensureStableFormat": false,
  // Change this to `true` to format files that don't have a dprint configuration file
  // in an ancestor directory using the global configuration file. This only applies to
  // languages where dprint is the default formatter. Regardless of this setting, use the
  // "Dprint: Format Document (global config)" or "Dprint: Format Selection (global config)"
  // command to format a file using it.
  "dprint.useGlobalConfig": false,
  // Change this to `false` to not show a notification when a file isn't formatted
  // because no dprint configuration file was found for it.
  "dprint.showNoConfigNotification": true
}

Known Issues

  • No support for custom config locations.

Developing and Testing Locally

  1. npm install
  2. Go to "Run and debug" in VS code and run the "Run Extension" task.

To run the tests:

  • npm run test:unit - Runs the unit tests.
  • npm test - Runs the integration tests in a downloaded copy of VS Code. This requires dprint to be on the path. Set the DPRINT_TEST_VSCODE_EXECUTABLE environment variable to use an existing VS Code executable instead of downloading one.

Release Notes

0.18.2

  • fix: probe for an executable at a relative dprint.path on Windows (#189)

0.18.1

  • feat: add dprint.showNoConfigNotification setting (#186)
  • feat: allow turning off the no config notification for only the workspace (#188)

0.18.0

  • feat(BREAKING): remove the experimental language server backend (#170)
  • feat(BREAKING): bump minimum vscode version to 1.82 (#148)
  • feat: support format selection (#146)
  • feat: support global config and formatting files outside a config's directory (#147)
  • feat: format user data files such as the user settings.json (#151)
  • feat: refresh plugin information instead of restarting when a config file changes (#152)
  • feat: add dprint.ensureStableFormat setting (#157)
  • feat: support shell expansion in dprint.path (#159)
  • feat: provide associations and locked in plugin config json schema (#162)
  • feat: format jupyter notebook cells (#166)
  • feat: add commands to format using the global config (#168)
  • perf: only edit what changed when formatting a document (#182)
  • fix: resolve npm executable when installed with pnpm (#145)
  • fix: watch config files used outside the workspace and don't fall back to the global config (#149)
  • fix: watch ancestor config files of workspace folders and don't fall back to the global config (#150)
  • fix: resolve the npm dprint executable from the config file's directory (#154)
  • fix: format untitled documents (#156)
  • fix: launch dprint without cmd.exe on Windows when possible (#163)
  • fix: ignore config files in cache directories such as Cargo's target directory (#165)
  • fix: do not poll forever when the workspace has no folders (#174)
  • fix: do not fail every folder when one fails to resolve its executable (#175)
  • fix: format a range when the plugin's line endings differ from the document's (#177)
  • fix: reject format requests when writing to or spawning dprint fails (#178)
  • fix: share the temp copy of the npm dprint executable between folders (#179)
  • fix: give feedback from the global config commands and show them for more documents (#180)
  • fix: fail config schema downloads that did not succeed and update the built-in schema (#181)
  • fix: provide the plugin schemas instead of having vscode download them (#183)

The dprint.experimentalLsp setting was removed. The extension always uses dprint's editor service.

0.17.2

  • fix: dispose formatting edit provider on config reinitialization (#141)
  • fix: instead of focusing output window on error, show notification (#140)
  • fix: update do not allow to deny (#130)

0.17.1

  • fix: fallback to global dprint when disallowing workspace "dprint.path" config (#128)

0.17.0

  • feat: prompt for custom workspace "dprint.path" setting (#126)
  • Revert "fix: improve how dprint executable is launched (#121)" (#125)

Adds a security measure to prompt when someone provides a custom "dprint.path" vscode workspace setting so that this extension doesn't launch a workspace defined executable on startup without explicit user approval.

0.16.8

  • fix: improve how dprint executable is launched (#121)

0.16.7

  • fix: improve config discovery (#111)

0.16.6

  • fix: retry trying to find config files with vscode API if one found in root with fs api (#109)

0.16.5

  • fix: wait for workspace to be initialized before checking for configuration files (#106)
  • fix: prevent logger debug output loss (#103)

0.16.4

  • perf: avoid calling process.report.getReport() on startup (#99)

0.16.3

  • fix(npm): run dprint from a temp directory on Windows (#92)

0.16.2

  • fix: ensure duplicate processes don't appear when restarting or changing config (#85)

0.16.1

  • fix: initialize backend only if configuration file exists (#80)

0.16.0

  • feat: add dprint.experimentalLsp

0.15.1

  • fix: exclude searching for dprint config files in node_modules folders

0.15.0

  • feat: auto-discover dprint in ancestor node_modules directories (#66)
  • feat: rename dprint.reset to dprint.restart (#65)
  • perf: lazily startup editor process (#64)

0.14.0

  • feat: auto-discover dprint.jsonc config (supported in dprint 0.36+)

0.13.6

  • fix: focus the dprint output window max one time per session

0.13.5

  • fix: regression opening a descendant directory of a folder with a config file

0.13.4

  • perf: reduce startup cpu usage with multiple workspace folders

0.13.3

  • fix: regression where dprint versions <= 0.28 stopped formatting

0.13.2

  • fix: ensure large files get formatted on Mac

0.13.1

  • fix: handle dprint process being killed by an outside force

0.13.0

  • feat: expand ~/ in the dprint.path configuration to the home directory

0.12.1

  • fix: support folders with spaces when resolving node_modules path and in "dprint.path" configuration

0.12.0

  • feat: prefer resolving dprint executable in node_modules
  • feat: support for editor schema v5 (#30)

0.11.0

  • Support sub directories with dprint configuration files.

0.10.0

  • Support multiple workspace folders.
  • Do not show notification for formatting errors (it only outputs to the output tab).
  • Better handling when default schema can't be downloaded.
  • Extension is bundled to single JS file to improve load times.

0.9.0

  • Support config files in ancestor directories of the workspace.

0.8.0

  • Support for dprint 0.17
  • Get config file schema from plugins.

0.7.0

  • Add logging to "output" tab in vscode (under "dprint").
  • Add "dprint.verbose" config for outputting verbose logging.

0.6.0

  • Support dprint 0.13

0.5.0

  • Support dprint 0.12

0.4.0

  • Added dprint.path setting.

0.3.0

  • Update to work with dprint 0.10.0 (will be backwards compatible with 0.9.0 for now).
  • Plugin now re-initializes when the configuration file changes.

0.2.0

Formatting is faster due to using a long-running background process for formatting.

0.1.6

  • Instructional message when dprint is not installed globally.
  • Fix encoding issue on error.

0.1.3-0.1.5

Updates based on latest dprint CLI.

0.1.2

Fix error text.

0.1.1

Auto-dismiss syntax error notifications.

0.1.0

Initial release.

About

Visual Studio Code extension for formatting code with dprint.

Resources

Stars

82 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages