-
-
Notifications
You must be signed in to change notification settings - Fork 63
ADFA-5048 (1/5): Move the extract-method sheet into :lsp:ui behind a plain-data contract #1817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.itsaky.androidide.lsp.kotlin.refactor | ||
|
|
||
| import com.itsaky.androidide.lsp.kotlin.utils.refactor.ExtractMethodCandidate | ||
| import com.itsaky.androidide.lsp.kotlin.utils.refactor.ExtractMethodPlan | ||
| import com.itsaky.androidide.lsp.kotlin.utils.refactor.signaturePrefix | ||
| import com.itsaky.androidide.lsp.kotlin.utils.refactor.signatureSuffix | ||
| import com.itsaky.androidide.lsp.ui.ExtractMethodSelection | ||
| import com.itsaky.androidide.lsp.ui.MethodCandidateView | ||
|
|
||
| /** | ||
| * The plan as the shared sheet sees it: labels, names and the two halves of the signature, no PSI and | ||
| * no offsets. | ||
| * | ||
| * Offsets stay on this side deliberately -- the sheet is a chooser, and resolving a selection back into | ||
| * a candidate is [candidateFor]'s job. | ||
| */ | ||
| fun ExtractMethodPlan.toMethodCandidateViews(): List<MethodCandidateView> = | ||
| candidates.map { candidate -> | ||
| MethodCandidateView( | ||
| label = candidate.label, | ||
| suggestedName = candidate.suggestedName, | ||
| takenNames = candidate.takenNames, | ||
| signaturePrefix = candidate.signaturePrefix, | ||
| signatureSuffix = candidate.signatureSuffix, | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a selection's index back to the plan it came from, or null when it does not address it. | ||
| * | ||
| * A null is a wiring bug rather than a user path -- the sheet only ever reports an index it was given -- | ||
| * so the caller reports it as a failed quick fix rather than guessing at a candidate. | ||
| */ | ||
| fun ExtractMethodPlan.candidateFor(selection: ExtractMethodSelection): ExtractMethodCandidate? = | ||
| candidates.getOrNull(selection.candidateIndex) | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,18 +183,31 @@ data class ExtractMethodPlan( | |
| } | ||
|
|
||
| /** | ||
| * The signature exactly as [buildExtractMethodRewrites] emits it. The sheet's preview calls this, so | ||
| * there is one derivation and the preview cannot drift from the declaration (R11). | ||
| * Everything the signature says before the method's name. | ||
| * | ||
| * Split from [signatureSuffix] rather than rendered whole because the sheet's preview follows what the | ||
| * user types, and [MethodCandidateView] carries the two halves. Both this and | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Daniel-ADFA low - unresolvable KDoc link.
|
||
| * [buildExtractMethodRewrites] compose them through [signatureText], so there is one derivation and | ||
| * the preview cannot drift from the declaration (R11). | ||
| */ | ||
| fun ExtractMethodCandidate.signatureText(name: String): String = | ||
| buildString { | ||
| annotations.forEach { append(it).append(' ') } | ||
| modifiers.forEach { append(it).append(' ') } | ||
| append("fun ") | ||
| receiverTypeText?.let { append(it).append('.') } | ||
| append(name) | ||
| append('(') | ||
| append(parameters.joinToString(", ") { "${it.name}: ${it.typeText}" }) | ||
| append(')') | ||
| returnTypeText?.let { append(": ").append(it) } | ||
| } | ||
| val ExtractMethodCandidate.signaturePrefix: String | ||
| get() = | ||
| buildString { | ||
| annotations.forEach { append(it).append(' ') } | ||
| modifiers.forEach { append(it).append(' ') } | ||
| append("fun ") | ||
| receiverTypeText?.let { append(it).append('.') } | ||
| } | ||
|
|
||
| /** Everything the signature says after the method's name: parameters and return type. */ | ||
| val ExtractMethodCandidate.signatureSuffix: String | ||
| get() = | ||
| buildString { | ||
| append('(') | ||
| append(parameters.joinToString(", ") { "${it.name}: ${it.typeText}" }) | ||
| append(')') | ||
| returnTypeText?.let { append(": ").append(it) } | ||
| } | ||
|
|
||
| /** The signature exactly as [buildExtractMethodRewrites] emits it. */ | ||
| fun ExtractMethodCandidate.signatureText(name: String): String = signaturePrefix + name + signatureSuffix | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Daniel-ADFA low - the adapter mapping is now untested.
Neither
toMethodCandidateViews()norcandidateFor()has a test, and the deleted:lsp:kotlinExtractMethodViewModelTestwas the only place a realExtractMethodCandidatewas rendered through the preview path. Its:lsp:uireplacement asserts on hardcoded prefix/suffix literals, so nothing pins that this function fillssignaturePrefix/signatureSuffixfrom the candidate at all.Concretely: swap lines 23 and 24 and the entire suite still passes -
ExtractMethodEditTest:406only covers the composedsignatureText, which is symmetric under the swap. A three-line test overtoMethodCandidateViews()+candidateFor()restores what the move dropped.