Skip to content

Conversation

@Bobronium
Copy link

@Bobronium Bobronium commented May 22, 2022

Closes #55
Addresses #38

Changes

  1. Show messages on any occasion when extension didn't reformat the file, except when code hasn't been changed by black
  2. Add show-formatting-messages setting that toggles behaviour in #1
  3. Process black stderr to display most relevant data first (e.g. line that couldn't be parsed)
  4. Change wording/formatting in some error messages

Checks

  • - Tested changes locally via VSCode debugger
  • - Made written code comply with linters
  • - Wrote tests to support the changes

Going to proceed with the last one one once I get overall feedback on changes

@ghost
Copy link

ghost commented May 22, 2022

CLA assistant check
All CLA requirements met.

package.json Outdated
"scope": "resource",
"type": "array"
},
"black-formatter.show-formatting-messages": {
Copy link
Member

@karthiknadig karthiknadig May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luabud Can you look at the naming of this setting and description for this? This setting allows users to get a visible UI notification if there is a issue when formatting. We also need to decide on the default value for this setting.

I feel like this should be a enum, with values like never, on-error, and on-warn. on-error covers scenarios where formatting fails due to some error like syntax error, or out-of-date version etc. on-warn covers scenarios in the on-error plus cases where formatting is intentionally skipped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the enum idea, and I don't see a problem with the setting name as is, but something more descriptive that this would show a notification could also work (e.g. black-formatter.promptMessages).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be black-formatter.showNotification? so that "black-formatter.showNotification": "on-warn" makes more sense as to what it will do.

@luabud what do you think the default should be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love showNotification! As for the default value, my vote would be for "on-error" to avoid annoying those who feel strongly about notifications. But I don't have a strong opinion on this 😊

Copy link
Author

@Bobronium Bobronium Jun 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luabud, Initially I agreed that default "on-error" would make sense, but after some thoughts I'd vote for "on-warn". The reason is simple: if user is annoyed by notifications, it's clear what's happening and how to fix it. On contrary, it's unclear what's happening when extension doesn't do what it supposed to do and doesn't emit any warnings either.

@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug no-changelog Exclude from release notes labels May 23, 2022
@Bobronium
Copy link
Author

I want to write tests to support the changes and have to ask, what's the reason to use assert_that(..., is_(...)) over plain assert ... is ... when running tests with pytest that already does a pretty good job at reporting assertions?

@karthiknadig
Copy link
Member

I want to write tests to support the changes and have to ask, what's the reason to use assert_that(..., is_(...)) over plain assert ... is ... when running tests with pytest that already does a pretty good job at reporting assertions?

Hamcrest provides better error messages when comparing objects that are complex. I also provides a way to include custom matchers and we can do fuzzy matching. This has been helpful in issues with Jedi Language Server.

Comment on lines +122 to +123
"""
Compose error message from stderr, while trying to display most relevant data first.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
Compose error message from stderr, while trying to display most relevant data first.
"""Compose error message from stderr, while trying to display most relevant data first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bobronium I don't we should rely on black to detect syntax errors. Jedi or Pylance can do a much better job at detecting these and adding an entry to the problems window that points to the exact line and column where the problem exists. This feels like it is adding additional responsibility to the black extension that I don't feel it should take on.

/cc @luabud what do you think?

"on-warn",
"on-message"
],
"scope": "resource",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"scope": "resource",
"scope": "machine",

I don't think this should be resource, this setting need not have workspace folder level of granularity. It can be machine where it can be handled in both local and remote scenarios.

Comment on lines +99 to +102
"on-crash",
"on-error",
"on-warn",
"on-message"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these should be on-error, on-warn, always, and never. I also recommend adding enum descriptions.

An example, for enum descriptions:

                "python.languageServer": {
                    "default": "Default",
                    "description": "Defines type of the language server.",
                    "enum": [
                        "Default",
                        "Jedi",
                        "Pylance",
                        "None"
                    ],
                    "enumDescriptions": [
                        "Automatically select a language server: Pylance if installed and available, otherwise fallback to Jedi.",
                        "Use Jedi behind the Language Server Protocol (LSP) as a language server.",
                        "Use Pylance as a language server.",
                        "Disable language server capabilities."
                    ],
                    "scope": "window",
                    "type": "string"
                },

/cc @luabud Need your input on the enum values and the descriptions.

"type": "array"
},
"black-formatter.showNotification": {
"default": "on-warn",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"default": "on-warn",
"default": "on-error",

I believe this should be on-error, and when we do show notification there should be a way to add a button to the displayed message to trigger a setting change. This might be a limitation of the LSP, but if we can run a command for VS Code we could make this work. That is probably a separate thing.

/cc @luabud this is a prime candidate for experiment.

@karthiknadig
Copy link
Member

@Bobronium If it is OK. I would like to update this PR with the latest extension template. We added few more configuration that make it easier to log to output and in cases where users want show notification. I will update the PR based on our intended plan, this way you will get credit for the idea when we merge it.

@Bobronium
Copy link
Author

@karthiknadig, sure! Thanks for a heads up. And thank you for picking this up.

@karthiknadig
Copy link
Member

This is now incorporated into the black extension via the backing extension template. Added credits to this in the release notes. Closing this PR.

The only part that was not used was the location extraction. Most syntax errors should be detected by language server like Pylance or Jedi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug no-changelog Exclude from release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Always print something in the logs

3 participants