Skip to content

Commit 8ffa614

Browse files
committed
Merge remote-tracking branch 'kos/develop' into idea-autocomplete
# Conflicts: # IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptNamedElement.kt # IDEA/src/test/kotlin/ksp/kos/ideaplugin/KerboScriptFindUsagesProviderTest.kt
2 parents 093aa85 + 3b5343e commit 8ffa614

14 files changed

Lines changed: 64 additions & 38 deletions

File tree

IDEA/src/main/java/ksp/kos/ideaplugin/annotator/KerboScriptAnnotator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class KerboScriptAnnotator : Annotator {
2525
if (declaration == null) {
2626
val message = "Unknown identifier `${element.name}`"
2727
if (ApplicationInfo.getInstance().apiVersion >= "201.3803.71") {
28+
@Suppress("MissingRecentApi")
2829
holder.newAnnotation(HighlightSeverity.ERROR, message).range(element).create()
2930
} else {
31+
@Suppress("DEPRECATION")
3032
holder.createErrorAnnotation(element, message)
3133
}
3234
}

IDEA/src/main/java/ksp/kos/ideaplugin/psi/KerboScriptNamedElement.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ private fun isDeclarationVisibleToUsage(usage: PsiElement, declaration: KerboScr
7373
return true
7474
}
7575

76-
// If the declaration is in a generated file (always named generated.ks, see KerboScriptElementFactory) but the
77-
// usage is in another file, assume that the declaration is not visible.
78-
if (declaration.containingFile.name == "generated.ks" && usage.containingFile.name != "generated.ks") return false
76+
if (usage.containingFile != declaration.containingFile) {
77+
// The declaration is local, but they don't share a file, no way it's visible.
78+
return false
79+
}
7980

8081
// If usage is inside a function declaration (relative to the common ancestor) then all bets on ordering are
8182
// off, and we'll let this fly.
@@ -106,11 +107,8 @@ private inline fun <reified T : PsiElement> doesTypeExistBetweenCurrentAndCloses
106107
otherAncestors.zip(currentAncestors).indexOfLast { (a, b) -> a == b }
107108

108109
if (closestCommonAncestorIndex == -1) {
109-
throw IllegalStateException(
110-
"Unable to find common ancestor: " +
111-
" current=$current@${current.containingFile.name}:${current.textRange} and " +
112-
" other=$other@${other.containingFile.name}:${other.textRange}"
113-
)
110+
// They don't even share an ancestor, so the type can't exist between them.
111+
return false
114112
}
115113

116114
val closestTypeIndex = currentAncestors.indexOfLast { it is T }

IDEA/src/main/java/ksp/kos/ideaplugin/psi/impl/KerboScriptScopeImpl.java

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ksp.kos.ideaplugin.psi.impl
2+
3+
import com.intellij.extapi.psi.ASTWrapperPsiElement
4+
import com.intellij.lang.ASTNode
5+
import ksp.kos.ideaplugin.psi.KerboScriptScope
6+
import ksp.kos.ideaplugin.reference.Cache
7+
import ksp.kos.ideaplugin.reference.context.LocalContext
8+
9+
/**
10+
* Created on 07/01/16.
11+
*
12+
* @author ptasha
13+
*/
14+
open class KerboScriptScopeImpl(node: ASTNode) : ASTWrapperPsiElement(node), KerboScriptScope {
15+
private var cache: Cache<LocalContext>? = null
16+
17+
@Synchronized
18+
override fun getCachedScope(): LocalContext {
19+
val resolvedCache = cache ?: run {
20+
// It's possible that this triggers a re-walk of the entire file, which will itself construct a
21+
// LocalContext and cache for this scope. If we now overwrite that it'll be incorrect. Make sure to
22+
// check again if our cache is still null before charging ahead.
23+
val parentScope = this.scope.cachedScope
24+
cache ?: run {
25+
val newCache = Cache(this, LocalContext(parentScope))
26+
cache = newCache
27+
newCache
28+
}
29+
}
30+
return resolvedCache.scope
31+
}
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ksp.kos.ideaplugin
2+
3+
class KerboScriptFindUsagesProviderTest : KerboScriptPlatformTestBase() {
4+
override val subdir: String = "findUsages"
5+
6+
fun testBasic() {
7+
val usages = myFixture.testFindUsagesUsingAction("Basic.ks")
8+
val expected = setOf(
9+
" PRINT param.",
10+
" PRINT param().",
11+
" LOCAL var TO param.",
12+
" LOCAL var TO param().",
13+
)
14+
assertEquals(expected, usages.map { it.presentation.plainText }.toSet())
15+
}
16+
}

IDEA/src/test/kotlin/ksp/kos/ideaplugin/annotator/KerboScriptAnnotatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ksp.kos.ideaplugin.KerboScriptPlatformTestBase
44

55

66
internal class KerboScriptAnnotatorTest : KerboScriptPlatformTestBase() {
7-
override val subdir = "AnnotatorUndefinedVariableErrors"
7+
override val subdir = "annotatorUndefinedVariableErrors"
88

99
fun testAnnotator() {
1010
myFixture.configureByFiles(

IDEA/src/test/testData/AnnotatorUndefinedVariableErrors/Imported1.ks renamed to IDEA/src/test/testData/annotatorUndefinedVariableErrors/Imported1.ks

File renamed without changes.

IDEA/src/test/testData/AnnotatorUndefinedVariableErrors/Imported3.ks renamed to IDEA/src/test/testData/annotatorUndefinedVariableErrors/Imported3.ks

File renamed without changes.

IDEA/src/test/testData/AnnotatorUndefinedVariableErrors/Imported5.ks renamed to IDEA/src/test/testData/annotatorUndefinedVariableErrors/Imported5.ks

File renamed without changes.

IDEA/src/test/testData/AnnotatorUndefinedVariableErrors/Imported6.ks renamed to IDEA/src/test/testData/annotatorUndefinedVariableErrors/Imported6.ks

File renamed without changes.

0 commit comments

Comments
 (0)