Skip to content

Commit 86fd15d

Browse files
authored
Merge pull request #387 from themkat/implement_abstract_members_emacs_fix
Fix issue where code action doesn't show up, unless entire text marked
2 parents 81b6b4c + a3c040e commit 86fd15d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 3 additions & 2 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,10 +17,10 @@ interface QuickFix {
1617
}
1718

1819
fun diagnosticMatch(diagnostic: Diagnostic, range: Range, diagnosticTypes: Set<String>): Boolean =
19-
diagnostic.range.equals(range) && diagnosticTypes.contains(diagnostic.code.left)
20+
range.isSubrangeOf(diagnostic.range) && diagnosticTypes.contains(diagnostic.code.left)
2021

2122
fun diagnosticMatch(diagnostic: KotlinDiagnostic, startCursor: Int, endCursor: Int, diagnosticTypes: Set<String>): Boolean =
22-
diagnostic.textRanges.any { it.startOffset == startCursor && it.endOffset == endCursor } && diagnosticTypes.contains(diagnostic.factory.name)
23+
diagnostic.textRanges.any { it.startOffset <= startCursor && it.endOffset >= endCursor } && diagnosticTypes.contains(diagnostic.factory.name)
2324

2425
fun findDiagnosticMatch(diagnostics: List<Diagnostic>, range: Range, diagnosticTypes: Set<String>) =
2526
diagnostics.find { diagnosticMatch(it, range, diagnosticTypes) }
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)