-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Features/#462 gutter icons module case #465
base: master
Are you sure you want to change the base?
Changes from 1 commit
522b9f7
49fd4c6
ab65a0e
fe4261a
b50ba5f
486e511
4510e23
ae940f0
7c72c6d
83c436b
9c62dda
6380fa3
fdbdba8
24663bb
13cde2f
9a56970
0551777
f26921d
aeb8b22
262b914
0b4f2b3
16a657f
6f7b489
7344c94
37d2024
0dc46cb
3676b79
baa4d7e
96f23b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,25 @@ import com.intellij.psi.PsiElement | |
import com.intellij.psi.stubs.StubElement | ||
import com.jetbrains.snakecharm.lang.psi.SmkUse | ||
import com.jetbrains.snakecharm.lang.psi.impl.SmkUseImpl | ||
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseInheritedRulesIndex.Companion.INHERITED_RULES_DECLARATION_VIA_WILDCARD | ||
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseNameIndex.Companion.KEY | ||
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseStub | ||
|
||
class SmkUseElementType | ||
: SmkRuleLikeElementType<SmkUseStub, SmkUse>("SMK_USE_DECLARATION_STATEMENT", KEY) { | ||
: SmkRuleDescendantElementType<SmkUseStub, SmkUse>("SMK_USE_DECLARATION_STATEMENT", KEY) { | ||
|
||
override fun createStub(name: String?, parentStub: StubElement<*>?): SmkUseStub = | ||
SmkUseStubImpl(name, parentStub) | ||
lateinit var psi: SmkUse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this field? Seems no usages + I consider it to be a nasty hack. It is factory, it shouldn't memorize reference to some of objects created via this factory. |
||
|
||
override fun createStub(name: String?, inheritedRules: List<String?>, parentStub: StubElement<*>?) = | ||
SmkUseStubImpl(name, inheritedRules, parentStub) | ||
|
||
override fun createStub(psi: SmkUse, parentStub: StubElement<out PsiElement>?): SmkUseStub = | ||
createStub(psi.name, parentStub) | ||
createStub( | ||
psi.name, | ||
psi.getDefinedReferencesOfImportedRuleNames()?.map { it.text } ?: listOf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SmkRuleDescendantStub.getInheritedRulesNames() seems should be also method of SmkImportedRulesNamesList.arguments stub. |
||
INHERITED_RULES_DECLARATION_VIA_WILDCARD | ||
), | ||
parentStub).also { this.psi = psi } | ||
|
||
override fun createPsi(stub: SmkUseStub): SmkUse = SmkUseImpl(stub) | ||
|
||
|
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> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems it is over-design. We have only one object that could inherit rules ( P.S |
||
fun getInheritedRulesNames(): List<String?> | ||
} |
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") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getImportedRules()
name sounds to innocent, like some simple filter on AST nodes, similar to other methods. Actually it is heavy method that does resolve. Let's emphasize that it isn't lightweight method and does resolve, e.g name ituse.getImportedRules().resolveNames()