Skip to content

Commit 40100f3

Browse files
committed
fix userInput and remove unused code
1 parent 91551dd commit 40100f3

File tree

7 files changed

+13
-53
lines changed

7 files changed

+13
-53
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererRecommendationAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class CodeWhispererRecommendationAction : AnAction(message("codewhisperer.trigge
5050
}
5151

5252
val triggerType = TriggerTypeInfo(CodewhispererTriggerType.OnDemand, CodeWhispererAutomatedTriggerType.Unknown())
53-
CodeWhispererInvocationStatus.getInstance().timeAtLastManualTrigger = Instant.now()
5453
val job = if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
5554
CodeWhispererServiceNew.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
5655
} else {

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class CodeWhispererPopupManager {
131131
.recommendationAdded(states, sessionContext)
132132
return
133133
}
134-
val userInputOriginal = recommendationContext.userInput
135134
val userInput = recommendationContext.userInput
136135
val typeaheadOriginal = run {
137136
val startOffset = states.requestContext.caretPosition.offset
@@ -144,11 +143,11 @@ class CodeWhispererPopupManager {
144143
// userInput + typeahead
145144
val prefix = states.requestContext.editor.document.charsSequence
146145
.substring(startOffset, currOffset)
147-
if (prefix.length < userInputOriginal.length) {
146+
if (prefix.length < userInput.length) {
148147
cancelPopup(popup)
149148
return
150149
} else {
151-
prefix.substring(userInputOriginal.length)
150+
prefix.substring(userInput.length)
152151
}
153152
}
154153
val isReverse = indexChange < 0
@@ -284,12 +283,11 @@ class CodeWhispererPopupManager {
284283
val caretPoint = states.requestContext.editor.offsetToXY(states.requestContext.caretPosition.offset)
285284
val editor = states.requestContext.editor
286285
val detailContexts = states.recommendationContext.details
287-
val userInputOriginal = states.recommendationContext.userInput
288286
val userInput = states.recommendationContext.userInput
289287
val selectedIndex = sessionContext.selectedIndex
290288
val typeaheadOriginal = sessionContext.typeaheadOriginal
291289
val typeahead = sessionContext.typeahead
292-
val userInputLines = userInputOriginal.split("\n").size - 1
290+
val userInputLines = userInput.split("\n").size - 1
293291
val lineCount = getReformattedRecommendation(detailContexts[selectedIndex], userInput).split("\n").size
294292
val additionalLines = typeaheadOriginal.split("\n").size - typeahead.split("\n").size
295293
val popupSize = (popup as AbstractPopup).preferredContentSize

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManagerNew.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ class CodeWhispererPopupManagerNew {
252252
}
253253
val editor = sessionContext.editor
254254
val previews = CodeWhispererServiceNew.getInstance().getAllSuggestionsPreviewInfo()
255-
val userInputOriginal = previews[sessionContext.selectedIndex].userInput
256-
val userInputLines = userInputOriginal.split("\n").size - 1
255+
val userInput = previews[sessionContext.selectedIndex].userInput
256+
val userInputLines = userInput.split("\n").size - 1
257257
val popupSize = (popup as AbstractPopup).preferredContentSize
258258
val yAboveFirstLine = p.y - popupSize.height + userInputLines * editor.lineHeight
259259
val popupRect = Rectangle(p.x, yAboveFirstLine, popupSize.width, popupSize.height)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererInvocationStatus.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CodeWhispererInvocationStatus {
2525
private var timeAtLastInvocationStart: Instant? = null
2626
var completionShownTime: Instant? = null
2727
private set
28-
var timeAtLastManualTrigger: Instant = Instant.now()
2928

3029
fun checkExistingInvocationAndSet(): Boolean =
3130
if (isInvokingCodeWhisperer.getAndSet(true)) {
@@ -66,8 +65,6 @@ class CodeWhispererInvocationStatus {
6665
return timeInDouble
6766
}
6867

69-
fun getTimeSinceLastManualTrigger() = Duration.between(timeAtLastManualTrigger, Instant.now()).toMillis().toDouble()
70-
7168
fun hasEnoughDelayToShowCodeWhisperer(): Boolean {
7269
val timeCanShowCodeWhisperer = timeAtLastDocumentChanged.plusMillis(CodeWhispererConstants.POPUP_DELAY)
7370
return timeCanShowCodeWhisperer.isBefore(Instant.now())

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererRecommendationManager.kt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,5 @@ class CodeWhispererRecommendationManager {
4343

4444
companion object {
4545
fun getInstance(): CodeWhispererRecommendationManager = service()
46-
47-
/**
48-
* a function to trim extra prefixing new line character (only leave 1 new line character)
49-
* example:
50-
* content = "\n\n\nfoo\n\nbar\nbaz"
51-
* return = "\nfoo\n\nbar\nbaz"
52-
*
53-
* example:
54-
* content = "\n\n\tfoobar\nbaz"
55-
* return = "\n\tfoobar\nbaz"
56-
*/
57-
fun trimExtraPrefixNewLine(content: String): String {
58-
if (content.isEmpty()) {
59-
return ""
60-
}
61-
62-
val firstChar = content.first()
63-
if (firstChar != '\n') {
64-
return content
65-
}
66-
67-
var index = 1
68-
while (index < content.length && content[index] == '\n') {
69-
index++
70-
}
71-
72-
return firstChar + content.substring(index)
73-
}
7446
}
7547
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererServiceNew.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -541,28 +541,22 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
541541
return null
542542
}
543543

544-
val userInputOriginal = CodeWhispererEditorManagerNew.getInstance().getUserInputSinceInvocation(
545-
requestContext.editor,
546-
requestContext.caretPosition.offset
547-
)
548544
val userInput =
549545
if (caretMovement == CaretMovement.NO_CHANGE) {
550546
LOG.debug { "Caret position not changed since invocation. Session Id: ${completions.sessionId}" }
551547
""
552548
} else {
553-
userInputOriginal.trimStart().also {
554-
LOG.debug {
555-
"Caret position moved forward since invocation. Session Id: ${completions.sessionId}, " +
556-
"user input since invocation: $userInputOriginal, " +
557-
"user input without leading spaces: $it"
558-
}
559-
}
549+
LOG.debug { "Caret position moved forward since invocation. Session Id: ${completions.sessionId}" }
550+
CodeWhispererEditorManagerNew.getInstance().getUserInputSinceInvocation(
551+
requestContext.editor,
552+
requestContext.caretPosition.offset
553+
)
560554
}
561555
val detailContexts = CodeWhispererRecommendationManager.getInstance().buildDetailContext(
562556
userInput,
563557
completions,
564558
)
565-
val recommendationContext = RecommendationContextNew(detailContexts, userInputOriginal, userInput, visualPosition, jobId)
559+
val recommendationContext = RecommendationContextNew(detailContexts, userInput, visualPosition, jobId)
566560
ongoingRequests[jobId] = buildInvocationContext(requestContext, responseContext, recommendationContext)
567561
return ongoingRequests[jobId]
568562
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/toolwindow/CodeWhispererCodeReferenceComponents.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CodeWhispererCodeReferenceComponents(private val project: Project) {
122122
)
123123
add(JLabel(" from ").asCodeReferencePanelFont(), inlineLabelConstraints)
124124
// TODO YUX: reference repository?
125-
// add(JLabel(ref.repository), inlineLabelConstraints)
125+
add(JLabel(ref.referenceName), inlineLabelConstraints)
126126
} else {
127127
add(
128128
JLabel(ref.licenseName).apply {
@@ -132,7 +132,7 @@ class CodeWhispererCodeReferenceComponents(private val project: Project) {
132132
)
133133
add(JLabel(" from ").asCodeReferencePanelFont(), inlineLabelConstraints)
134134
// TODO YUX: reference repository?
135-
// add(repoNameLink(ref.repository(), ref.referenceUrl), inlineLabelConstraints)
135+
add(repoNameLink(ref.referenceName, ref.referenceUrl), inlineLabelConstraints)
136136
}
137137

138138
if (!lineNums.isNullOrEmpty()) {

0 commit comments

Comments
 (0)