Skip to content

Commit a3c040e

Browse files
committed
Change private helper function into an extension function
1 parent 6022088 commit a3c040e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

server/src/main/kotlin/org/javacs/kt/codeaction/quickfix/QuickFix.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.eclipse.lsp4j.Range
77
import org.eclipse.lsp4j.jsonrpc.messages.Either
88
import org.javacs.kt.CompiledFile
99
import org.javacs.kt.index.SymbolIndex
10+
import org.javacs.kt.util.isSubrangeOf
1011
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
1112
import org.jetbrains.kotlin.diagnostics.Diagnostic as KotlinDiagnostic
1213

@@ -16,15 +17,7 @@ interface QuickFix {
1617
}
1718

1819
fun diagnosticMatch(diagnostic: Diagnostic, range: Range, diagnosticTypes: Set<String>): Boolean =
19-
isDiagnosticInRange(diagnostic, range) && diagnosticTypes.contains(diagnostic.code.left)
20-
21-
// for a diagnostic to be in range the lines should be the same, and
22-
// the input character range should be within the bounds of the diagnostics range.
23-
private fun isDiagnosticInRange(diagnostic: Diagnostic, range: Range): Boolean {
24-
val diagnosticRange = diagnostic.range
25-
return diagnosticRange.start.line == range.start.line && diagnosticRange.end.line == range.end.line &&
26-
diagnosticRange.start.character <= range.start.character && diagnosticRange.end.character >= range.end.character
27-
}
20+
range.isSubrangeOf(diagnostic.range) && diagnosticTypes.contains(diagnostic.code.left)
2821

2922
fun diagnosticMatch(diagnostic: KotlinDiagnostic, startCursor: Int, endCursor: Int, diagnosticTypes: Set<String>): Boolean =
3023
diagnostic.textRanges.any { it.startOffset <= startCursor && it.endOffset >= endCursor } && diagnosticTypes.contains(diagnostic.factory.name)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.javacs.kt.util
2+
3+
import org.eclipse.lsp4j.Range
4+
5+
// checks if the current range is within the other range (same lines, within the character bounds)
6+
fun Range.isSubrangeOf(otherRange: Range): Boolean =
7+
otherRange.start.line == this.start.line && otherRange.end.line == this.end.line &&
8+
otherRange.start.character <= this.start.character && otherRange.end.character >= this.end.character

0 commit comments

Comments
 (0)