question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle when black times out formatting on save

See original GitHub issue

Environment data

  • VS Code version: 1.28.2
  • Extension version (available under the Extensions sidebar): 2018.9.2
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Miniconda Python 3.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: black 18.9b0

Actual behavior

When black fails to format on save due to timeout, there is no message in the output window, indicating this is the reason for not formatting the document.

Expected behavior

When black fails to format on save due to timeout, it would be useful to see some kind of warning about this in the output window. Not only in the developer tools console.

Steps to reproduce:

  1. Set "python.formatting.provider": "black", "editor.formatOnSave": true and save a large Python script (mine was 712 pep8-compliant rows).
  2. Save

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Starting Jedi Python language engine.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

WARN Aborted format on save after 750ms

Extra note

As a solution to the fact that black doesn’t format a big file, increase the default "editor.formatOnSaveTimeout": 750 to a larger value in settings.json.

However, this issue is not about that, but rather the fact that it took me hours 🤕 to figure out WHY black was not formatting on save, as I was unaware of the developer tools console.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
karthiknadigcommented, Nov 12, 2022

This is now addressed in black extension.

1reaction
amiantoscommented, Feb 28, 2019

Came to Github to file an issue for this! I assumed format on save was buggy due to the silent failure and was just dealing with it for about a week or two before I realized I should say something, and the process of filing an issue made me learn the timeout setting was the cause. Doubling the timeout from 750 to 1500 solved the problem for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Black slow startup to format a single file · Issue #2564 - GitHub
I'm a bit annoyed that it takes too much time to format a single file when using black to auto-save contents in my...
Read more >
VSCode not autoformatting on save (python - black)
Have you try to increase the Format on Save Timeout in Text Editor -> Formatting. i'm aware it can cause trouble if the...
Read more >
The Black code style - Black 22.12.0 documentation
Black aims for consistency, generality, readability and reducing git diffs. Similar language constructs are formatted with similar rules.
Read more >
Using Black To Auto Format Your Python | HackerNoon
You will save time and mental energy for more important matters. Black can reformat your entire file in place according to the Black...
Read more >
Image File Formats: When to Use Each File Type - 99Designs
Here's everything you need to know about image file formats. ... All raster images can be saved in one of two primary color...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found