Skip to content

Commit

Permalink
Merge pull request #387 from themkat/implement_abstract_members_emacs…
Browse files Browse the repository at this point in the history
…_fix

Fix issue where code action doesn't show up, unless entire text marked
  • Loading branch information
fwcd authored Sep 14, 2022
2 parents 81b6b4c + a3c040e commit 86fd15d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.eclipse.lsp4j.Range
import org.eclipse.lsp4j.jsonrpc.messages.Either
import org.javacs.kt.CompiledFile
import org.javacs.kt.index.SymbolIndex
import org.javacs.kt.util.isSubrangeOf
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.diagnostics.Diagnostic as KotlinDiagnostic

Expand All @@ -16,10 +17,10 @@ interface QuickFix {
}

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

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

fun findDiagnosticMatch(diagnostics: List<Diagnostic>, range: Range, diagnosticTypes: Set<String>) =
diagnostics.find { diagnosticMatch(it, range, diagnosticTypes) }
Expand Down
8 changes: 8 additions & 0 deletions server/src/main/kotlin/org/javacs/kt/util/RangeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.javacs.kt.util

import org.eclipse.lsp4j.Range

// checks if the current range is within the other range (same lines, within the character bounds)
fun Range.isSubrangeOf(otherRange: Range): Boolean =
otherRange.start.line == this.start.line && otherRange.end.line == this.end.line &&
otherRange.start.character <= this.start.character && otherRange.end.character >= this.end.character

0 comments on commit 86fd15d

Please sign in to comment.