Skip to content

Commit

Permalink
fix imports marked as not found
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Jan 2, 2024
1 parent 26445fc commit 2c58d82
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
45 changes: 40 additions & 5 deletions src/main/kotlin/com/emberjs/gts/GtsSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter
import com.intellij.openapi.fileTypes.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.IconLoader
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -73,6 +74,7 @@ import com.intellij.psi.search.ProjectScope
import com.intellij.psi.templateLanguages.*
import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.IFileElementType
import com.intellij.psi.tree.IStubFileElementType
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.elementType
import com.intellij.psi.xml.XmlTokenType
Expand All @@ -89,6 +91,20 @@ val JS: JSLanguageDialect = JavaScriptSupportLoader.ECMA_SCRIPT_6


open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : Language(lang, id) {
public var fileElementType: JSFileElementType? = null
override fun <T : Any?> getUserData(key: Key<T>): T? {
if (key.toString() == "js.file.element.type") {
return fileElementType as T?
}
return super.getUserData(key)
}

override fun <T : Any?> putUserDataIfAbsent(key: Key<T>, value: T & Any): T & Any {
if (key.toString() == "js.file.element.type") {
return value
}
return super.putUserDataIfAbsent(key, value)
}

companion object {
val INSTANCE = GtsLanguage()
Expand Down Expand Up @@ -116,6 +132,10 @@ class GtsFile(viewProvider: FileViewProvider?, val isJS: Boolean =false)

class GtsFileElementType(language: Language?) : JSFileElementType(language) {

init {
(language as GtsLanguage).fileElementType = this
}

override fun parseContents(chameleon: ASTNode): ASTNode? {
return GtsElementTypes.TS_CONTENT_ELEMENT_TYPE.parseContents(chameleon)
}
Expand All @@ -125,7 +145,22 @@ class GtsFileElementType(language: Language?) : JSFileElementType(language) {
}

companion object {
val INSTANCE = GtsFileElementType(TS)
val INSTANCE = GtsFileElementType(GtsLanguage.INSTANCE)
}
}

class GjsFileElementType(language: Language?) : JSFileElementType(language) {

override fun parseContents(chameleon: ASTNode): ASTNode? {
return GtsElementTypes.TS_CONTENT_ELEMENT_TYPE.parseContents(chameleon)
}

override fun getExternalId(): String {
return GjsLanguage.INSTANCE.toString() + ":" + this
}

companion object {
val INSTANCE = GjsFileElementType(GjsLanguage.INSTANCE)
}
}

Expand Down Expand Up @@ -238,11 +273,11 @@ class GtsElementTypes {

open class GtsParserDefinition(val isJS: Boolean = false) : TypeScriptParserDefinition() {

override fun getFileNodeType(): IFileElementType {
override fun getFileNodeType(): JSFileElementType {
if (isJS) {
return GtsElementTypes.GJS_FILE_NODE_TYPE
return GjsFileElementType.INSTANCE
}
return GtsElementTypes.GTS_FILE_NODE_TYPE
return GtsFileElementType.INSTANCE
}

override fun createLexer(project: Project?): Lexer {
Expand Down Expand Up @@ -632,7 +667,7 @@ class GtsComponentCandidatesProvider(val placeInfo: JSImportPlaceInfo) : JSImpor
exports.add(Info("default", getComponentName(virtualFile), GtsIcons.icon, virtualFile))
}

val namedExports = PsiTreeUtil.collectElements(file) { (it as? JSElementBase)?.isExported == true && !it.isExportedWithDefault}.map { it as JSElementBase }
val namedExports = PsiTreeUtil.collectElements(file) { (it as? JSElementBase)?.isExported == true}.map { it as JSElementBase }
namedExports.forEach {
exports.add(Info("named", it.name!!, GtsIcons.icon, virtualFile))
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/emberjs/utils/EmberUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ class EmberUtils {
fun findComponentArgsType(element: JSElement): JSRecordType? {
var cls: PsiElement? = element
if (cls is TypeScriptVariable) {
return cls.jsType?.asRecordType()?.callSignatures?.first()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
return cls.jsType?.asRecordType()?.callSignatures?.firstOrNull()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
}
if (cls is TypeScriptAsExpression) {
return cls.type?.jsType?.asRecordType()?.callSignatures?.first()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
return cls.type?.jsType?.asRecordType()?.callSignatures?.firstOrNull()?.returnType?.asRecordType()?.properties?.find { it.memberName == "Context" }?.jsType?.asRecordType()?.properties?.find { it.memberName == "args" }?.jsType?.asRecordType()
}
if (cls !is TypeScriptClassImpl) {
cls = PsiTreeUtil.findChildOfType(cls, TypeScriptClassImpl::class.java)
Expand Down

0 comments on commit 2c58d82

Please sign in to comment.