添加stubIndex
This commit is contained in:
@@ -15,13 +15,14 @@ import me.zhouxi.slint.lang.psi.SlintPsiUtils.InternalTypes
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes
|
||||
import me.zhouxi.slint.lang.psi.utils.exportedElements
|
||||
import me.zhouxi.slint.lang.psi.utils.inheritDeclaredElements
|
||||
import me.zhouxi.slint.stubs.types.SlintFileElementType
|
||||
|
||||
class SlintCompletionContributor : CompletionContributor() {
|
||||
init {
|
||||
//文件级别
|
||||
extend(
|
||||
CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement().withAncestor(4, PlatformPatterns.psiElement(SlintParserDefinition.FileType)),
|
||||
PlatformPatterns.psiElement().withAncestor(4, PlatformPatterns.psiElement(SlintFileElementType)),
|
||||
object : CompletionProvider<CompletionParameters>() {
|
||||
override fun addCompletions(
|
||||
parameters: CompletionParameters,
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package me.zhouxi.slint.stubs
|
||||
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.stubs.stub.SlintComponentStub
|
||||
import me.zhouxi.slint.stubs.types.SlintComponentStubType
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
object SlintStubTypes {
|
||||
val ComponentType = SlintComponentStubType()
|
||||
interface SlintStubTypes {
|
||||
companion object {
|
||||
// val Component: IStubElementType<SlintComponentStub, SlintComponent> = SlintComponentStubType()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package me.zhouxi.slint.stubs;
|
||||
package me.zhouxi.slint.stubs
|
||||
|
||||
import com.intellij.psi.stubs.StubIndexKey;
|
||||
import me.zhouxi.slint.lang.psi.SlintComponentName;
|
||||
import com.intellij.psi.stubs.StubIndexKey
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintComponentName
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
public class StubKeys {
|
||||
|
||||
public static final StubIndexKey<String, SlintComponentName> COMPONENT = StubIndexKey.createIndexKey("slint.component");
|
||||
|
||||
|
||||
object StubKeys {
|
||||
val Component: StubIndexKey<String, SlintComponent> = StubIndexKey.createIndexKey("slint.component")
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package me.zhouxi.slint.stubs.impl
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStubImpl
|
||||
import me.zhouxi.slint.lang.psi.SlintFile
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
class SlintFileStub(file: SlintFile) : PsiFileStubImpl<SlintFile>(file)
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.zhouxi.slint.stubs.impl
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStubImpl
|
||||
import com.intellij.psi.tree.IStubFileElementType
|
||||
import me.zhouxi.slint.lang.psi.SlintFile
|
||||
import me.zhouxi.slint.stubs.stub.SlintFileStub
|
||||
import me.zhouxi.slint.stubs.types.SlintFileElementType
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
class SlintFileStubImpl(file: SlintFile) : PsiFileStubImpl<SlintFile>(file), SlintFileStub {
|
||||
|
||||
override fun getType(): IStubFileElementType<*> {
|
||||
return SlintFileElementType
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.zhouxi.slint.stubs.index
|
||||
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import com.intellij.psi.stubs.StubIndexKey
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.stubs.StubKeys
|
||||
|
||||
class ComponentNameIndex : StringStubIndexExtension<SlintComponent>() {
|
||||
override fun getKey(): StubIndexKey<String, SlintComponent> {
|
||||
return StubKeys.Component
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.zhouxi.slint.stubs.stub;
|
||||
|
||||
import com.intellij.psi.stubs.PsiFileStub;
|
||||
import me.zhouxi.slint.lang.psi.SlintFile;
|
||||
|
||||
public interface SlintFileStub extends PsiFileStub<SlintFile> {
|
||||
}
|
||||
@@ -1,26 +1,38 @@
|
||||
package me.zhouxi.slint.stubs.types
|
||||
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.intellij.lang.LighterAST
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.lang.LighterASTTokenNode
|
||||
import com.intellij.lang.TreeBackedLighterAST
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.*
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.lang.psi.SlintComponent
|
||||
import me.zhouxi.slint.lang.psi.SlintExport
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.ComponentName
|
||||
import me.zhouxi.slint.lang.psi.SlintTypes.Export
|
||||
import me.zhouxi.slint.lang.psi.impl.SlintComponentImpl
|
||||
import me.zhouxi.slint.stubs.StubKeys
|
||||
import me.zhouxi.slint.stubs.impl.SlintComponentStubImpl
|
||||
import me.zhouxi.slint.stubs.stub.SlintComponentStub
|
||||
import org.mozilla.javascript.ast.AstNode
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* @author zhouxi 2024/5/23
|
||||
*/
|
||||
class SlintComponentStubType :
|
||||
IStubElementType<SlintComponentStub, SlintComponent>("SlintComponentStub", SlintLanguage.INSTANCE) {
|
||||
class SlintComponentStubType(debugName: String) :
|
||||
ILightStubElementType<SlintComponentStub, SlintComponent>(debugName, SlintLanguage.INSTANCE) {
|
||||
override fun createPsi(stub: SlintComponentStub): SlintComponent {
|
||||
return SlintComponentImpl(stub, this)
|
||||
}
|
||||
|
||||
fun createPsi(node: ASTNode): SlintComponent {
|
||||
return SlintComponentImpl(node)
|
||||
}
|
||||
|
||||
override fun createStub(psi: SlintComponent, parentStub: StubElement<out PsiElement?>): SlintComponentStub {
|
||||
return SlintComponentStubImpl(
|
||||
parentStub,
|
||||
@@ -47,7 +59,23 @@ class SlintComponentStubType :
|
||||
return SlintComponentStubImpl(parentStub, this, exported, identifier!!)
|
||||
}
|
||||
|
||||
override fun createStub(tree: LighterAST, node: LighterASTNode, parentStub: StubElement<*>): SlintComponentStub {
|
||||
var exported = false
|
||||
var parent = tree.getParent(node)
|
||||
while (parent != null) {
|
||||
if (parent.tokenType == Export) {
|
||||
exported = true
|
||||
break
|
||||
}
|
||||
parent = tree.getParent(parent)
|
||||
}
|
||||
val identifier = tree.getChildren(node).first { it.tokenType == ComponentName }
|
||||
val token = tree.getChildren(identifier)[0] as LighterASTTokenNode
|
||||
|
||||
return SlintComponentStubImpl(parentStub, this, exported, tree.charTable.intern(token.text).toString())
|
||||
}
|
||||
|
||||
override fun indexStub(stub: SlintComponentStub, sink: IndexSink) {
|
||||
sink.occurrence(StubKeys.COMPONENT, stub.identifier)
|
||||
sink.occurrence(StubKeys.Component, stub.identifier)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.zhouxi.slint.stubs.types
|
||||
|
||||
import com.intellij.psi.tree.ILightStubFileElementType
|
||||
import me.zhouxi.slint.lang.SlintLanguage
|
||||
import me.zhouxi.slint.stubs.impl.SlintFileStubImpl
|
||||
|
||||
object SlintFileElementType : ILightStubFileElementType<SlintFileStubImpl?>("SlintFile", SlintLanguage.INSTANCE) {
|
||||
|
||||
override fun getStubVersion(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user