Add LSP refactoring capabilities framework - #4855
Add LSP refactoring capabilities framework#4855Mateusz Kadlubowski (xeho91) wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds the shared LSP framework for registering, filtering, converting, and testing refactoring code actions.
Changes:
- Adds refactor provider dispatch and LSP conversion.
- Supports disabled actions and post-edit rename commands.
- Adds Fourslash refactor verification helpers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
internal/lsp/server.go |
Advertises refactor support. |
internal/ls/lsconv/converters.go |
Converts offsets in arbitrary text. |
internal/ls/codeactions.go |
Extends actions and invokes refactors. |
internal/ls/codeactions_refactor.go |
Implements the refactor framework. |
internal/ls/codeactions_refactor_test.go |
Tests action conversion. |
internal/fourslash/fourslash.go |
Adds refactor test helpers. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/ls/codeactions_refactor.go:152
- The provider is selected using
RefactorAction.Kinds, but the emitted kind is taken independently fromCodeAction.Kindand defaults torefactor.rewrite. The new only-filter test registers an extract action whose factory leavesKindempty, so arefactor.extractrequest returns arefactor.rewriteaction, violating the request filter. Propagate/validate the registered kind, or require factories to set a kind and filter each generated action by its actual emitted kind.
kind := action.Kind
if kind == "" {
kind = lsproto.CodeActionKindRefactorRewrite
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (3)
internal/fourslash/fourslash.go:2035
- This collector accepts every
refactor.*response regardless of the requestedonlykinds. Consequently,VerifyRefactorWithOnlyAvailable(..., refactor.extract)can treat a returnedrefactor.rewriteas available, bypassing the client's hierarchical filtering and allowing server-side filtering regressions to pass. Filter the collected actions by requested-kind containment.
if item.CodeAction != nil && item.CodeAction.Kind != nil &&
isRefactoringKind(*item.CodeAction.Kind) && item.CodeAction.Disabled == nil {
actions = append(actions, item.CodeAction)
internal/fourslash/fourslash.go:2069
- Using
""as the sentinel for “do not verify edits” makes an empty expected file unrepresentable. A refactor that deletes all content will skip both applying the edit and asserting the result, so the test passes without checking behavior. Use a*stringor an explicit verification flag so an empty expected value remains testable.
if options.NewFileContent != "" {
actual := f.applyRefactorEdits(t, matchingAction, options.ApplyChanges)
assert.Equal(t, options.NewFileContent, actual, "File content after applying refactoring did not match expected content.")
internal/ls/codeactions_refactor.go:155
- Filtering uses
RefactorAction.Kinds, but the emitted kind comes independently fromCodeAction.Kindand defaults torefactor.rewrite. The newOnlyFiltertest already registers an extract action whose factory omitsKind, so anonly: [refactor.extract]request returnsrefactor.rewrite; a conforming client then filters out the action. Ensure each result inherits a matching descriptor kind, or validate its explicit kind against both the descriptor andonly.
kind := action.Kind
if kind == "" {
kind = lsproto.CodeActionKindRefactorRewrite
|
We're not going to be able to review this prior to the repo move back to |
|
Will it still be under consideration once I migrate my PRs to the main repository - microsoft/typescript - when the time comes? |
Umbrella PR for the discussion #4747.
Shared base for missing refactoring code actions.
What?
onlykind, convert to LSPDisabledSupportcapability + user preferenceVerifyRefactorVerifyRefactorDisabledVerifyRefactorWithOnly*Why?
LSP refactoring capabilities are missing.
One base first, then add actions one PR each.
I have a draft work done for two refactoring capabilities done, which I could use as stacked PRs:
Infer function return typerefactoring capability xeho91/typescript-go#1Extract typerefactoring capability xeho91/typescript-go#2I couldn't create PRs for those in this repository, given that
xeho91:lsp-refactoring-capabilitiesis a fork.