Title: Colon-triggered block formatter and line formatter do not coexist · Issue #2714 · microsoft/vscode-python · GitHub
Open Graph Title: Colon-triggered block formatter and line formatter do not coexist · Issue #2714 · microsoft/vscode-python
X Title: Colon-triggered block formatter and line formatter do not coexist · Issue #2714 · microsoft/vscode-python
Description: In working on the line formatter (#2690), I discovered the registration of the OnEnterFormater overrides the registration of BlockFormatProviders in extension.ts. The current code looks like this (after the introduction of the second lin...
Open Graph Description: In working on the line formatter (#2690), I discovered the registration of the OnEnterFormater overrides the registration of BlockFormatProviders in extension.ts. The current code looks like this (...
X Description: In working on the line formatter (#2690), I discovered the registration of the OnEnterFormater overrides the registration of BlockFormatProviders in extension.ts. The current code looks like this (...
Opengraph URL: https://github.com/microsoft/vscode-python/issues/2714
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Colon-triggered block formatter and line formatter do not coexist","articleBody":"In working on the line formatter (#2690), I discovered the registration of the `OnEnterFormater` overrides the registration of `BlockFormatProviders` in `extension.ts`. \r\n\r\nThe current code looks like this (after the introduction of the second line in #649):\r\n```ts\r\ncontext.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, new BlockFormatProviders(), ':'));\r\ncontext.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, new OnEnterFormatter(), '\\n'));\r\n```\r\n\r\nThe last registration appears to take precedence, so you can hit enter to format a line, but if you type a `:`, nothing happens, say after the `else` in this example:\r\n\r\n```python\r\nif x:\r\n pass\r\n else\r\n```\r\n\r\nIf you swap the registration order so that `BlockFormatProviders` comes last, line formatting no longer works, but hitting `:` in the above code gets reformatted into:\r\n\r\n```python\r\nif x:\r\n pass\r\nelse:\r\n```\r\n\r\nI think this may be the cause of (or at least fix) #771, since you hit `:` after `else` before you would hit enter, meaning that the `else` would have already been moved left to the correct position.\r\n\r\nThe documentation for `registerOnTypeFormattingEditProvider` states that multiple providers can be registered, and will be selected based on a \"score\". If the score is the same, then the last one wins, which is what is happening here. The \"first\" trigger character differing between two registrations doesn't seem to matter. The solution is probably to make a single `OnTypeFormattingEditProvider` which then dispatches based on the trigger character, like:\r\n\r\n```ts\r\ncontext.subscriptions.push(languages.registerOnTypeFormattingEditProvider(PYTHON, new NewfangledProvider(), '\\n', [':']));\r\n```","author":{"url":"https://github.com/jakebailey","@type":"Person","name":"jakebailey"},"datePublished":"2018-09-27T22:00:20Z","url":"https://github.com/microsoft/vscode-python/issues/2714"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7fd99d0e-0e8d-10c3-a577-b13ad7f573f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FFA:85408:9EA6E9:D6AF18:6AFE6408 |
| html-safe-nonce | 65530494ef5d887043347068aa8fa54657970854d3cec86171be5af050906b23 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkZBOjg1NDA4OjlFQTZFOTpENkFGMTg6NkFGRTY0MDgiLCJ2aXNpdG9yX2lkIjoiNTMwOTU1NTg5ODczMTg4MTQ4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b5053bc5259e3f471bb0b7450e39b9802f1c38f44e50f06b7707b1c8cbdbefb5 |
| hovercard-subject-tag | issue:364669194 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/vscode-python/2714/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b1e1f668441201bc11e169ed73749ebc20c8d75da8f3f05dd933fe7733f43a4/microsoft/vscode-python/issues/2714 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b1e1f668441201bc11e169ed73749ebc20c8d75da8f3f05dd933fe7733f43a4/microsoft/vscode-python/issues/2714 |
| og:image:alt | In working on the line formatter (#2690), I discovered the registration of the OnEnterFormater overrides the registration of BlockFormatProviders in extension.ts. The current code looks like this (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jakebailey |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/vscode-python git https://github.com/microsoft/vscode-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 106462765 |
| octolytics-dimension-repository_nwo | microsoft/vscode-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 49946255 |
| octolytics-dimension-repository_parent_nwo | DonJayamanne/pythonVSCode |
| octolytics-dimension-repository_network_root_id | 49946255 |
| octolytics-dimension-repository_network_root_nwo | DonJayamanne/pythonVSCode |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width