@@ -19,6 +19,7 @@ import org.assertj.core.util.VisibleForTesting
19
19
import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException
20
20
import software.aws.toolkits.core.utils.debug
21
21
import software.aws.toolkits.core.utils.getLogger
22
+ import software.aws.toolkits.core.utils.warn
22
23
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
23
24
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererClientAdaptor
24
25
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
@@ -154,14 +155,28 @@ class CodeWhispererUserModificationTracker(private val project: Project) : Dispo
154
155
private fun emitTelemetryOnSuggestion (acceptedSuggestion : AcceptedSuggestionEntry ) {
155
156
val file = acceptedSuggestion.vFile
156
157
157
- if (file == null || (! file.isValid)) {
158
+ if (file == null || (! file.isValid) || ! acceptedSuggestion.range.isValid ) {
158
159
sendModificationTelemetry(acceptedSuggestion, null )
159
160
sendUserModificationTelemetryToServiceAPI(acceptedSuggestion)
160
161
} else {
161
162
// Will remove this later when we truly don't need toolkit user modification telemetry anymore
162
163
val document = runReadAction {
163
164
FileDocumentManager .getInstance().getDocument(file)
164
165
}
166
+ val start = acceptedSuggestion.range.startOffset
167
+ val end = acceptedSuggestion.range.endOffset
168
+ if (document != null ) {
169
+ if (start < 0 || end < start || end > document.textLength) {
170
+ LOG .warn {
171
+ " Invalid range for suggestion ${acceptedSuggestion.requestId} : " +
172
+ " start=$start , end=$end , docLength=${document.textLength} "
173
+ }
174
+ sendModificationTelemetry(acceptedSuggestion, null )
175
+ sendUserModificationTelemetryToServiceAPI(acceptedSuggestion)
176
+ return
177
+ }
178
+ }
179
+
165
180
val currentString = document?.getText(
166
181
TextRange (acceptedSuggestion.range.startOffset, acceptedSuggestion.range.endOffset)
167
182
)
0 commit comments