-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New index for inherited rules was created. Behaviour of creating gutt…
…er icons in case of overridden rules was changed. Corresponding tests were extended. Resolves: #462, #463, #429
- Loading branch information
Dmitry
committed
Jan 29, 2022
1 parent
9c62dda
commit 6380fa3
Showing
11 changed files
with
208 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/com/jetbrains/snakecharm/lang/psi/impl/stubs/SmkRuleDescendantElementType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.jetbrains.snakecharm.lang.psi.impl.stubs | ||
|
||
import com.intellij.psi.stubs.* | ||
import com.jetbrains.python.psi.PyElement | ||
import com.jetbrains.python.psi.PyStubElementType | ||
import com.jetbrains.snakecharm.lang.psi.SmkRuleLike | ||
import com.jetbrains.snakecharm.lang.psi.stubs.RuleDescendantStub | ||
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseInheritedRulesIndex | ||
|
||
abstract class SmkRuleDescendantElementType<StubT : RuleDescendantStub<*>, PsiT : PyElement>( | ||
debugName: String, | ||
private val nameIndexKey: StubIndexKey<String, out SmkRuleLike<*>>? | ||
) : | ||
PyStubElementType<StubT, PsiT>(debugName) { | ||
abstract fun createStub(name: String?, inheritedRules: List<String?>, parentStub: StubElement<*>?): StubT | ||
|
||
override fun serialize(stub: StubT, dataStream: StubOutputStream) { | ||
dataStream.writeName(stub.name) | ||
dataStream.writeInt(stub.getInheritedRulesNames().size) | ||
stub.getInheritedRulesNames().forEach { name -> | ||
dataStream.writeName(name) | ||
} | ||
} | ||
|
||
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): StubT { | ||
val name = dataStream.readNameString() | ||
val size = dataStream.readInt() | ||
val inheritedRules = mutableListOf<String?>() | ||
for (x in 0 until size) { | ||
inheritedRules.add(dataStream.readNameString()) | ||
} | ||
return createStub(name, inheritedRules, parentStub) | ||
} | ||
|
||
override fun indexStub(stub: StubT, sink: IndexSink) { | ||
if (nameIndexKey != null) { | ||
stub.name?.let { name -> | ||
sink.occurrence(nameIndexKey, name) | ||
} | ||
} | ||
stub.getInheritedRulesNames().forEach { inheritedName -> | ||
if (inheritedName != null) { | ||
sink.occurrence(SmkUseInheritedRulesIndex.KEY, inheritedName) | ||
} | ||
} | ||
super.indexStub(stub, sink) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/jetbrains/snakecharm/lang/psi/stubs/RuleDescendantStub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.jetbrains.snakecharm.lang.psi.stubs | ||
|
||
import com.intellij.psi.PsiNamedElement | ||
import com.intellij.psi.stubs.NamedStub | ||
|
||
/** | ||
* Stub of rule like element which inherits at least one rule | ||
*/ | ||
interface RuleDescendantStub<T : PsiNamedElement> : NamedStub<T> { | ||
fun getInheritedRulesNames(): List<String?> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/jetbrains/snakecharm/lang/psi/stubs/SmkUseInheritedRulesIndex.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.jetbrains.snakecharm.lang.psi.stubs | ||
|
||
import com.intellij.psi.stubs.StringStubIndexExtension | ||
import com.intellij.psi.stubs.StubIndexKey | ||
import com.jetbrains.snakecharm.lang.psi.SmkUse | ||
|
||
class SmkUseInheritedRulesIndex : | ||
StringStubIndexExtension<SmkUse>() { | ||
override fun getKey() = KEY | ||
|
||
companion object { | ||
const val INHERITED_RULES_DECLARATION_VIA_WILDCARD = "*" | ||
|
||
val KEY = StubIndexKey.createIndexKey<String, SmkUse>("Smk.use.inheritedRules") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters