Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkoziel authored and lukaszwawrzyk committed Feb 22, 2023
1 parent a0d7307 commit 10370dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object PythonFunctionCallHeuristic : VersionReplacementHeuristic {
}

val currentVersion = updateSuggestion.currentLibrary.version.value
val (parentMatch, matchedVersion) = functionCallsWithAssociatedStrings.firstNotNullOfOrNull { call ->
val matchedVersion = functionCallsWithAssociatedStrings.firstNotNullOfOrNull { call ->
Regex.fromLiteral(currentVersion).find(call.matchedText)?.let { call.subMatch(it) }
} ?: return null

Expand All @@ -28,7 +28,7 @@ object PythonFunctionCallHeuristic : VersionReplacementHeuristic {
listOf(
FileChange(
matchedVersion.origin,
parentMatch.offset + matchedVersion.offset,
matchedVersion.offset,
updateSuggestion.currentLibrary.version.value.length,
updateSuggestion.suggestedVersion.value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ data class LibraryUpdate(

data class MatchedText(
val match: MatchResult,
val origin: Path
val origin: Path,
val baseOffset: Int = 0
) {
val offset: Int
get() = match.range.start
get() = match.range.start + baseOffset

val offsetLastMatchGroup: Int?
get() = match.groups.last()?.range?.start
val matchedText: String
get() = match.value

fun subMatch(other: MatchResult): Pair<MatchedText, MatchedText> = this to MatchedText(other, origin)
fun subMatch(subMatch: MatchResult): MatchedText = MatchedText(subMatch, origin, baseOffset = offset)
}

interface VersionReplacementHeuristic {
Expand Down

0 comments on commit 10370dd

Please sign in to comment.