Title: TSServer: Refactor trigger reason · Issue #35096 · microsoft/TypeScript · GitHub
Open Graph Title: TSServer: Refactor trigger reason · Issue #35096 · microsoft/TypeScript
X Title: TSServer: Refactor trigger reason · Issue #35096 · microsoft/TypeScript
Description: Follow up on #34930 Problem VS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the user using a keyboard shortcut or if th...
Open Graph Description: Follow up on #34930 Problem VS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the...
X Description: Follow up on #34930 Problem VS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35096
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TSServer: Refactor trigger reason","articleBody":"Follow up on #34930\r\n\r\n## Problem\r\nVS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the user using a keyboard shortcut or if they are requested automatically when the user simply makes a selection in the current document.\r\n\r\nThis distinction is important for a few reasons brought up in #34930:\r\n\r\n- There are cases where we do not want the code action lightbulb to show up in VS Code but refactorings still should be availible if the user requests them\r\n- The TypeScript server could be less strict about the selection for manually requested refactorings. For example, if I request to `extract constant` with no selection, TS Server could assume that I want to extract the nearest expression.\r\n\r\n## Protocol Proposal\r\nIn the `getApplicableRefactors` request, add a new `triggerReason` field:\r\n\r\n```ts\r\ninterface GetApplicableRefactorsRequestArgs extends FileLocationOrRangeRequestArgs {\r\n triggerReason?: RefactorTriggerReason;\r\n}\r\n```\r\n\r\nThe trigger reason would capture why the refactoring was requested:\r\n\r\n```ts\r\ntype RefactorTriggerReason = RefactorInvokedReason;\r\n\r\ninterface RefactorInvokedReason {\r\n kind: 'invoked';\r\n}\r\n```\r\n\r\nAt the moment, I think we only need a single trigger reason: `invoked`. I have based this design around the existing server API for parameter hints.\r\n\r\n## How TS Server could use `triggerReason`\r\nAs a first step, when refactorings are explicitly invoked by the user, if the current selection is not extractable, we should automatically expand the selection for `extract constant` and `extract function` to nearest extractable expression.\r\n\r\n## Possible extension: hierarchal refactorings\r\nVS Code uses a hierarchal system to assign the class of code actions / refactorings. For example, `extract constant` has a [`CodeActionKind`](https://github.com/microsoft/vscode/blob/c408a2c02d78982b1f83819c587c02bb59af9f93/src/vs/vscode.d.ts#L1950) of `refactor.extract.constant`. Users can setup keybindings for `refactor.extract` (show all `extract` refactorings) or for `refactor.extract.constant` (show only the `extract constant` refactorings).\r\n\r\nWe should consider putting some form of hierarchical refactorings into the TS Server api as well. A few reasons this may be helpful:\r\n\r\n- If TS Server knows the type of refactorings being requested, it can only compute that subset of refactorings\r\n- In the future, we can specialize behavior for individual refactoring requests even more. For example, if a user explicitly requests `extract constant` refactorings for TS Server, we could show more than one expression around the current selection that can be extracted.\r\n\r\nTo support this in the server api, we would need to add a new another field on `RefactorInvokedReason`:\r\n\r\n```ts\r\ninterface RefactorInvokedReason {\r\n kind: 'invoked';\r\n refactorType?: RequestedRefactoringType;\r\n}\r\n```\r\n\r\nVS Code uses dotted string to represent a hierarchy of refactoring types (e.g. `\"refactor.extract.constant\"`). TS could also use this scheme. Or we could hardcode the hierarchy:\r\n\r\n```ts\r\nenum RequestedRefactoringType {\r\n Refactor,\r\n Refactor_Extract,\r\n Refactor_Extract_Constant,\r\n Refactor_Extract_Function,\r\n ...\r\n}\r\n```\r\n","author":{"url":"https://github.com/mjbvz","@type":"Person","name":"mjbvz"},"datePublished":"2019-11-14T07:22:00Z","url":"https://github.com/microsoft/TypeScript/issues/35096"}
| 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:3a7de9df-95a8-ebcc-e495-a26ea32cbfa4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD72:2D2F2F:A35757:D4F1A5:6B00E400 |
| html-safe-nonce | 1d836033bd2edf397028ffc717c6b4c2329b2482e79922b19d5f377c0b4be638 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDcyOjJEMkYyRjpBMzU3NTc6RDRGMUE1OjZCMDBFNDAwIiwidmlzaXRvcl9pZCI6Ijc3MDgwMjU5NTUwNjI3MDMxMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 216586cfaddc1345685c538dd5fe012fa595b046fd9d01876be69dbbf568db3d |
| hovercard-subject-tag | issue:522673366 |
| 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/TypeScript/35096/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a62337711cfa0ab378c1d63fab1f6d69d1523403e8f31de64adf18806e2a483e/microsoft/TypeScript/issues/35096 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a62337711cfa0ab378c1d63fab1f6d69d1523403e8f31de64adf18806e2a483e/microsoft/TypeScript/issues/35096 |
| og:image:alt | Follow up on #34930 Problem VS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mjbvz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width